Skip to content

Commit 359c80e

Browse files
authored
[feature] adding random accent colour options
1 parent 285b1d8 commit 359c80e

File tree

7 files changed

+172
-12
lines changed

7 files changed

+172
-12
lines changed

‎index.html‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,26 @@ <h1 class="menu-header">Theme</h1>
287287
<inputid="control-layout-theme-random" class="control-layout-theme-random" type="checkbox" tabindex="1">
288288
<labelfor="control-layout-theme-random"><spanclass="label-icon"></span>Random Accent colour on load/refresh</label>
289289
</div>
290+
<divclass="radio-wrap form-indent-1">
291+
<inputid="control-layout-theme-style-any" class="control-layout-theme-style-any" type="radio" tabindex="1" name="control-layout-theme-style" value="any">
292+
<labelfor="control-layout-theme-style-any"><spanclass="label-icon"></span>Any colour</label>
293+
</div>
294+
<divclass="radio-wrap form-indent-1">
295+
<inputid="control-layout-theme-style-light" class="control-layout-theme-style-light" type="radio" tabindex="1" name="control-layout-theme-style" value="light">
296+
<labelfor="control-layout-theme-style-light"><spanclass="label-icon"></span>Light colours</label>
297+
</div>
298+
<divclass="radio-wrap form-indent-1">
299+
<inputid="control-layout-theme-style-dark" class="control-layout-theme-style-dark" type="radio" tabindex="1" name="control-layout-theme-style" value="dark">
300+
<labelfor="control-layout-theme-style-dark"><spanclass="label-icon"></span>Dark colours</label>
301+
</div>
302+
<divclass="radio-wrap form-indent-1">
303+
<inputid="control-layout-theme-style-pastel" class="control-layout-theme-style-pastel" type="radio" tabindex="1" name="control-layout-theme-style" value="pastel">
304+
<labelfor="control-layout-theme-style-pastel"><spanclass="label-icon"></span>Pastel colours</label>
305+
</div>
306+
<divclass="radio-wrap form-indent-1">
307+
<inputid="control-layout-theme-style-saturated" class="control-layout-theme-style-saturated" type="radio" tabindex="1" name="control-layout-theme-style" value="saturated">
308+
<labelfor="control-layout-theme-style-saturated"><spanclass="label-icon"></span>Saturated colours</label>
309+
</div>
290310
</div>
291311
</div>
292312
</div>

‎js/control.js‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,22 @@ var control = (function(){
192192
helper.e(".control-header-search-engine-custom-url").disabled=true;
193193
};
194194
};
195+
var_theme=function(){
196+
if(state.get().layout.theme.random.active){
197+
helper.eA("input[name='control-layout-theme-style']").forEach(function(arrayItem,index){
198+
arrayItem.disabled=false;
199+
});
200+
}else{
201+
helper.eA("input[name='control-layout-theme-style']").forEach(function(arrayItem,index){
202+
arrayItem.disabled=true;
203+
});
204+
};
205+
};
195206
_edit();
196207
_date();
197208
_clock();
198209
_search();
210+
_theme();
199211
};
200212

201213
var_bind=function(){
@@ -224,12 +236,23 @@ var control = (function(){
224236
},false);
225237
helper.e(".control-layout-theme-random").addEventListener("change",function(){
226238
state.change({
227-
path: "layout.theme.random",
239+
path: "layout.theme.random.active",
228240
value: this.checked
229241
});
230242
theme.render();
243+
dependents();
231244
data.save();
232245
},false);
246+
helper.eA("input[name='control-layout-theme-style']").forEach(function(arrayItem,index){
247+
arrayItem.addEventListener("change",function(){
248+
state.change({
249+
path: "layout.theme.random.style",
250+
value: this.value
251+
});
252+
render();
253+
data.save();
254+
},false);
255+
});
233256
helper.e(".control-link-new-tab").addEventListener("change",function(){
234257
state.change({
235258
path: "link.newTab",
@@ -492,7 +515,8 @@ var control = (function(){
492515
varupdate=function(){
493516
helper.e(".control-edit").checked=state.get().edit.active;
494517
helper.e(".control-layout-theme").value=helper.rgbToHex(state.get().layout.theme.current);
495-
helper.e(".control-layout-theme-random").checked=state.get().layout.theme.random;
518+
helper.e(".control-layout-theme-random").checked=state.get().layout.theme.random.active;
519+
helper.e(".control-layout-theme-style-"+state.get().layout.theme.random.style).checked=true;
496520
helper.e(".control-link-new-tab").value=state.get().link.style.newTab;
497521
helper.e(".control-link-style-"+state.get().link.style).checked=true;
498522
helper.e(".control-link-sort-"+state.get().link.sort).checked=true;

‎js/helper.js‎

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,79 @@ var helper = (function(){
8484
};
8585
};
8686

87+
varhslToRgb=function(hslObject){
88+
if(hslObject==undefined){
89+
returnnull;
90+
};
91+
92+
varchroma=(1-Math.abs((2*hslObject.l)-1))*hslObject.s;
93+
varhuePrime=hslObject.h/60;
94+
varsecondComponent=chroma*(1-Math.abs((huePrime%2)-1));
95+
96+
huePrime=Math.floor(huePrime);
97+
varred;
98+
vargreen;
99+
varblue;
100+
101+
if(huePrime===0){
102+
red=chroma;
103+
green=secondComponent;
104+
blue=0;
105+
}elseif(huePrime===1){
106+
red=secondComponent;
107+
green=chroma;
108+
blue=0;
109+
}elseif(huePrime===2){
110+
red=0;
111+
green=chroma;
112+
blue=secondComponent;
113+
}elseif(huePrime===3){
114+
red=0;
115+
green=secondComponent;
116+
blue=chroma;
117+
}elseif(huePrime===4){
118+
red=secondComponent;
119+
green=0;
120+
blue=chroma;
121+
}elseif(huePrime===5){
122+
red=chroma;
123+
green=0;
124+
blue=secondComponent;
125+
};
126+
127+
varlightnessAdjustment=hslObject.l-(chroma/2);
128+
red+=lightnessAdjustment;
129+
green+=lightnessAdjustment;
130+
blue+=lightnessAdjustment;
131+
132+
varresult={
133+
r: Math.round(red*255),
134+
g: Math.round(green*255),
135+
b: Math.round(blue*255)
136+
};
137+
138+
returnresult;
139+
};
140+
87141
varhexToRgb=function(hex){
142+
if(hex==undefined){
143+
returnnull;
144+
};
88145
varresult=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
89146
if(result){
90147
result={
91148
r: parseInt(result[1],16),
92149
g: parseInt(result[2],16),
93150
b: parseInt(result[3],16)
94151
};
95-
}else{
96-
result=null;
97-
}
152+
};
98153
returnresult;
99154
};
100155

101156
varrgbToHex=function(rgbObject){
157+
if(rgbObject==undefined){
158+
returnnull;
159+
};
102160
varcomponentToHex=function(hexPart){
103161
hexPart=hexPart.toString(16);
104162
if(hexPart.length==1){
@@ -312,6 +370,7 @@ var helper = (function(){
312370
applyOptions: applyOptions,
313371
hexToRgb: hexToRgb,
314372
rgbToHex: rgbToHex,
373+
hslToRgb: hslToRgb,
315374
makeNode: makeNode,
316375
setObject: setObject,
317376
getObject: getObject,

‎js/state.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ var state = (function(){
6868
g: 255,
6969
b: 0,
7070
},
71-
random: false
71+
random: {
72+
active: false,
73+
style: "any"
74+
}
7275
},
7376
},
7477
edit: {

‎js/theme.js‎

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,53 @@ var theme = (function(){
77
};
88

99
varrandom=function(){
10-
if(state.get().layout.theme.random){
11-
varrandomColor={
12-
r: helper.randomNumber(0,255),
13-
g: helper.randomNumber(0,255),
14-
b: helper.randomNumber(0,255)
10+
if(state.get().layout.theme.random.active){
11+
varrandomVal=function(min,max){
12+
returnMath.floor(Math.random()*(max-min)+1)+min;
1513
};
14+
varcolor={
15+
any: function(){
16+
return{
17+
h: randomVal(0,360),
18+
s: randomVal(0,100),
19+
l: randomVal(0,100)
20+
};
21+
},
22+
light: function(){
23+
return{
24+
h: randomVal(0,360),
25+
s: randomVal(50,90),
26+
l: randomVal(50,90)
27+
};
28+
},
29+
dark: function(){
30+
return{
31+
h: randomVal(0,360),
32+
s: randomVal(10,50),
33+
l: randomVal(10,50)
34+
};
35+
},
36+
pastel: function(){
37+
return{
38+
h: randomVal(0,360),
39+
s: 100,
40+
l: 80
41+
};
42+
},
43+
saturated: function(){
44+
return{
45+
h: randomVal(0,360),
46+
s: 100,
47+
l: 50
48+
};
49+
}
50+
};
51+
varhsl=color[state.get().layout.theme.random.style]();
52+
varrandomColor=helper.hslToRgb({
53+
h: hsl.h,
54+
s: (hsl.s/100),
55+
l: (hsl.l/100)
56+
});
1657
state.change({
1758
path: "layout.theme.current",
1859
value: randomColor

‎js/update.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ var update = (function(){
3232
returndata;
3333
};
3434

35+
var_update_230=function(data){
36+
data.state.layout.theme.random={
37+
active: data.state.layout.theme.random,
38+
style: "any"
39+
};
40+
data.version=2.30;
41+
returndata;
42+
};
43+
3544
// var _update_300 = function(data){
3645
// data.version = 3.00;
3746
// return data;
@@ -50,6 +59,10 @@ var update = (function(){
5059
console.log("\trunning update",2.10);
5160
data=_update_210(data);
5261
};
62+
if(data.version<2.30){
63+
console.log("\trunning update",2.30);
64+
data=_update_230(data);
65+
};
5366
// if (data.version < 3.00){
5467
// console.log("\t# running update", 3.00);
5568
// data = _update_300(data);

‎js/version.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
varversion=(function(){
22

33
// version is normally bumped when the state needs changing or any new functionality is added
4-
varcurrent="2.2.0";
4+
varcurrent="2.3.0";
55

66
varget=function(){
77
varnumber=current.split(".");

0 commit comments

Comments
(0)