-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsettings.js
74 lines (60 loc) · 1.64 KB
/
settings.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
/* Copyright (c) 2015, Amperka LLC
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE.txt file for details.
*/
function setBackgroundColor(val) {
$('body').css('background-color', val);
val = val.replace(/[^0-9a-f]/gi, '');
if (val.length < 6) {
val = val[0] + val[0] + val[1] + val[1] + val[2] + val[2];
}
var max = 0;
var min = 255;
for (var i = 0; i < 3; i++) {
var c = parseInt(val.substr(i*2, 2), 16);
max = c > max ? c : max;
min = c < min ? c : min;
}
var lum = (min + max) / 2;
if (lum < 128) {
$('#menu').addClass('light');
} else {
$('#menu').removeClass('light');
}
}
$(function() {
$('#settings input').change(function(e) {
var name = $(this).attr('name');
var val = $(this).val();
switch (name) {
case 'font-size':
$('h1').css('font-size', val + 'vw');
break;
case 'text-color':
$('h1').css('color', val);
break;
case 'bg-color':
setBackgroundColor(val);
break;
}
});
$('#apply-settings').click(function(e) {
e.preventDefault();
$('#settings').hide();
});
$('.btn-settings').click(function(e) {
e.preventDefault();
e.stopPropagation();
$('#settings').toggle(0);
});
$('#settings').click(function(e) {
e.stopPropagation();
});
$('body').click(function() {
$('#settings').hide();
});
$('#settings input').each(function() {
$(this).change();
});
});