X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/9d33721630e02ab9bed1d7853be4fcb5960d7b4f..c30f20122d1f2f0f49240aae17d1233dd745e1e5:/app/assets/javascripts/index/notes.js.erb diff --git a/app/assets/javascripts/index/notes.js.erb b/app/assets/javascripts/index/notes.js.erb index 1646e8b6d..012538e1d 100644 --- a/app/assets/javascripts/index/notes.js.erb +++ b/app/assets/javascripts/index/notes.js.erb @@ -3,7 +3,7 @@ function initializeNotes(map) { var params = OSM.mapParams(), - noteLayer = new L.LayerGroup({code: 'N'}), + noteLayer = map.noteLayer, notes = {}, newNote; @@ -25,8 +25,6 @@ function initializeNotes(map) { }) }; - map.noteLayer = noteLayer; - map.on("layeradd", function (e) { if (e.layer == noteLayer) { loadNotes(); @@ -52,7 +50,10 @@ function initializeNotes(map) { }); if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') { - if (params.notes || params.layers.indexOf('N') >= 0) map.addLayer(noteLayer); + if (params.notes || (params.layers && params.layers.indexOf('N')) >= 0) { + map.addLayer(noteLayer); + } + if (params.note) { $.ajax({ url: "/api/" + OSM.API_VERSION + "/notes/" + params.note + ".json", @@ -162,6 +163,8 @@ function initializeNotes(map) { return content[0]; } + var addNoteButton = $(".control-note .control-button"); + function createNote(marker, form, url) { var location = marker.getLatLng(); @@ -188,7 +191,7 @@ function initializeNotes(map) { notes[feature.properties.id] = updateMarker(marker, feature); newNote = null; - $("#createnoteanchor").removeClass("disabled").addClass("geolink"); + addNoteButton.removeClass("disabled").addClass("geolink"); } } @@ -217,12 +220,13 @@ function initializeNotes(map) { }); } - $(".leaflet-control-attribution").on("click", "#createnoteanchor", function (e) { + addNoteButton.on("click", function (e) { e.preventDefault(); + e.stopPropagation(); - if ($(e.target).hasClass("disabled")) return; + if (addNoteButton.hasClass("disabled")) return; - $(e.target).removeClass("geolink").addClass("disabled"); + addNoteButton.removeClass("geolink").addClass("disabled"); map.addLayer(noteLayer); @@ -243,25 +247,23 @@ function initializeNotes(map) { draggable: true }); - var popupContent = $(JST["templates/notes/new"]({ - create_url: $(e.target).attr("href") - })); + var popupContent = $(JST["templates/notes/new"]()); popupContent.find("textarea").on("input", disableWhenBlank); function disableWhenBlank(e) { - $(e.target.form).prop("disabled", $(e.target).val() === ""); + $(e.target.form.add).prop("disabled", $(e.target).val() === ""); } popupContent.find("input[type=submit]").on("click", function (e) { e.preventDefault(); - createNote(newNote, e.target.form, $(e.target).data("url")); + createNote(newNote, e.target.form, '/api/0.6/notes.json'); }); newNote.addTo(noteLayer).bindPopup(popupContent[0], popupOptions()).openPopup(); newNote.on("remove", function (e) { - $("#createnoteanchor").removeClass("disabled").addClass("geolink"); + addNoteButton.removeClass("disabled").addClass("geolink"); }).on("dragstart", function (e) { $(newNote).stopTime("removenote"); }).on("dragend", function (e) {