forked from shyamtala003/gradient_container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
101 lines (74 loc) · 2.65 KB
/
main.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
99
100
101
// theme toggler
let themeTogglerBtn=document.getElementById('theme_toggler');
let styleLink=document.getElementById('css_link');
themeTogglerBtn.addEventListener("click",()=>{
let icon=Array.from(themeTogglerBtn.children);
if(icon[0].name==="moon")
{
icon[0].setAttribute("name","sunny");
styleLink.setAttribute("href","./css/dark.css");
}else
{
icon[0].setAttribute("name","moon");
styleLink.setAttribute("href","./css/white.css");
}
})
// copy to clipboard
let copyBtn = document.querySelectorAll('.copy_to_clipboard');
var clipboard = new ClipboardJS(copyBtn);
clipboard.on('success', function (e) {
let toastDiv = document.getElementById('notify_toast');
toastDiv.classList.add("show_toast");
setTimeout(() => {
toastDiv.classList.remove("show_toast");
}, 2000)
});
clipboard.on('error', function (e) {
console.info('Action:', e.action);
console.info('Text:', e.text);
console.info('Trigger:', e.trigger);
});
// code for making own gradient color
let generateGradient = () => {
let gradientCardEdit = document.getElementById('gradient_card_edit');
let colorPosition = document.getElementById('rangeSlider').value;
// console.log(colorDeg);
let AllColorArray = [];
let color = document.querySelectorAll('.colorinput');
color.forEach(element => {
AllColorArray.push(element.value);
})
let gradientColor = `linear-gradient(${colorPosition}deg,${AllColorArray.toString()})`;
gradientCardEdit.style.background = gradientColor;
let copyToClipboard = document.getElementById('color_maker_copy_btn');
copyToClipboard.setAttribute("data-clipboard-text", `background:${gradientColor};`)
}
generateGradient();
// code for add more input type="color"
let addInputColor = document.getElementById('add_input_btn');
let c = 3;
let addColorInputer = () => {
if (c <= 5) {
let colorInputs = document.getElementById('color_inputs');
let colorPicker = document.createElement('input');
colorPicker.classList.add("color", "colorinput");
colorPicker.setAttribute("type", "color");
colorPicker.setAttribute("value", "#1f1f1f");
colorPicker.setAttribute("oninput", "generateGradient()");
colorInputs.append(colorPicker);
generateGradient();
c++;
} else {
alert("only 5 colors allowed!")
}
}
// code for open and close the gradient maker div
let openBtn = document.getElementById('make_gradient_btn');
let closeBtn = document.getElementById('close');
let colorMakerDropDown = document.querySelector('.color_maker');
openBtn.onclick = () => {
colorMakerDropDown.classList.remove("color_maker_close");
}
closeBtn.onclick= () => {
colorMakerDropDown.classList.add("color_maker_close");
}