]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.note.js
Switch to bootstrap recommended viewport definition
[rails.git] / app / assets / javascripts / leaflet.note.js
index 24f18f7ab3f66de38f3351eb146c68fcf1232491..5f801096731793a376ca0c3cdf0f729c2c2312a5 100644 (file)
@@ -1,39 +1,31 @@
-L.Control.Note = L.Control.extend({
-    options: {
-        position: 'topright',
-        title: 'Notes',
-    },
+L.OSM.note = function (options) {
+  var control = L.control(options);
 
-    onAdd: function (map) {
-        var className = 'control-note',
-            container = L.DomUtil.create('div', className);
+  control.onAdd = function (map) {
+    var $container = $("<div>")
+      .attr("class", "control-note");
 
-        var link = L.DomUtil.create('a', 'control-button', container);
-        link.innerHTML = "<span class='icon note'></span>";
-        link.href = '#';
-        link.title = this.options.title;
+    var link = $("<a>")
+      .attr("class", "control-button")
+      .attr("href", "#")
+      .html("<span class=\"icon note\"></span>")
+      .appendTo($container);
 
-        L.DomEvent
-            .on(link, 'click', L.DomEvent.stopPropagation)
-            .on(link, 'click', L.DomEvent.preventDefault)
-            .on(link, 'click', this._toggle, this)
-            .on(link, 'dblclick', L.DomEvent.stopPropagation);
+    map.on("zoomend", update);
 
-        this.map = map;
+    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"));
+    }
 
-        return container;
-    },
+    update();
 
-    // TODO: this relies on notesLayer on the map
-    _toggle: function() {
-        if (this.map.hasLayer(this.map.noteLayer)) {
-            this.map.removeLayer(this.map.noteLayer);
-        } else {
-            this.map.addLayer(this.map.noteLayer);
-        }
-    }
-});
+    return $container[0];
+  };
 
-L.control.note = function(options) {
-    return new L.Control.Note(options);
+  return control;
 };