module.exports = { /** * Removes all node childs. * * @param {Node} node The HTML Node */ removeChilds: function (node) { var childs = node.childNodes; if (childs) while (childs.length > 0) node.removeChild (childs[0]); } /** * Removes a node from the document. * * @param {Node} node The HTML Node */ ,remove: function (node) { if (node.parentNode) node.parentNode.removeChild (node); } /** * Replaces the node child/s with another one. * * @param {Node} node The HTML Node * @param {Node} child The new child or %null to set an empty node */ ,setChild: function (node, child) { this.removeChilds (node); if (child) node.appendChild (child); } /** * Replaces the node text/childs with text. * * @param {Node} node The HTML Node * @param {Node} child The new node text or %null for no text */ ,setText: function (node, text) { this.removeChilds (node); if (text) node.appendChild ( node.ownerDocument.createTextNode (text)); } /** * Adds a class to the node CSS classes. Note that this * function doesn't check if the node already has the class. * * @param {Node} node The HTML element * @param {string} className The CSS class name */ ,addClass: function (node, className) { node.className = className +' '+ node.className; } /** * Removes a class from the node CSS classes. This functions * removes all ocurrences of the class from the node. * * @param {Node} node The HTML element * @param {string} className The CSS class name */ ,removeClass: function (node, className) { var index = 0; var found = false; var classes = node.className.split (' '); while ((index = classes.indexOf (className, index)) != -1) { classes.splice (index, 1); found = true; } if (found) node.className = classes.join (' '); } /** * Hides the node from the document. * * @param {Node} node The HTML element */ ,hide: function (node) { node.style.visibility = 'none'; } /** * Shows a hidden node. * * @param {Node} node The HTML element * @param {String} displayValue The CSS display value when it's displayed, * if it isn't specified 'block' is used */ ,show: function (node, displayValue) { node.style.display = displayValue ? displayValue : 'block'; } /** * Shows or hides node. * * @param {Node} node The HTML element * @param {Boolean} display Wheter to display the node * @param {String} displayValue The CSS display value when it's displayed, * if it isn't specified 'block' is used */ ,display: function (node, display, displayValue) { if (display) this.show (node, displayValue); else this.hide (node); } /** * Shows or hides node. * * @param {Node} node The HTML Node * @param {Boolean} visible Wheter to display the node */ ,setVisible: function (node, visible) { node.style.visibility = visible ? 'visible' : 'hidden'; } };