X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/078059b76b8304368fd7ddac2dd563470e83472e..5fdada204cf92d8ca99300927713724aaaf1b2bd:/app/assets/javascripts/leaflet.query.js?ds=sidebyside diff --git a/app/assets/javascripts/leaflet.query.js b/app/assets/javascripts/leaflet.query.js index 3eab9054d..5f449c214 100644 --- a/app/assets/javascripts/leaflet.query.js +++ b/app/assets/javascripts/leaflet.query.js @@ -2,16 +2,35 @@ L.OSM.query = function (options) { var control = L.control(options); control.onAdd = function (map) { - var $container = $('
') - .attr('class', 'control-query'); - - var link = $('') - .attr('class', 'control-button') - .attr('href', '#') - .attr('data-original-title', I18n.t('javascripts.site.queryfeature_tooltip')) - .html('') + var $container = $("
") + .attr("class", "control-query"); + + var link = $("") + .attr("class", "control-button") + .attr("href", "#") + .html("") .appendTo($container); + map.on("zoomend", update); + + update(); + + function update() { + var wasDisabled = link.hasClass("disabled"), + isDisabled = map.getZoom() < 14; + link + .toggleClass("disabled", isDisabled) + .attr("data-original-title", I18n.t(isDisabled ? + "javascripts.site.queryfeature_disabled_tooltip" : + "javascripts.site.queryfeature_tooltip")); + + if (isDisabled && !wasDisabled) { + link.trigger("disabled"); + } else if (wasDisabled && !isDisabled) { + link.trigger("enabled"); + } + } + return $container[0]; };