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-09-20 13:54:28 +02:00

58 lines
1.3 KiB
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,' ');
}
};
var __entityMap = {
"&": "&",
"<": "&lt;",
">": "&gt;"
};
String.prototype.escapeHTML = function() {
return String(this).replace(/[&<>]/g, function (s) {
return __entityMap[s];
});
}
String.prototype.stripHTML = function() {
return this.replace(/(<([^>]+)>)/ig, "");
}
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
if(!window.app) window.app = new App();