Skip to content

Commit cff0eba

Browse files
committed
[refactor] improve custom theme edit control
1 parent 69b0d2b commit cff0eba

File tree

9 files changed

+62
-39
lines changed

9 files changed

+62
-39
lines changed

‎package-lock.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nighttab",
3-
"version": "4.10.0",
3+
"version": "4.11.0",
44
"description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.",
55
"main": "index.js",
66
"scripts":{

‎src/index.html‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,9 @@ <h1 class="menu-item-header-text">Saved themes</h1>
13271327
<divclass="button-wrap">
13281328
<buttonclass="control-theme-custom-add button mb-0" tabindex="-1">Save current theme</button>
13291329
</div>
1330-
<divclass="button-wrap">
1331-
<buttonclass="control-theme-custom-edit button mb-0" tabindex="-1">Edit</button>
1330+
<divclass="input-wrap input-button input-hide">
1331+
<inputid="control-theme-custom-edit" class="control-theme-custom-edit" type="checkbox" tabindex="1">
1332+
<labelfor="control-theme-custom-edit" class="mb-0"><spanclass="label-icon"></span> Edit</label>
13321333
</div>
13331334
</div>
13341335
<pclass="control-theme-custom-helper form-helper small">Saving a Theme will record the current Colour, Accent, Font, Style and Radius.</p>

‎src/js/control.js‎

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,9 +2539,10 @@ var control = (function(){
25392539
}
25402540
},{
25412541
element: helper.e(".control-theme-custom-edit"),
2542-
type: "button",
2542+
path: "theme.custom.edit",
2543+
type: "checkbox",
25432544
func: function(){
2544-
theme.custom.edit();
2545+
render.class();
25452546
}
25462547
},{
25472548
element: helper.e(".control-theme-style-dark"),
@@ -3450,10 +3451,13 @@ var control = (function(){
34503451
};
34513452
};
34523453
var_theme=function(){
3454+
helper.removeClass(html,"is-theme-custom-edit");
3455+
helper.removeClass(html,"is-theme-radius");
3456+
if(state.get.current().theme.custom.edit){
3457+
helper.addClass(html,"is-theme-custom-edit");
3458+
};
34533459
if(state.get.current().theme.radius>0){
34543460
helper.addClass(html,"is-theme-radius");
3455-
}else{
3456-
helper.removeClass(html,"is-theme-radius");
34573461
};
34583462
};
34593463
var_layout=function(){
@@ -3842,23 +3846,21 @@ var control = (function(){
38423846
_transitional();
38433847
};
38443848
var_edit=function(){
3849+
_disable.input(".control-edit",true);
38453850
if(bookmarks.get().length>0){
38463851
_disable.input(".control-edit",false);
3847-
}else{
3848-
_disable.input(".control-edit",true);
38493852
};
38503853
};
38513854
var_group=function(){
3855+
_disable.element("[for=control-group-name-size]",true);
3856+
_disable.input(".control-group-name-size",true);
3857+
_disable.element(".control-group-name-size-count",true);
3858+
_disable.input(".control-group-name-size-default",true);
38523859
if(state.get.current().group.name.show){
38533860
_disable.element("[for=control-group-name-size]",false);
38543861
_disable.input(".control-group-name-size",false);
38553862
_disable.element(".control-group-name-size-count",false);
38563863
_disable.input(".control-group-name-size-default",false);
3857-
}else{
3858-
_disable.element("[for=control-group-name-size]",true);
3859-
_disable.input(".control-group-name-size",true);
3860-
_disable.element(".control-group-name-size-count",true);
3861-
_disable.input(".control-group-name-size-default",true);
38623864
};
38633865
};
38643866
var_link=function(){
@@ -4062,20 +4064,23 @@ var control = (function(){
40624064
};
40634065
};
40644066
var_theme=function(){
4067+
_disable.input(".control-theme-custom-edit",true);
4068+
_disable.input(".control-theme-accent-random-style-any",true);
4069+
_disable.input(".control-theme-accent-random-style-light",true);
4070+
_disable.input(".control-theme-accent-random-style-dark",true);
4071+
_disable.input(".control-theme-accent-random-style-pastel",true);
4072+
_disable.input(".control-theme-accent-random-style-saturated",true);
4073+
_disable.input(".control-theme-accent-randomise",true);
4074+
if(state.get.current().theme.custom.all.length>0){
4075+
_disable.input(".control-theme-custom-edit",false);
4076+
};
40654077
if(state.get.current().theme.accent.random.active){
40664078
_disable.input(".control-theme-accent-random-style-any",false);
40674079
_disable.input(".control-theme-accent-random-style-light",false);
40684080
_disable.input(".control-theme-accent-random-style-dark",false);
40694081
_disable.input(".control-theme-accent-random-style-pastel",false);
40704082
_disable.input(".control-theme-accent-random-style-saturated",false);
40714083
_disable.input(".control-theme-accent-randomise",false);
4072-
}else{
4073-
_disable.input(".control-theme-accent-random-style-any",true);
4074-
_disable.input(".control-theme-accent-random-style-light",true);
4075-
_disable.input(".control-theme-accent-random-style-dark",true);
4076-
_disable.input(".control-theme-accent-random-style-pastel",true);
4077-
_disable.input(".control-theme-accent-random-style-saturated",true);
4078-
_disable.input(".control-theme-accent-randomise",true);
40794084
};
40804085
};
40814086
var_background=function(){

‎src/js/state.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ var state = (function(){
262262
style: "dark",
263263
radius: 0.25,
264264
shadow: 1,
265-
custom: []
265+
custom: {
266+
all: [],
267+
edit: false
268+
}
266269
},
267270
background: {
268271
color: {

‎src/js/theme.js‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,13 +1089,20 @@ var theme = (function(){
10891089

10901090
mod.custom={
10911091
get: function(index){
1092-
returnJSON.parse(JSON.stringify(state.get.current().theme.custom[index]));
1092+
returnJSON.parse(JSON.stringify(state.get.current().theme.custom.all[index]));
10931093
},
10941094
add: function(){
1095-
state.get.current().theme.custom.push(JSON.parse(JSON.stringify(stagedThemeCustom.theme)));
1095+
state.get.current().theme.custom.all.push(JSON.parse(JSON.stringify(stagedThemeCustom.theme)));
10961096
},
10971097
remove: function(copyStagedThemeCustom){
1098-
state.get.current().theme.custom.splice(stagedThemeCustom.position.index,1);
1098+
state.get.current().theme.custom.all.splice(stagedThemeCustom.position.index,1);
1099+
},
1100+
close: function(){
1101+
helper.setObject({
1102+
object: state.get.current(),
1103+
path: "theme.custom.edit",
1104+
newValue: false
1105+
});
10991106
}
11001107
};
11011108

@@ -1399,7 +1406,7 @@ var theme = (function(){
13991406
all: function(){
14001407
varthemeCustomSaved=helper.e(".theme-custom");
14011408
varformInline=helper.node("div|class:form-inline");
1402-
varallThemeCuston=JSON.parse(JSON.stringify(state.get.current().theme.custom));
1409+
varallThemeCuston=JSON.parse(JSON.stringify(state.get.current().theme.custom.all));
14031410
if(allThemeCuston.length>0){
14041411
allThemeCuston.forEach(function(arrayItem,index){
14051412
varthemeCustomItem=helper.node("div|class:theme-custom-item");
@@ -1527,6 +1534,7 @@ var theme = (function(){
15271534
shade.close();
15281535
pagelock.unlock();
15291536
stagedThemeCustom.reset();
1537+
control.render.dependents();
15301538
};
15311539
varcancelAction=function(){
15321540
shade.close();
@@ -1561,12 +1569,16 @@ var theme = (function(){
15611569
};
15621570
varsuccessAction=function(){
15631571
mod.custom.remove();
1572+
custom.check();
15641573
data.save();
15651574
render.custom.clear();
15661575
render.custom.all();
15671576
shade.close();
15681577
pagelock.unlock();
15691578
stagedThemeCustom.reset();
1579+
control.render.update();
1580+
control.render.class();
1581+
control.render.dependents();
15701582
};
15711583
varcancelAction=function(){
15721584
shade.close();
@@ -1590,16 +1602,6 @@ var theme = (function(){
15901602
});
15911603
pagelock.lock();
15921604
},
1593-
edit: function(){
1594-
varhtml=helper.e("html");
1595-
if(_customThemeEdit){
1596-
_customThemeEdit=false;
1597-
helper.removeClass(html,"is-theme-custom-edit");
1598-
}else{
1599-
_customThemeEdit=true;
1600-
helper.addClass(html,"is-theme-custom-edit");
1601-
};
1602-
},
16031605
clear: function(){
16041606
varthemeCustom=helper.e(".theme-custom");
16051607
while(themeCustom.lastChild){
@@ -1662,6 +1664,11 @@ var theme = (function(){
16621664
edit: function(){
16631665
render.custom.edit();
16641666
render.custom.tabIndex();
1667+
},
1668+
check: function(){
1669+
if(state.get.current().theme.custom.all<=0){
1670+
mod.custom.close();
1671+
};
16651672
}
16661673
};
16671674

‎src/js/update.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,13 @@ var update = (function(){
757757
"4.10.0": function(data){
758758
data.state.theme.shadow=1;
759759
returndata;
760+
},
761+
"4.11.0": function(data){
762+
data.state.theme.custom={
763+
all: data.state.theme.custom,
764+
edit: false
765+
};
766+
returndata;
760767
}
761768
};
762769

‎src/js/version.js‎

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

3-
varcurrent="4.10.0";
3+
varcurrent="4.11.0";
44

55
varname="Naughty Goose";
66

‎src/manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nightTab",
33
"short_name": "nightTab",
44
"description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.",
5-
"version": "4.10.0",
5+
"version": "4.11.0",
66
"manifest_version": 2,
77
"chrome_url_overrides":{
88
"newtab": "index.html"

0 commit comments

Comments
(0)