chore: replace DomUtil.classIf by classList.toggle

cf #1342
This commit is contained in:
Yohan Boniface 2024-05-17 16:51:25 +02:00
parent 3a19b921a7
commit 26d4b439cd
5 changed files with 13 additions and 25 deletions

View file

@ -87,7 +87,7 @@ export default class Browser {
const parent = DomUtil.get(this.datalayerId(datalayer)) const parent = DomUtil.get(this.datalayerId(datalayer))
// Panel is not open // Panel is not open
if (!parent) return if (!parent) return
DomUtil.classIf(parent, 'off', !datalayer.isVisible()) parent.classList.toggle('off', !datalayer.isVisible())
const container = parent.querySelector('ul') const container = parent.querySelector('ul')
const headline = parent.querySelector('h5') const headline = parent.querySelector('h5')
const toggleList = () => parent.classList.toggle('show-list') const toggleList = () => parent.classList.toggle('show-list')

View file

@ -614,8 +614,8 @@ U.DataLayer.include({
} }
L.DomEvent.on(toggle, 'click', this.toggle, this) L.DomEvent.on(toggle, 'click', this.toggle, this)
L.DomEvent.on(zoomTo, 'click', this.zoomTo, this) L.DomEvent.on(zoomTo, 'click', this.zoomTo, this)
L.DomUtil.addClass(container, this.getHidableClass()) container.classList.add(this.getHidableClass())
L.DomUtil.classIf(container, 'off', !this.isVisible()) container.classList.toggle('off', !this.isVisible())
}, },
getHidableElements: function () { getHidableElements: function () {
@ -628,8 +628,8 @@ U.DataLayer.include({
propagateRemote: function () { propagateRemote: function () {
const els = this.getHidableElements() const els = this.getHidableElements()
for (let i = 0; i < els.length; i++) { for (const el of els) {
L.DomUtil.classIf(els[i], 'remotelayer', this.isRemoteLayer()) el.classList.toggle('remotelayer', this.isRemoteLayer())
} }
}, },
@ -820,7 +820,7 @@ const ControlsMixin = {
L.DomUtil.createIcon(row, 'icon-drag', L._('Drag to reorder')) L.DomUtil.createIcon(row, 'icon-drag', L._('Drag to reorder'))
datalayer.renderToolbox(row) datalayer.renderToolbox(row)
const title = L.DomUtil.add('span', '', row, datalayer.options.name) const title = L.DomUtil.add('span', '', row, datalayer.options.name)
L.DomUtil.classIf(row, 'off', !datalayer.isVisible()) row.classList.toggle('off', !datalayer.isVisible())
title.textContent = datalayer.options.name title.textContent = datalayer.options.name
row.dataset.id = L.stamp(datalayer) row.dataset.id = L.stamp(datalayer)
}) })

View file

@ -162,11 +162,6 @@ L.DomUtil.createCopiableInput = (parent, label, value) => {
return input return input
} }
L.DomUtil.classIf = (el, className, bool) => {
if (bool) L.DomUtil.addClass(el, className)
else L.DomUtil.removeClass(el, className)
}
L.DomUtil.element = ({ tagName, parent, ...attrs }) => { L.DomUtil.element = ({ tagName, parent, ...attrs }) => {
const el = document.createElement(tagName) const el = document.createElement(tagName)
if (attrs.innerHTML) { if (attrs.innerHTML) {

View file

@ -390,17 +390,10 @@ U.Map = L.Map.extend({
}, },
renderControls: function () { renderControls: function () {
L.DomUtil.classIf( const hasSlideshow = Boolean(this.options.slideshow && this.options.slideshow.active)
document.body, const barEnabled = this.options.captionBar || hasSlideshow
'umap-caption-bar-enabled', document.body.classList.toggle('umap-caption-bar-enabled', barEnabled)
this.options.captionBar || document.body.classList.toggle('umap-slideshow-enabled', hasSlideshow)
(this.options.slideshow && this.options.slideshow.active)
)
L.DomUtil.classIf(
document.body,
'umap-slideshow-enabled',
this.options.slideshow && this.options.slideshow.active
)
for (const control of Object.values(this._controls)) { for (const control of Object.values(this._controls)) {
this.removeControl(control) this.removeControl(control)
} }
@ -968,7 +961,7 @@ U.Map = L.Map.extend({
}, },
checkDirty: function () { checkDirty: function () {
L.DomUtil.classIf(this._container, 'umap-is-dirty', this.isDirty) this._container.classList.toggle('umap-is-dirty', this.isDirty)
}, },
addDirtyDatalayer: function (datalayer) { addDirtyDatalayer: function (datalayer) {

View file

@ -863,7 +863,7 @@ U.DataLayer = L.Evented.extend({
}, },
isRemoteLayer: function () { isRemoteLayer: function () {
return !!( return Boolean(
this.options.remoteData && this.options.remoteData &&
this.options.remoteData.url && this.options.remoteData.url &&
this.options.remoteData.format this.options.remoteData.format
@ -1528,7 +1528,7 @@ U.DataLayer = L.Evented.extend({
}, },
isVisible: function () { isVisible: function () {
return this.layer && this.map.hasLayer(this.layer) return Boolean(this.layer && this.map.hasLayer(this.layer))
}, },
getFeatureByIndex: function (index) { getFeatureByIndex: function (index) {