Skip to content

Commit

Permalink
Hide dark mode context menu items when not applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed May 13, 2024
1 parent 184cc83 commit 54abed4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion vendor/assets/leaflet/leaflet.osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,25 @@ L.OSM.DarkMode = L.Class.extend({
}, this);

var updateContextMenuElements = function () {
var numberOfLayersWithApplicableFilter = 0;
map.eachLayer(function (layer) {
if (layer instanceof L.OSM.TileLayer) {
if (!layer.options.darkUrl) {
numberOfLayersWithApplicableFilter++;
}
}
});
contextMenuElements.forEach(function (menuElement) {
menuElement.hidden = !this._enabled;
menuElement.hidden = !this._enabled || numberOfLayersWithApplicableFilter == 0;
if ('filter' in menuElement.dataset) {
menuElement.firstChild.checked = menuElement.dataset.filter === this._darkFilter;
}
}, this);
}.bind(this);
updateContextMenuElements();
this._contextMenuUpdateHandlers.push(updateContextMenuElements);
map.on("layeradd", updateContextMenuElements);
map.on("layerremove", updateContextMenuElements);

return this;
},
Expand Down

0 comments on commit 54abed4

Please sign in to comment.