]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.note.js
Merge remote-tracking branch 'upstream/pull/5451'
[rails.git] / app / assets / javascripts / leaflet.note.js
1 L.OSM.note = function (options) {
2   var control = L.control(options);
3
4   control.onAdd = function (map) {
5     var $container = $("<div>")
6       .attr("class", "control-note");
7
8     var link = $("<a>")
9       .attr("class", "control-button")
10       .attr("href", "#")
11       .html("<span class=\"icon note\"></span>")
12       .appendTo($container);
13
14     map.on("zoomend", update);
15
16     function update() {
17       var wasDisabled = link.hasClass("disabled"),
18           isDisabled = OSM.STATUS === "database_offline" || map.getZoom() < 12;
19       link
20         .toggleClass("disabled", isDisabled)
21         .attr("data-bs-original-title", I18n.t(isDisabled ?
22           "javascripts.site.createnote_disabled_tooltip" :
23           "javascripts.site.createnote_tooltip"));
24
25       if (isDisabled && !wasDisabled) {
26         link.trigger("disabled");
27       } else if (wasDisabled && !isDisabled) {
28         link.trigger("enabled");
29       }
30     }
31
32     update();
33
34     return $container[0];
35   };
36
37   return control;
38 };