-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathscript.js
108 lines (94 loc) · 2.76 KB
/
script.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
102
103
104
105
106
107
108
let config = {
url: 'http://192.168.1.225',
};
let whiteStatus = 0;
$(document).ready(function() {
btnStatus();
// Cache buster added because caching was a big problem on mobile
let cacheBuster = new Date().getTime();
const pickr = Pickr.create({
el: '.color-picker',
theme: 'classic', // or 'monolith', or 'nano'
lockOpacity: true,
padding: 15,
inline: true,
swatches: [
'rgba(255, 0, 0, 1)',
'rgba(0, 255, 0, 1)',
'rgba(0, 0, 255, 1)',
// 'rgba(255, 250.0, 0, 1)', // yellow broken
'rgba(255, 0, 255, 1)',
'rgba(0, 255, 255, 1)',
'rgba(255, 255, 255, 1)',
'rgba(0, 0, 0, 1)',
],
components: {
// Main components
preview: true,
opacity: false,
hue: true,
// Input / output Options
interaction: {
hex: true,
rgba: true,
// hsla: true,
// hsva: true,
// cmyk: true,
input: true,
// clear: true,
save: true
}
}
});
pickr.on('swatchselect', e => {
sendData(e);
});
pickr.on('save', e => {
sendData(e);
});
function sendData(e){
let obj = e.toRGBA();
let red = Math.floor(obj[0]);
let green = Math.floor(obj[1]);
let blue = Math.floor(obj[2]);
let queryBuilder = `red=${red}&green=${green}&blue=${blue}`;
console.log(queryBuilder);
$.ajax({
url: `${config.url}/api/lr?${queryBuilder}&${cacheBuster}`,
method: 'GET',
dataType: 'json',
cache: false,
success: function (result) {
console.log(result);
}
});
}
$('#btnToggle').on('click', function(e){
// let state;
if(whiteStatus == 0) {
whiteStatus = Math.floor(255);
} else {
whiteStatus = 0;
}
//right
$.ajax({
url: `${config.url}/api/lr/white?white=${whiteStatus}&${cacheBuster}`,
method: 'GET',
success: function(result) {
console.log(result);
},
complete: btnStatus
});
e.preventDefault();
});
// Main big button - uses kitchenRight for master data.
function btnStatus() {
if(whiteStatus == 0) {
$('#btnToggle').text('Turn On');
$('#btnToggle').removeClass().addClass('btn btn-block btn-dark');
} else {
$('#btnToggle').text('Turn Off')
$('#btnToggle').removeClass().addClass('btn btn-block btn-light');
}
}
});