diff --git a/common/HTMLElement.js b/common/HTMLElement.js new file mode 100644 index 0000000..8b473ac --- /dev/null +++ b/common/HTMLElement.js @@ -0,0 +1,32 @@ +HTMLElement.prototype.removeClass || (HTMLElement.prototype.removeClass = function(remove) { + var newClassName = ""; + var i; + var classes = this.className.split(" "); + for(i = 0; i < classes.length; i++) { + if(classes[i] !== remove) { + newClassName += classes[i] + " "; + } + } + this.className = newClassName; +}); + +HTMLElement.prototype.hasClass || (HTMLElement.prototype.hasClass = function(cls) { + return (' ' + this.className + ' ').indexOf(' ' + cls + ' ') > -1; +}); + +HTMLElement.prototype.addClass || (HTMLElement.prototype.addClass = function(add) { + if(this.hasClass(add)) return; + this.className += ' ' + add; +}); + +HTMLElement.prototype.toggleClass || (HTMLElement.prototype.toggleClass = function(clazz) { + if(this.hasClass(clazz)) { + this.removeClass(clazz); + } else { + this.addClass(clazz); + } +}); + +HTMLElement.prototype.remove || (HTMLElement.prototype.remove = function() { + this.parentElement.removeChild(this); +});