OSM.router.route("/note/new");
});
- function createNote(marker, form, url) {
+ function createNote(marker, text, callback) {
var location = marker.getLatLng().wrap();
marker.options.draggable = false;
marker.dragging.disable();
$.ajax({
- url: url,
+ url: "/api/0.6/notes.json",
type: "POST",
oauth: true,
data: {
lat: location.lat,
lon: location.lng,
- text: $(form.text).val()
+ text
},
- success: function (feature) {
- noteCreated(feature, marker);
- }
+ success: callback
});
-
- function noteCreated(feature, marker) {
- content.find("textarea").val("");
- updateMarker(feature);
- newNoteMarker = null;
- noteLayer.removeLayer(marker);
- addNoteButton.removeClass("active");
- OSM.router.route("/note/" + feature.properties.id);
- }
}
function updateMarker(feature) {
}
content.find("input[type=submit]").on("click", function (e) {
+ const text = content.find("textarea").val();
+
e.preventDefault();
$(this).prop("disabled", true);
- createNote(newNoteMarker, e.target.form, "/api/0.6/notes.json");
+ createNote(newNoteMarker, text, (feature) => {
+ content.find("textarea").val("");
+ updateMarker(feature);
+ noteLayer.removeLayer(newNoteMarker);
+ newNoteMarker = null;
+ addNoteButton.removeClass("active");
+ OSM.router.route("/note/" + feature.properties.id);
+ });
});
return map.getState();