-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
98 lines (81 loc) · 1.71 KB
/
index.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
/**
* element-classlist
* Element class list component
*
* @copyright 2013 Enrico Marino
* @license MIT
*/
/**
* Expose `classlist`
*/
module.exports = classlist;
/**
* classlist
*/
function classlist (element) {
/**
* Utils
*/
var array = [];
var slice = array.slice;
/**
* add_class
* Add class `name` if not already present.
*
* @param {String} name class name
* @return {Element} this for chaining
* @api public
*/
element.prototype.add_class = function (name) {
this.el.classList.add(name);
return this;
};
/**
* remove_class
* Remove class `name` when present
*
* @param {String} name class to remove
* @return {Element} this for chaining
* @api public
*/
element.prototype.remove_class = function (name) {
this.el.classList.remove(name);
return this;
};
/**
* toggle_class
* Toggle class `name`.
*
* @param {String} name class to toggle
* @return {ClassList} this for chaining
* @api public
*/
element.prototype.toggle_class = function (name) {
this.el.classList.toggle(name);
return this;
};
/**
* classes
* Return an array of classes.
*
* @return {Array} array of classes
* @api public
*/
element.prototype.classes = function () {
return slice.call(this.el.classList);
};
/**
* has_class|contain_class
* Check if class `name` is present.
*
* @param {String} name class name to check
* @return {Boolean} true if class `name` is present
* false otherwise
* @api public
*/
element.prototype.has_class =
element.prototype.contains_class = function (name) {
return this.list.contains(name);
};
return element;
}