Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added html class functions to JS Performance
- Loading branch information
1 parent
ab8d972
commit e677bda
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
})(); |