X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/7094370208712e77d92ea2ad0d76e160742d6c0a..b8a1a904c6273252c56998178b69f5f65d744d69:/app/assets/javascripts/leaflet.note.js diff --git a/app/assets/javascripts/leaflet.note.js b/app/assets/javascripts/leaflet.note.js index a38e012de..19fc9392c 100644 --- a/app/assets/javascripts/leaflet.note.js +++ b/app/assets/javascripts/leaflet.note.js @@ -2,17 +2,35 @@ L.OSM.note = function (options) { var control = L.control(options); control.onAdd = function (map) { - var $container = $('
') - .attr('class', 'control-note'); - - $('') - .attr('id', 'createnoteanchor') - .attr('class', 'control-button geolink') - .attr('data-minzoom', 12) - .attr('href', '#') - .html('') + var $container = $("
") + .attr("class", "control-note"); + + var link = $("") + .attr("class", "control-button") + .attr("href", "#") + .html("") .appendTo($container); + map.on("zoomend", update); + + function update() { + var 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) { + link.trigger("disabled"); + } else if (wasDisabled && !isDisabled) { + link.trigger("enabled"); + } + } + + update(); + return $container[0]; };