-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQs.c.js
57 lines (52 loc) · 1.39 KB
/
Qs.c.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
// Classes
/**
* Adds and removes classes from an element.
* Stands for CLaSses.
*
* @param {Element} ele the element
* @param {string[]} add the classes to add
* @param {string[]} remove the classes to remove
*/
function cls (ele, add, remove) {
var addLength = add.length
var removeLength = remove.length
var i
for (i = 0; i < addLength; i += 1) {
ele.classList.add(add[i])
}
for (i = 0; i < removeLength; i += 1) {
ele.classList.remove(remove[i])
}
}
/**
* Adds and removes classes for each element that match the specified selectors.
* Stands for QueryAllCLaSses.
*
* @param {string} text the selectors
* @param {string[]} add the classes to add
* @param {string[]} remove the classes to remove
*/
function qacls (text, add, remove) {
var l = document.querySelectorAll(text)
var count = l.length
for (var i = 0; i < count; i += 1) {
cls(l[i], add, remove)
}
}
/**
* Adds and removes classes for each element that match the specified selectors
* inside a given parrent element.
* Stands for QueryAllSubCLaSses.
*
* @param {Element} sub the parrent element
* @param {string} text the selectors
* @param {string[]} add the classes to add
* @param {string[]} remove the classes to remove
*/
function qascls (sub, text, add, remove) {
var l = sub.querySelectorAll(text)
var count = l.length
for (var i = 0; i < count; i += 1) {
cls(l[i], add, remove)
}
}