-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjcolor.js
94 lines (61 loc) · 1.94 KB
/
jcolor.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
(function(global){
const defaultArr = ['9984D4', 'C9E3AC', 'E8D6CB', 'BFD7EA', 'D4EAC8', 'D0ADA7'];
var clrArray;
//Default function that is being called
var color = function(selector, elem,colors, callback){
popup(selector,elem,colors, callback);
}
//creates inner division
function popup( selector, elem, colors, callback){
if(typeof colors !== "undefined"){
clrArray = colors;
}
else{
clrArray = defaultArr;
}
var wrapper = document.createElement("div");
var select = selector;
select.append(wrapper);
content(wrapper);
//selector settings
select.style.pointerEvents ="none";
select.style.position = "relative";
//wrapper styling
wrapper.style.width = "140px";
wrapper.style.position = "absolute";
wrapper.style.bottom = "110%";
wrapper.style.left = "50%";
wrapper.style.marginLeft = "-80px";
var colorStlye = document.querySelectorAll(".color");
for(var i=0; i<colorStlye.length; i++)
colorStlye[i].addEventListener("click", function(event){
event.stopImmediatePropagation();
if(typeof elem !== "undefined")
elem.style.backgroundColor = "#" + this.id;
else
select.style.backgroundColor = "#" + this.id;
wrapper.remove();
select.style.pointerEvents = "auto";
callback("#" + this.id);
});
}
//content of the inner Division
function content(wrapper){
for(var i = 0; i<clrArray.length; i++){
var dv = document.createElement("div");
wrapper.append(dv);
dv.style.backgroundColor = "#" + clrArray[i];
dv.style.borderRadius = "90px";
wrapper.style.borderRadius = "3px";
wrapper.style.pointerEvents ="none";
dv.style.display = "inline-block";
dv.style.width = "40px";
dv.style.height = "40px";
dv.id = clrArray[i];
dv.setAttribute("class", "color");
dv.style.pointerEvents = "all";
wrapper.style.backgroundColor = '#EEEEEE';
}
}
global.color = color;
}(window));