X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/22d6633114d02af0e543afbb23cc05e33d1a1c9d..cdfe2ac21ec01344b4b10d566582e7cc2b2eb7cb:/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 54e0d5df7..4538e9968 100644 --- a/app/assets/javascripts/index/notes.js.erb +++ b/app/assets/javascripts/index/notes.js.erb @@ -1,9 +1,8 @@ //= require templates/notes/show //= require templates/notes/new -$(document).ready(function () { - var params = OSM.mapParams(), - noteLayer = new L.LayerGroup(), +function initializeNotes(map) { + var noteLayer = map.noteLayer, notes = {}, newNote; @@ -25,13 +24,6 @@ $(document).ready(function () { }) }; - layers.push({ - layer: noteLayer, - layerCode: "N" - }); - - map.noteLayer = noteLayer; - map.on("layeradd", function (e) { if (e.layer == noteLayer) { loadNotes(); @@ -56,23 +48,17 @@ $(document).ready(function () { } }); - if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') { - if (params.layers) setMapLayers(params.layers); - if (params.notes) map.addLayer(noteLayer); - if (params.note) { - $.ajax({ - url: "/api/" + OSM.API_VERSION + "/notes/" + params.note + ".json", - success: function (feature) { - var marker = updateMarker(notes[feature.properties.id], feature); - - notes[feature.properties.id] = marker; - - map.addLayer(noteLayer); - marker.openPopup(); - } - }); - } - } + noteLayer.showNote = function(id) { + $.ajax({ + url: "/api/" + OSM.API_VERSION + "/notes/" + id + ".json", + success: function (feature) { + var marker = updateMarker(notes[feature.properties.id], feature); + notes[feature.properties.id] = marker; + map.addLayer(noteLayer); + marker.openPopup(); + } + }); + }; function updateMarker(marker, feature) { if (marker) { @@ -86,13 +72,11 @@ $(document).ready(function () { icon: noteIcons[feature.properties.status], opacity: 0.9 }); - marker.addTo(noteLayer).bindPopup( createPopupContent(marker, feature.properties), popupOptions() ); } - return marker; } @@ -115,9 +99,7 @@ $(document).ready(function () { function success(json) { var oldNotes = notes; - notes = {}; - json.features.forEach(updateMarkers); function updateMarkers(feature) { @@ -174,6 +156,8 @@ $(document).ready(function () { return content[0]; } + var addNoteButton = $(".control-note .control-button"); + function createNote(marker, form, url) { var location = marker.getLatLng(); @@ -200,7 +184,7 @@ $(document).ready(function () { notes[feature.properties.id] = updateMarker(marker, feature); newNote = null; - $("#createnoteanchor").removeClass("disabled").addClass("geolink"); + addNoteButton.removeClass("active"); } } @@ -229,12 +213,14 @@ $(document).ready(function () { }); } - $(".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; + if (addNoteButton.hasClass("active")) return; - $(e.target).removeClass("geolink").addClass("disabled"); + addNoteButton.addClass("active"); map.addLayer(noteLayer); @@ -255,33 +241,27 @@ $(document).ready(function () { 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"); - }); - - newNote.on("dragstart", function (e) { + addNoteButton.removeClass("active"); + }).on("dragstart", function (e) { $(newNote).stopTime("removenote"); - }); - - newNote.on("dragend", function (e) { + }).on("dragend", function (e) { e.target.openPopup(); }); }); -}); +}