Y-SLD/assets/plugins/leaflet/leaflet-measure/src/dom.js

37 lines
860 B
JavaScript
Raw Normal View History

2024-03-01 11:23:55 +00:00
// dom.js
// utility functions for managing DOM elements
var selectOne = function (selector, el) {
if (!el) {
el = document;
}
return el.querySelector(selector);
};
var selectAll = function (selector, el) {
if (!el) {
el = document;
}
return Array.prototype.slice.call(el.querySelectorAll(selector));
};
var hide = function (el) {
if (el) {
el.setAttribute('style', 'display:none;');
return el;
}
};
var show = function (el) {
if (el) {
el.removeAttribute('style');
return el;
}
};
module.exports = {
$: selectOne, // `$('.myclass', baseElement)` - returns selected element or undefined
$$: selectAll, // `$$('.myclass', baseElement)` - returns array of selected elements
hide: hide, // `hide(someElement)` - hide passed dom element
show: show // `show(someElement)` - show passed dom element
};