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
2014-02-04 21:44:02 +01:00

67 lines
1.5 KiB
JavaScript

function debug(obj) {
if(typeof obj != "string")
obj = JSON.stringify(obj);
else {
obj = arguments.join(' ')
}
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.htmlDecode = function() {
var e = document.createElement('div');
e.innerHTML = this;
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}
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();