This repository has been archived on 2025-08-18. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
FeedMonkey/js/application.js
2013-08-25 03:54:25 +02:00

38 lines
909 B
JavaScript

function debug(obj) {
if(typeof obj != "string")
obj = JSON.stringify(obj);
alert(obj)
}
function $(obj) {
if(typeof obj == "string") return document.querySelector(obj);
else return obj;
}
function $$(obj) {
if(typeof obj == "string") return document.querySelectorAll(obj);
else return new NodeList(obj);
}
Object.getOwnPropertyNames(Array.prototype).forEach(function(methodName) {
NodeList.prototype[methodName] = Array.prototype[methodName];
});
Node.prototype.hasClass = function(cls) {
return this.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
};
Node.prototype.addClass = function(cls) {
if (!this.hasClass(cls)) this.className += " " + cls;
};
Node.prototype.removeClass = function(cls) {
if (this.hasClass(cls)) {
var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
this.className = this.className.replace(reg,' ');
}
};
if(!window.app) window.app = new App();