58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
class Utils {
|
|
|
|
$(className) {
|
|
return document.querySelector(className);
|
|
}
|
|
|
|
_(className) {
|
|
return document.querySelectorAll(className);
|
|
}
|
|
|
|
|
|
e(className, callback, type = "click",) {
|
|
$(`${className}`)[`on${type}`] = (event) => {
|
|
callback(event)
|
|
}
|
|
}
|
|
|
|
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"
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
getRandom(min, max) {
|
|
const floatRandom = Math.random()
|
|
const difference = max - min
|
|
const random = Math.round(difference * floatRandom)
|
|
const randomWithinRange = random + min
|
|
return randomWithinRange
|
|
}
|
|
|
|
}
|
|
|
|
let { $, _, e, customMethods, getRandom } = new Utils()
|
|
customMethods()
|
|
// let utils = new Utils()
|