-
Notifications
You must be signed in to change notification settings - Fork 0
/
jss.js
46 lines (32 loc) · 984 Bytes
/
jss.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
const jss = (function () {
"use strict";
/// Constructor
/// params el string the query selector
//// params props object of property and values
function Constructor(el, props) {
/// save the query selector
this.el = el;
/// save elements in selector variable
this.NodeList = document.querySelectorAll(el);
/// call the style function to apply the styles passed in props object
this.style(props)
}
//// style function
/// params props object of property and values
Constructor.prototype.style = function(props){
/// get the array of keys
let keys = Object.keys(props);
//// run this function for element
this.NodeList.forEach(function (item) {
//// run this code for each key
keys.forEach((key) => {
//// change the style
item.style[key] = props[key];
});
});
}
//// return a function that returns new constructor
return function (el, props) {
return new Constructor(el, props);
};
})();