Navigation Menu

Skip to content

Commit

Permalink
Added html class functions to JS Performance
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeiscontent committed Mar 14, 2012
1 parent ab8d972 commit e677bda
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions js/html-class-functions.js
@@ -0,0 +1,48 @@
(function() {
var __elementPrototype;
__elementPrototype = Element.prototype;
/*!
* JavaScript hasClass|addClass|removeClass implementations.
* Copyright(c) 2011 Aaron Reisman <aaron@lifeiscontent.net>
* MIT Licensed
*/

/**
* Return a `Boolean` from the given `className`.
*
* @param {String} className
* @return {Boolean}
* @api public
*/

__elementPrototype.hasClass = function(className) {
var testStr;
className = ' '+className+' ';
testStr = ' '+this.className+' ';
return testStr.indexOf(className) > -1;
};

/**
* Return a `Boolean` from the given `className` that will be added.
*
* @param {String} className
* @return {Boolean}
* @api public
*/

__elementPrototype.addClass = function(className) {
return (this.hasClass(className)) ? false : !!(this.className += ' '+className);
};

/**
* Return a `Boolean` from the given `className` that will be removed.
*
* @param {String} className
* @return {Boolean}
* @api public
*/

__elementPrototype.removeClass = function(className) {
return (this.hasClass(className)) ? !!(this.className = this.className.replace(className, '')) : false;
};
})();

0 comments on commit e677bda

Please sign in to comment.