X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/e96a64ca9c2ea068dd9167e074ee26c8d28744b4..2b252e8337109de714bb8aa38ccf6d46e7686e42:/app/assets/javascripts/leaflet.key.js?ds=sidebyside diff --git a/app/assets/javascripts/leaflet.key.js b/app/assets/javascripts/leaflet.key.js index cf54b2ded..58bfbf6d2 100644 --- a/app/assets/javascripts/leaflet.key.js +++ b/app/assets/javascripts/leaflet.key.js @@ -5,24 +5,30 @@ L.OSM.key = function (options) { var $container = $('
') .attr('class', 'control-key'); - $('') + var button = $('') .attr('class', 'control-button') .attr('href', '#') - .attr('title', I18n.t('javascripts.key.tooltip')) .html('') .on('click', toggle) .appendTo($container); var $ui = $('
') - .attr('class', 'layers-ui'); + .attr('class', 'key-ui'); - $('
') + $('
') + .attr('class', 'sidebar_heading') .appendTo($ui) .append( - $('

') - .text(I18n.t('javascripts.key.title'))); + $('') + .text(I18n.t('javascripts.close')) + .attr('class', 'icon close') + .bind('click', toggle)) + .append( + $('

') + .text(I18n.t('javascripts.key.title'))); - var $section = $('
') + var $section = $('
') + .attr('class', 'section') .appendTo($ui); options.sidebar.addPane($ui); @@ -31,6 +37,10 @@ L.OSM.key = function (options) { .on('show', shown) .on('hide', hidden); + map.on('baselayerchange', updateButton); + + updateButton(); + function shown() { map.on('zoomend baselayerchange', update); $section.load('/key', update); @@ -43,11 +53,23 @@ L.OSM.key = function (options) { function toggle(e) { e.stopPropagation(); e.preventDefault(); - options.sidebar.togglePane($ui); + if (!button.hasClass('disabled')) { + options.sidebar.togglePane($ui, button); + } + $('.leaflet-control .control-button').tooltip('hide'); + } + + function updateButton() { + var disabled = map.getMapBaseLayerId() !== 'mapnik' + button + .toggleClass('disabled', disabled) + .attr('data-original-title', I18n.t(disabled ? + 'javascripts.key.tooltip_disabled' : + 'javascripts.key.tooltip')) } function update() { - var layer = getMapBaseLayerId(map), + var layer = map.getMapBaseLayerId(), zoom = map.getZoom(); $('.mapkey-table-entry').each(function () {