]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.note.js
Fix new rubocop warnings
[rails.git] / app / assets / javascripts / leaflet.note.js
index 77fb9baff90f3afc6936dfdd7d4a599fda8daf30..5f801096731793a376ca0c3cdf0f729c2c2312a5 100644 (file)
@@ -2,16 +2,28 @@ L.OSM.note = function (options) {
   var control = L.control(options);
 
   control.onAdd = function (map) {
-    var $container = $('<div>')
-      .attr('class', 'control-note');
+    var $container = $("<div>")
+      .attr("class", "control-note");
 
-    $('<a>')
-      .attr('class', 'control-button')
-      .attr('href', '#')
-      .attr('title', I18n.t('javascripts.notes.new.add'))
-      .html('<span class="icon note"></span>')
+    var link = $("<a>")
+      .attr("class", "control-button")
+      .attr("href", "#")
+      .html("<span class=\"icon note\"></span>")
       .appendTo($container);
 
+    map.on("zoomend", update);
+
+    function update() {
+      var disabled = OSM.STATUS === "database_offline" || map.getZoom() < 12;
+      link
+        .toggleClass("disabled", disabled)
+        .attr("data-bs-original-title", I18n.t(disabled ?
+          "javascripts.site.createnote_disabled_tooltip" :
+          "javascripts.site.createnote_tooltip"));
+    }
+
+    update();
+
     return $container[0];
   };