dom-class.js revision 0fa21f434cf7d4ed63d790f8fb2a9c68e656d00e
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Determines whether a DOM element has the given className.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method hasClass
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {HTMLElement} element The DOM element.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {String} className the class name to search for
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @return {Boolean} Whether or not the element has the given class.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp var re = Y.DOM._getRegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
87a49173dbc22a145cb87e605cca83fd42524377Tripp * Adds a class name to a given DOM element.
87a49173dbc22a145cb87e605cca83fd42524377Tripp * @method addClass
87a49173dbc22a145cb87e605cca83fd42524377Tripp * @param {HTMLElement} element The DOM element.
87a49173dbc22a145cb87e605cca83fd42524377Tripp * @param {String} className the class name to add to the class attribute
87a49173dbc22a145cb87e605cca83fd42524377Tripp if (!Y.DOM.hasClass(node, className)) { // skip if already present
87a49173dbc22a145cb87e605cca83fd42524377Tripp node.className = Y.Lang.trim([node.className, className].join(' '));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Removes a class name from a given element.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method removeClass
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {HTMLElement} element The DOM element.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {String} className the class name to remove from the class attribute
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp node.className = Y.Lang.trim(node.className.replace(Y.DOM._getRegExp('(?:^|\\s+)' +
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if ( hasClass(node, className) ) { // in case of multiple adjacent
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Replace a class with another class for a given element.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * If no oldClassName is present, the newClassName is simply added.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method replaceClass
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {HTMLElement} element The DOM element.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {String} oldClassName the class name to be replaced
87a49173dbc22a145cb87e605cca83fd42524377Tripp * @param {String} newClassName the class name that will be replacing the old class name
87a49173dbc22a145cb87e605cca83fd42524377Tripp //Y.log('replaceClass replacing ' + oldC + ' with ' + newC, 'info', 'Node');
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * If the className exists on the node it is removed, if it doesn't exist it is added.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method toggleClass
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {HTMLElement} element The DOM element.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {String} className the class name to be toggled