VulpesOS/gaia/shared/js/contacts/utilities/dom.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

49 lines
1.5 KiB
JavaScript
Executable file

'use strict';
var utils = window.utils || {};
if (!utils.dom) {
(function(document) {
var Dom = utils.dom = {};
// remove all children of a given parent node
Dom.removeChildNodes = function(node) {
while (node.hasChildNodes()) {
node.removeChild(node.firstChild);
}
};
// Given a container, applys the class passed to all the
// nodes matching a selector.
// CAUTION: Please be careful using this function as it could
// be quite expensive depending on the container and selector.
Dom.addClassToNodes = function(container, selector, clazz) {
var nodes = container.querySelectorAll(selector);
for (var i = 0, n = nodes.length; i < n; ++i) {
nodes[i].classList.add(clazz);
}
};
// Given a container, removes the class passed to all the
// nodes matching a selector.
// CAUTION: Please be careful using this function as it could
// be quite expensive depending on the container and selector.
Dom.removeClassFromNodes = function(container, selector, clazz) {
var nodes = container.querySelectorAll(selector);
for (var i = 0, n = nodes.length; i < n; ++i) {
nodes[i].classList.remove(clazz);
}
};
Dom.updatePhoto = function(photo, dest) {
var background = '';
if (photo != null) {
background = 'url(' + URL.createObjectURL(photo) + ')';
}
dest.style.backgroundImage = background;
// Only for testing purposes
dest.dataset.photoReady = 'true';
};
})(document);
}