]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/notes.js.erb
Focus on the text field when a note is opened
[rails.git] / app / assets / javascripts / index / notes.js.erb
index 4594f1c782bf3fd1c692b2321c01459f012372fc..9fb03bb0dd62af9ad4ec7c5be0a75a70fd0b20b4 100644 (file)
@@ -37,13 +37,19 @@ $(document).ready(function () {
     if (e.layer == noteLayer) {
       map.off("moveend", loadNotes);
       noteLayer.clearLayers();
+      notes = {};
     }
   });
 
+  map.on("popupopen", function (e) {
+    $(e.popup._container).find(".comment").focus();
+  });
+
   map.on("popupclose", function (e) {
     if (newNote && e.popup == newNote._popup) {
       $(newNote).oneTime(10, "removenote", function () {
         map.removeLayer(newNote);
+        newNote = null;
       });
     }
   });
@@ -69,22 +75,22 @@ $(document).ready(function () {
   }
 
   function updateMarker(marker, feature) {
-    var icon = noteIcons[feature.properties.status];
-    var popupContent = createPopupContent(marker, feature.properties);
-
     if (marker)
     {
       marker.setIcon(noteIcons[feature.properties.status]);
-      marker._popup.setContent(popupContent);
+      marker._popup.setContent(createPopupContent(marker, feature.properties));
     }
     else
     {
       marker = L.marker(feature.geometry.coordinates.reverse(), {
-        icon: icon,
+        icon: noteIcons[feature.properties.status],
         opacity: 0.7
       });
 
-      marker.addTo(noteLayer).bindPopup(popupContent, popupOptions());
+      marker.addTo(noteLayer).bindPopup(
+        createPopupContent(marker, feature.properties),
+        popupOptions()
+      );
     }
 
     return marker;
@@ -169,6 +175,7 @@ $(document).ready(function () {
     $.ajax({
       url: url,
       type: "POST",
+      oauth: true,
       data: {
         lat: location.lat,
         lon: location.lng,
@@ -176,8 +183,8 @@ $(document).ready(function () {
       },
       success: function (feature) {
         notes[feature.properties.id] = updateMarker(marker, feature);
+        newNote = null;
 
-        $(".leaflet-popup-close-button").off("click.close");
         $("#createnoteanchor").removeClass("disabled").addClass("geolink");
       }
     });
@@ -189,6 +196,7 @@ $(document).ready(function () {
     $.ajax({
       url: url,
       type: "POST",
+      oauth: true,
       data: {
         text: $(form.text).val()
       },