-
Notifications
You must be signed in to change notification settings - Fork 2
/
quick.js
98 lines (77 loc) · 2.92 KB
/
quick.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
//
// █▀█ █░█ █ █▀▀ █▄▀ ░ ░░█ █▀ version
// ▀▀█ █▄█ █ █▄▄ █░█ ▄ █▄█ ▄█ 1.7.2
//
//
var _ = (function () {
'use strict';
var quick = {};
quick.edit = function (elem, text) {
if (typeof elem === "string") return document.querySelector(elem).innerHTML = text
elem.innerHTML = text
}
quick.addClass = function(elem, classname) {
if (!elem) throw new Error("Element parameter is not set!")
if (!classname) throw new Error("Class parameter is not set!")
if (typeof elem === "string") return document.querySelector(elem).classList.add(classname)
elem.classList.add(classname)
}
quick.getType = function(elem) {
return typeof elem
}
quick.setCSS = function (elem, prop, value) {
if (!elem) throw new Error("Element parameter is not set!")
if (!prop) throw new Error("Property parameter is not set!")
if (!value) throw new Error("Value parameter is not set!")
if (typeof elem === "string") return document.querySelector(elem).style.setProperty(prop, value)
elem.style.setProperty(prop, value)
}
quick.hide = function(elem) {
if (typeof elem == "string") return document.querySelector(elem).style.display = "none"
elem.style.display = "none"
}
quick.show = function(elem) {
if (typeof elem == "string") return document.querySelector(elem).style.removeProperty("display")
}
quick.toggle = function(elem) {
if (typeof elem == "string") {
var e = document.querySelector(elem)
if (e.style.display == "none") {
return e.style.removeProperty("display")
} else {
return e.style.display = "none"
}
}
if (elem.style.display == "none") {
return elem.style.removeProperty("display")
} else {
return elem.style.display = "none"
}
}
quick.removeClass = function(elem, classname) {
if (typeof elem === "string") return document.querySelector(elem).classList.remove(classname)
elem.classList.remove(classname)
}
quick.get = function(elem) {
if (!elem) throw new Error("No query selector provided")
return document.querySelector(elem)
}
quick.loop = function(times, callback) {
for (var i = 0; i < times; i++){
callback();
}
}
quick.on = function (elem, event, callback, useCapture) {
if (!elem) throw new Error('Please provide an element to attach the event to.');
if (!event) throw new Error('Please provide an event to listen for.');
if (!callback) throw new Error('Please provide a callback to run');
if (typeof elem === "string") return document.querySelector(elem).addEventListener(event, callback, useCapture || false);
elem.addEventListener(event, callback, useCapture || false);
};
quick.redirect = function (url) {
if (!url) throw new Error("No URL parameter provided")
document.location.href = url
}
return quick;
})();