2015-02-01 03:21:54 +00:00
|
|
|
|
2016-09-26 09:28:47 +00:00
|
|
|
module.exports =
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2016-12-20 09:32:17 +00:00
|
|
|
/**
|
|
|
|
* Removes all node childs.
|
|
|
|
*
|
|
|
|
* @param {Node} node The HTML Node
|
|
|
|
*/
|
2015-01-23 13:09:30 +00:00
|
|
|
removeChilds: function (node)
|
|
|
|
{
|
|
|
|
var childs = node.childNodes;
|
|
|
|
|
2015-07-07 15:27:47 +00:00
|
|
|
if (childs)
|
2015-01-23 13:09:30 +00:00
|
|
|
while (childs.length > 0)
|
|
|
|
node.removeChild (childs[0]);
|
|
|
|
}
|
|
|
|
|
2016-12-20 09:32:17 +00:00
|
|
|
/**
|
|
|
|
* Removes a node from the document.
|
|
|
|
*
|
|
|
|
* @param {Node} node The HTML Node
|
|
|
|
*/
|
2015-01-23 13:09:30 +00:00
|
|
|
,remove: function (node)
|
2015-11-09 08:14:33 +00:00
|
|
|
{
|
2015-07-07 15:27:47 +00:00
|
|
|
if (node.parentNode)
|
|
|
|
node.parentNode.removeChild (node);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2016-12-20 09:32:17 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2015-01-23 13:09:30 +00:00
|
|
|
,setText: function (node, text)
|
|
|
|
{
|
|
|
|
Vn.Node.removeChilds (node);
|
|
|
|
|
|
|
|
if (text)
|
2016-10-04 15:27:49 +00:00
|
|
|
node.appendChild (
|
|
|
|
node.ownerDocument.createTextNode (text));
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-07-15 13:39:07 +00:00
|
|
|
|
2016-12-20 09:32:17 +00:00
|
|
|
/**
|
|
|
|
* 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 Node
|
|
|
|
* @param {String} className The CSS class name
|
|
|
|
*/
|
2015-07-15 13:39:07 +00:00
|
|
|
,addClass: function (node, className)
|
|
|
|
{
|
2016-12-20 09:32:17 +00:00
|
|
|
node.className = className +' '+ node.className;
|
2015-07-15 13:39:07 +00:00
|
|
|
}
|
2016-12-20 09:32:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a class from the node CSS classes. This functions
|
|
|
|
* removes all ocurrences of the class from the node.
|
|
|
|
*
|
|
|
|
* @param {Node} node The HTML Node
|
|
|
|
* @param {String} className The CSS class name
|
|
|
|
*/
|
2015-07-15 13:39:07 +00:00
|
|
|
,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 (' ');
|
|
|
|
}
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2016-12-20 09:32:17 +00:00
|
|
|
/**
|
|
|
|
* Hides the node from the document.
|
|
|
|
*
|
|
|
|
* @param {Node} node The HTML Node
|
|
|
|
*/
|
2015-07-28 19:14:26 +00:00
|
|
|
,hide: function (node)
|
|
|
|
{
|
|
|
|
node.style.display = 'none';
|
|
|
|
}
|
|
|
|
|
2016-12-20 09:32:17 +00:00
|
|
|
/**
|
|
|
|
* Shows a hidden node.
|
|
|
|
*
|
|
|
|
* @param {Node} node The hidden HTML Node
|
|
|
|
*/
|
2015-07-28 19:14:26 +00:00
|
|
|
,show: function (node)
|
|
|
|
{
|
2015-09-22 07:20:47 +00:00
|
|
|
node.style.display = 'block';
|
2015-07-28 19:14:26 +00:00
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
};
|