57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
class Utils {
|
|
|
|
$(className) {
|
|
return document.querySelector(className);
|
|
}
|
|
|
|
_(className) {
|
|
return document.querySelectorAll(className);
|
|
}
|
|
|
|
|
|
click(className, callback, type = "click",) {
|
|
$(`${className}`)[`on${type}`] = (event) => {
|
|
callback(event)
|
|
}
|
|
}
|
|
|
|
query(name) {
|
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
|
var r = window.location.search.substr(1).match(reg);
|
|
if (r != null)
|
|
return unescape(r[2]);
|
|
return null;
|
|
}
|
|
|
|
customMethods() {
|
|
Element.prototype.add = function(className) {
|
|
this.classList.add(className)
|
|
}
|
|
|
|
Element.prototype.remove = function(className) {
|
|
this.classList.remove(className)
|
|
}
|
|
|
|
Element.prototype.none = function() {
|
|
this.style.display = "none"
|
|
}
|
|
|
|
Element.prototype.show = function() {
|
|
this.style.display = "block"
|
|
}
|
|
|
|
Element.prototype.toggle = function() {
|
|
if (this.style.display == "none") {
|
|
this.style.display = "block"
|
|
} else {
|
|
this.style.display = "none"
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
let { $, _, click, customMethods, query } = new Utils()
|
|
customMethods()
|