if (undefined === HTMLElement.prototype.addClass) {
Object.assign(HTMLElement.prototype, {
addClass: function(className) {
if (this.classList) {
this.classList.add(className);
}
return this;
},
removeClass: function(className) {
if (this.classList) {
this.classList.remove(className);
}
return this;
},
toggleClass: function(className, toggle) {
toggle ? this.addClass(className) : this.removeClass(className);
return this;
},
hasClass: function(className) {
if (this.classList) {
return this.classList.contains(className);
}
return undefined;
},
show: function() {
if (this.style) {
this.style.display = "block";
}
return this;
},
hide: function() {
if (this.style) {
this.style.display = "none";
}
return this;
},
appendBefore: function (element) {
this.parentElement && this.parentElement.insertBefore(element, this);
},
appendAfter: function (element) {
this.parentElement && this.parentElement.insertBefore(element, this.nextSibling);
},
data: function(offset, value) {
var attrName = 'data-' + offset;
return undefined !== value
? this.setAttribute(attrName, value)
: this.getAttribute(attrName);
},
hasData: function(offset) {
return this.hasAttribute('data-' + offset);
},
removeData: function(offset) {
return this.removeAttribute('data-' + offset);
}
});
}
// manage compatibility with previous browser
if (undefined === NodeList.prototype.forEach) {
Object.assign(NodeList.prototype, {
forEach: function(callback) {
for (var index = 0; index < this.length; index++) {
callback(this[index], index, this);
}
}
});
}
if (undefined === String.hashCode) {
String.prototype.hashCode = function() {
var hash = 0, i = 0, len = this.length;
while ( i < len ) {
hash = ((hash << 5) - hash + this.charCodeAt(i++)) << 0;
}
return hash;
};
}