Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
49 lines
1.5 KiB
JavaScript
Executable file
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);
|
|
}
|