]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.note.js
Merge remote-tracking branch 'upstream/pull/5685'
[rails.git] / app / assets / javascripts / leaflet.note.js
index a38e012de63cff6f3640ef8b962b127275bd793f..e2ca4ffdfda3409580525a33df000b08d1e66c6f 100644 (file)
@@ -1,18 +1,32 @@
 L.OSM.note = function (options) {
-  var control = L.control(options);
+  const control = L.control(options);
 
   control.onAdd = function (map) {
-    var $container = $('<div>')
-      .attr('class', 'control-note');
+    const $container = $("<div>")
+      .attr("class", "control-note");
 
-    $('<a>')
-      .attr('id', 'createnoteanchor')
-      .attr('class', 'control-button geolink')
-      .attr('data-minzoom', 12)
-      .attr('href', '#')
-      .html('<span class="icon note"></span>')
+    const link = $("<a>")
+      .attr("class", "control-button")
+      .attr("href", "#")
+      .html("<span class=\"icon note\"></span>")
       .appendTo($container);
 
+    map.on("zoomend", update);
+
+    function update() {
+      const wasDisabled = link.hasClass("disabled"),
+            isDisabled = OSM.STATUS === "database_offline" || map.getZoom() < 12;
+      link
+        .toggleClass("disabled", isDisabled)
+        .attr("data-bs-original-title", I18n.t(isDisabled ?
+          "javascripts.site.createnote_disabled_tooltip" :
+          "javascripts.site.createnote_tooltip"));
+      if (isDisabled === wasDisabled) return;
+      link.trigger(isDisabled ? "disabled" : "enabled");
+    }
+
+    update();
+
     return $container[0];
   };