-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·83 lines (79 loc) · 2.29 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="/static/iro.min.js" ></script>
<style>
.iro__slider {
display: none;
}
#colorPicker {
min-height: 400px;
padding-top: 5%;
display: flex;
/* display: -webkit-flex; */
justify-content: center;
/* align-items: center; */
/* align-content: center; */
}
</style>
</head>
<body>
<!-- <div class="square" id="colorView" align="center"></div> -->
<div id="colorPicker"></div>
<script type="text/javascript">
function throttle (func, limit) {
var inThrottle;
return function() {
const args = arguments;
const context = this;
if (!inThrottle) {
func.apply(context, args);
inThrottle = true;
setTimeout(() => inThrottle = false, limit);
}
};
}
function getUserId() {
if(!localStorage.getItem("user_id")) {
localStorage.setItem("user_id", Math.random().toString().substring(2));
}
return localStorage.getItem("user_id");
}
var demo = new iro.ColorPicker("#colorPicker", {
width: 660,
height: 660,
markerRadius: 25,
color: "#f00",
borderWidth: 10,
padding: 4,
anticlockwise: true,
css: {
// body: {
// "background-color": "$color",
// "color": "$color"
// },
// "#text": {
// "border-color": "$color",
// "color": "$color"
// },
// "#colorView": {
// "background-color": "$color",
// "color": "$color"
// }
}});
demo.on("color:change", throttle((color) => {
post('pick_color', {color: JSON.stringify(color.rgb)});
document.body.style.background = color.hexString;
}, 150));
function post(url, headers) {
let request = new XMLHttpRequest();
request.open("POST", url);
request.setRequestHeader('user_id', getUserId());
Object.keys(headers).map((header) => request.setRequestHeader(header, headers[header]));
request.send();
}
</script>
</body>
</html>