Skip to content

Commit eeabdca

Browse files
committed
[refactor] improve link and data module
1 parent eba4147 commit eeabdca

File tree

7 files changed

+106
-55
lines changed

7 files changed

+106
-55
lines changed

‎src/js/control.js‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ var control = (function(){
44
element: helper.e(".control-menu-open"),
55
type: "button",
66
func: function(){
7-
menu.mod.open();
8-
menu.render.toggle();
9-
menu.render.tabindex.toggle();
10-
pagelock.render.toggle();
7+
menu.open();
118
}
129
},{
1310
element: helper.e(".control-menu-layout"),
@@ -55,24 +52,21 @@ var control = (function(){
5552
element: helper.e(".control-menu-close"),
5653
type: "button",
5754
func: function(){
58-
shade.destroy();
59-
menu.mod.close();
60-
menu.render.toggle();
61-
menu.render.tabindex.toggle();
62-
pagelock.render.toggle();
55+
menu.close();
6356
}
6457
},{
6558
element: helper.e(".control-link-add"),
6659
type: "button",
6760
func: function(){
68-
link.render.add();
61+
link.add();
6962
}
7063
},{
7164
element: helper.e(".control-link-edit"),
7265
path: "link.edit",
7366
type: "checkbox",
7467
func: function(){
7568
render();
69+
link.render.tabindex();
7670
}
7771
},{
7872
element: helper.e(".control-theme-accent-current"),
@@ -2144,7 +2138,7 @@ var control = (function(){
21442138
element: helper.e(".control-background-image-file"),
21452139
type: "file",
21462140
func: function(){
2147-
background.importData();
2141+
background.mod.import();
21482142
}
21492143
},{
21502144
element: helper.e(".control-background-image-file-clear"),
@@ -2214,20 +2208,20 @@ var control = (function(){
22142208
element: helper.e(".control-data-import"),
22152209
type: "file",
22162210
func: function(){
2217-
data.importData();
2211+
data.mod.import();
22182212
}
22192213
},{
22202214
element: helper.e(".control-data-export"),
22212215
type: "a",
22222216
func: function(){
2223-
data.exportData();
2217+
data.mod.export();
22242218
}
22252219
},{
22262220
element: helper.e(".control-data-clear"),
22272221
type: "a",
22282222
func: function(){
22292223
menu.close();
2230-
data.clearData();
2224+
data.render.clear();
22312225
}
22322226
}];
22332227

@@ -2465,7 +2459,6 @@ var control = (function(){
24652459
helper.removeClass(html,"is-link-style-list");
24662460
helper.removeClass(html,"is-link-style-block");
24672461
helper.removeClass(html,"is-link-edit");
2468-
link.render.tabIndex();
24692462
if(state.get().link.show){
24702463
helper.addClass(html,"is-link-show");
24712464
helper.addClass(html,"is-link-area-alignment-"+state.get().link.area.alignment);
@@ -2488,7 +2481,6 @@ var control = (function(){
24882481
};
24892482
if(state.get().link.edit){
24902483
helper.addClass(html,"is-link-edit");
2491-
link.render.tabIndex();
24922484
};
24932485
};
24942486
};

‎src/js/data.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ var data = (function(){
9595
varpara2=helper.node("p:This can not be undone.");
9696
clearContent.appendChild(para1);
9797
clearContent.appendChild(para2);
98-
modal.render({
98+
modal.render.make({
9999
heading: "Clear all nightTab data?",
100100
content: clearContent,
101101
successAction: function(){

‎src/js/keyboard.js‎

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ var keyboard = (function(){
1010
edge.render.clear();
1111
}elseif(state.get().menu){
1212
menu.close();
13-
shade.destroy();
1413
}elseif(state.get().autoSuggest){
1514
autoSuggest.destroy();
1615
}elseif(state.get().modal){
17-
modal.destroy();
16+
modal.render.clear();
1817
shade.destroy();
1918
}elseif(state.get().link.edit){
2019
helper.setObject({
@@ -34,9 +33,14 @@ var keyboard = (function(){
3433
window.addEventListener("keydown",function(event){
3534
// ctrl+alt+a
3635
if(event.ctrlKey&&event.altKey&&event.keyCode==65){
37-
if(state.get().link.show){
38-
menu.close();
39-
link.render.add();
36+
if(!state.get().link.add){
37+
if(state.get().menu){
38+
menu.close();
39+
};
40+
if(state.get().modal){
41+
modal.render.clear();
42+
};
43+
link.add();
4044
};
4145
};
4246
},false);
@@ -58,8 +62,9 @@ var keyboard = (function(){
5862
window.addEventListener("keydown",function(event){
5963
// ctrl+alt+m
6064
if(event.ctrlKey&&event.altKey&&event.keyCode==77){
61-
shade.destroy();
62-
modal.destroy();
65+
if(state.get().modal){
66+
modal.render.clear();
67+
};
6368
menu.toggle();
6469
};
6570
},false);
@@ -69,24 +74,11 @@ var keyboard = (function(){
6974
window.addEventListener("keydown",function(event){
7075
// ctrl+alt+e
7176
if(event.ctrlKey&&event.altKey&&event.keyCode==69){
72-
if(state.get().link.show&&bookmarks.get().length>0){
73-
if(state.get().link.edit){
74-
helper.setObject({
75-
object: state.get(),
76-
path: "link.edit",
77-
newValue: false
78-
});
79-
}else{
80-
helper.setObject({
81-
object: state.get(),
82-
path: "link.edit",
83-
newValue: true
84-
});
85-
};
86-
control.update();
87-
control.render();
88-
data.save();
89-
};
77+
link.mod.edit.toggle();
78+
link.render.tabindex();
79+
control.update();
80+
control.render();
81+
data.save();
9082
};
9183
},false);
9284
};

‎src/js/link.js‎

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,77 @@ var link = (function(){
3030
}
3131
};
3232

33-
mod.edit=function(){
34-
if(bookmarks.get().length<=0){
33+
mod.edit={
34+
open: function(){
35+
helper.setObject({
36+
object: state.get(),
37+
path: "link.edit",
38+
newValue: true
39+
});
40+
},
41+
close: function(){
3542
helper.setObject({
3643
object: state.get(),
3744
path: "link.edit",
3845
newValue: false
3946
});
40-
};
47+
},
48+
toggle: function(){
49+
if(state.get().link.edit){
50+
helper.setObject({
51+
object: state.get(),
52+
path: "link.edit",
53+
newValue: false
54+
});
55+
}else{
56+
helper.setObject({
57+
object: state.get(),
58+
path: "link.edit",
59+
newValue: true
60+
});
61+
};
62+
},
63+
check: function(){
64+
if(bookmarks.get().length<=0){
65+
helper.setObject({
66+
object: state.get(),
67+
path: "link.edit",
68+
newValue: false
69+
});
70+
};
71+
}
72+
};
73+
74+
mod.add={
75+
open: function(){
76+
helper.setObject({
77+
object: state.get(),
78+
path: "link.add",
79+
newValue: true
80+
});
81+
},
82+
close: function(){
83+
helper.setObject({
84+
object: state.get(),
85+
path: "link.add",
86+
newValue: false
87+
});
88+
},
89+
toggle: function(){
90+
if(state.get().link.add){
91+
helper.setObject({
92+
object: state.get(),
93+
path: "link.add",
94+
newValue: false
95+
});
96+
}else{
97+
helper.setObject({
98+
object: state.get(),
99+
path: "link.add",
100+
newValue: true
101+
});
102+
};
103+
}
41104
};
42105

43106
varbind={};
@@ -104,21 +167,23 @@ var link = (function(){
104167
render.add=function(){
105168
stagedLink.init();
106169
varform=render.form();
107-
modal.render({
170+
modal.render.make({
108171
heading: "Add a new bookmark",
109172
successAction: function(){
110173
stagedLink.data.timeStamp=newDate().getTime();
111174
bookmarks.add(JSON.parse(JSON.stringify(stagedLink.data)));
112175
data.save();
176+
mod.add.close();
113177
render.clear();
114178
render.item.all();
115-
render.tabIndex();
179+
render.tabindex();
116180
sortable(".link-area");
117181
control.dependents();
118182
control.render();
119183
stagedLink.reset();
120184
},
121185
cancelAction: function(){
186+
mod.add.close();
122187
stagedLink.reset();
123188
autoSuggest.destroy();
124189
},
@@ -159,14 +224,14 @@ var link = (function(){
159224
if(stagedLink.data.accent.override){
160225
form.querySelector(".link-form-input-color").value=helper.rgbToHex(stagedLink.data.accent.color);
161226
};
162-
modal.render({
227+
modal.render.make({
163228
heading: "Edit "+stagedLink.data.name,
164229
successAction: function(){
165230
bookmarks.edit(JSON.parse(JSON.stringify(stagedLink.data)));
166231
data.save();
167232
render.clear();
168233
render.item.all();
169-
render.tabIndex();
234+
render.tabindex();
170235
render.previousFocus();
171236
sortable(".link-area");
172237
stagedLink.reset();
@@ -182,13 +247,13 @@ var link = (function(){
182247
};
183248

184249
render.remove=function(bookmarkData){
185-
modal.render({
250+
modal.render.make({
186251
heading: "Remove "+bookmarkData.name+" bookmark",
187252
content: "Are you sure you want to remove this bookmark? This can not be undone.",
188253
successAction: function(){
189254
_previousFocus=_previousFocus-1;
190255
bookmarks.remove(bookmarkData);
191-
mod.edit();
256+
mod.edit.check();
192257
header.render.button.edit();
193258
data.save();
194259
render.clear();
@@ -517,7 +582,7 @@ var link = (function(){
517582
}
518583
};
519584

520-
render.tabIndex=function(){
585+
render.tabindex=function(){
521586
varallLinkControlItem=helper.eA(".link-control-item");
522587
if(state.get().link.edit){
523588
allLinkControlItem.forEach(function(arrayItem,index){
@@ -694,7 +759,8 @@ var link = (function(){
694759
};
695760

696761
varadd=function(){
697-
link.render.add();
762+
mod.add.open();
763+
render.add();
698764
};
699765

700766
varinit=function(){

‎src/js/state.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ var state = (function(){
166166
},
167167
show: true,
168168
edit: false,
169+
add: false,
169170
style: "block"
170171
},
171172
layout: {

‎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="3.46.0";
3+
varcurrent="3.48.0";
44

55
varcompare=function(a,b){
66
varpa=a.split(".");

‎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": "3.46.0",
5+
"version": "3.47.0",
66
"manifest_version": 2,
77
"chrome_url_overrides":{
88
"newtab": "index.html"

0 commit comments

Comments
(0)