Skip to content

Commit

Permalink
Mark current dark mode context menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed May 13, 2024
1 parent 21f672b commit 184cc83
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions vendor/assets/leaflet/leaflet.osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,26 @@ L.OSM.DarkMode = L.Class.extend({
text: menuItem.text,
callback: function () {
this._darkFilter = menuItem.filter;
this._contextMenuUpdateHandlers.forEach(function (handler) {
handler();
});
if (this._enabled) {
L.OSM.DarkMode._layers.forEach(function (layer) {
this._enableLayerDarkVariant(layer);
}, this);
}
}.bind(this)
});
this._decorateContextMenuElement(menuElement, menuItem);
contextMenuElements.push(menuElement);
}, this);

var updateContextMenuElements = function () {
contextMenuElements.forEach(function (menuElement) {
menuElement.hidden = !this._enabled;
if ('filter' in menuElement.dataset) {
menuElement.firstChild.checked = menuElement.dataset.filter === this._darkFilter;
}
}, this);
}.bind(this);
updateContextMenuElements();
Expand Down Expand Up @@ -164,6 +171,17 @@ L.OSM.DarkMode = L.Class.extend({
if (container) {
layer.getContainer().style.removeProperty('filter');
}
},

_decorateContextMenuElement: function (menuElement, menuItem) {
menuElement.dataset.filter = menuItem.filter;
var radio = document.createElement('input');
radio.type = 'radio';
radio.tabIndex = -1;
radio.classList.add('leaflet-contextmenu-icon');
radio.style.pointerEvents = 'none';
radio.style.transform = 'scale(80%)';
menuElement.prepend(radio, " ");
}
});

Expand Down

0 comments on commit 184cc83

Please sign in to comment.