move stuff in common.js around a bit

This commit is contained in:
Andrew Dolgov 2021-02-19 06:40:35 +03:00
parent 5475eed452
commit d57e7eaa98
1 changed files with 14 additions and 16 deletions

View File

@ -27,8 +27,6 @@ Element.prototype.removeClassName = function(className) {
};
Element.prototype.toggleClassName = function(className) {
console.log(this, className);
if (this.hasClassName(className))
return this.removeClassName(className);
else
@ -97,6 +95,20 @@ Element.hasClassName = function (elem, className) {
return elem.hasClassName(className);
}
Array.prototype.remove = function(s) {
for (let i=0; i < this.length; i++) {
if (s == this[i]) this.splice(i, 1);
}
};
Array.prototype.uniq = function() {
return this.filter((v, i, a) => a.indexOf(v) === i);
};
String.prototype.stripTags = function() {
return this.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?(\/)?>|<\/\w+>/gi, '');
}
/* xhr shorthand helpers */
/* exported xhrPost */
@ -122,20 +134,6 @@ function xhrPost(url, params = {}, complete = undefined) {
});
}
Array.prototype.remove = function(s) {
for (let i=0; i < this.length; i++) {
if (s == this[i]) this.splice(i, 1);
}
};
Array.prototype.uniq = function() {
return this.filter((v, i, a) => a.indexOf(v) === i);
};
String.prototype.stripTags = function() {
return this.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?(\/)?>|<\/\w+>/gi, '');
}
/* exported xhrJson */
function xhrJson(url, params = {}, complete = undefined) {
return new Promise((resolve, reject) =>