Skip to content

Commit 588fc36

Browse files
committed
[feature] adding update module
1 parent c9f05f5 commit 588fc36

File tree

11 files changed

+142
-66
lines changed

11 files changed

+142
-66
lines changed

‎index.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ <h1 class="menu-header">Page</h1>
286286

287287
<scriptsrc="js/helper.js"></script>
288288
<scriptsrc="js/data.js"></script>
289+
<scriptsrc="js/update.js"></script>
289290
<scriptsrc="js/state.js"></script>
290291
<scriptsrc="js/bookmarks.js"></script>
291292
<scriptsrc="js/control.js"></script>

‎js/bookmarks.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ var bookmarks = (function(){
215215
get: get,
216216
add: add,
217217
edit: edit,
218-
remove: remove,
219-
restore: restore
218+
remove: remove
220219
};
221220

222221
})();

‎js/control.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ var control = (function(){
108108
_layout();
109109
};
110110

111-
var_dependents=function(options){
111+
var_dependents=function(){
112112
var_date=function(){
113113
varactiveCount=0;
114114
vartoCheck=[state.get().header.date.show.date,state.get().header.date.show.day,state.get().header.date.show.month,state.get().header.date.show.year];

‎js/data.js‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var data = (function(){
1616

1717
varsave=function(){
1818
vardata={
19+
version: version.get(),
1920
state: state.get(),
2021
bookmarks: bookmarks.get()
2122
};
@@ -28,17 +29,37 @@ var data = (function(){
2829
returndata;
2930
};
3031

32+
var_checkForSavedData=function(data){
33+
if(data){
34+
console.log("data loaded");
35+
if(!("version"indata)||data.version!=version.get()){
36+
console.log("data version found less than current");
37+
data=update.render(data);
38+
set(saveName,JSON.stringify(data));
39+
}else{
40+
console.log("data version =",version.get());
41+
};
42+
}else{
43+
console.log("no data found to load");
44+
};
45+
};
46+
47+
varinit=function(){
48+
_checkForSavedData(load());
49+
};
50+
3151
varwipe=function(){
3252
clear(saveName);
3353
};
3454

3555
return{
56+
init: init,
3657
save: save,
3758
clear: clear,
3859
set: set,
3960
get: get,
40-
wipe: wipe,
41-
load: load
61+
load: load,
62+
wipe: wipe
4263
};
4364

4465
})();

‎js/helper.js‎

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ var helper = (function(){
6969
returnobject;
7070
};
7171

72-
varapplyOptions=function(defaultOptions,options){
73-
if(defaultOptions&&options){
74-
if(options){
75-
for(varkeyinoptions){
76-
if(keyindefaultOptions){
77-
defaultOptions[key]=options[key];
72+
varapplyOptions=function(options,override){
73+
if(options&&override){
74+
if(override){
75+
for(varkeyinoverride){
76+
if(keyinoptions){
77+
options[key]=override[key];
7878
};
7979
};
8080
};
81-
returndefaultOptions;
81+
returnoptions;
8282
}else{
8383
returnnull;
8484
};
@@ -156,75 +156,75 @@ var helper = (function(){
156156
returnarray;
157157
};
158158

159-
functionsetObject(options){
160-
vardefaultOptions={
159+
functionsetObject(override){
160+
varoptions={
161161
path: null,
162162
object: null,
163163
newValue: null
164164
};
165-
if(options){
166-
vardefaultOptions=applyOptions(defaultOptions,options);
165+
if(override){
166+
varoptions=applyOptions(options,override);
167167
};
168-
varaddress=_makeAddress(defaultOptions.path);
168+
varaddress=_makeAddress(options.path);
169169
var_setData=function(){
170170
while(address.length>1){
171171
// shift off and store the first key
172172
varcurrentKey=address.shift();
173173
// if the key is not found make a new object
174-
if(!(currentKeyindefaultOptions.object)){
174+
if(!(currentKeyinoptions.object)){
175175
// make an empty object in the current object level
176176
if(isNaN(currentKey)){
177-
defaultOptions.object[currentKey]={};
177+
options.object[currentKey]={};
178178
}else{
179-
defaultOptions.object[currentKey]=[];
179+
options.object[currentKey]=[];
180180
};
181181
};
182182
// drill down the object with the first key
183-
defaultOptions.object=defaultOptions.object[currentKey];
183+
options.object=options.object[currentKey];
184184
};
185185
varfinalKey=address.shift();
186-
defaultOptions.object[finalKey]=defaultOptions.newValue;
186+
options.object[finalKey]=options.newValue;
187187
};
188-
if(defaultOptions.object!=null&&defaultOptions.path!=null&&defaultOptions.newValue!=null){
188+
if(options.object!=null&&options.path!=null&&options.newValue!=null){
189189
_setData();
190190
}else{
191191
returnfalse;
192192
};
193193
};
194194

195-
functiongetObject(options){
196-
vardefaultOptions={
195+
functiongetObject(override){
196+
varoptions={
197197
object: null,
198198
path: null
199199
};
200-
if(options){
201-
vardefaultOptions=applyOptions(defaultOptions,options);
200+
if(override){
201+
varoptions=applyOptions(options,override);
202202
};
203-
varaddress=_makeAddress(defaultOptions.path);
203+
varaddress=_makeAddress(options.path);
204204
var_getData=function(){
205205
while(address.length>1){
206206
// shift off and store the first key
207207
varcurrentKey=address.shift();
208208
// if the key is not found make a new object
209-
if(!(currentKeyindefaultOptions.object)){
209+
if(!(currentKeyinoptions.object)){
210210
// make an empty object in the current object level
211211
if(isNaN(currentKey)){
212-
defaultOptions.object[currentKey]={};
212+
options.object[currentKey]={};
213213
}else{
214-
defaultOptions.object[currentKey]=[];
214+
options.object[currentKey]=[];
215215
};
216216
};
217217
// drill down the object with the first key
218-
defaultOptions.object=defaultOptions.object[currentKey];
218+
options.object=options.object[currentKey];
219219
};
220220
varfinalKey=address.shift();
221-
if(!(finalKeyindefaultOptions.object)){
221+
if(!(finalKeyinoptions.object)){
222222
return"";
223223
}else{
224-
returndefaultOptions.object[finalKey];
224+
returnoptions.object[finalKey];
225225
};
226226
};
227-
if(defaultOptions.object!=null&&defaultOptions.path!=null){
227+
if(options.object!=null&&options.path!=null){
228228
return_getData();
229229
}else{
230230
returnfalse;

‎js/init.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
// log version
22
console.log("nightTab v",version.get(),"loaded");
33

4+
// check for old versions
5+
data.init();
6+
47
// bind and update controls
58
// render states
69
state.init();
710

8-
// close menu if left open
9-
menu.init();
10-
1111
// restore bookmarks
1212
bookmarks.init();
1313

14+
// close menu if left open
15+
menu.init();
16+
1417
// render input color value
1518
// render css accent var
1619
theme.init();

‎js/modal.js‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ var modal = (function(){
1111
};
1212
};
1313

14-
varrender=function(options){
15-
vardefaultOptions={
14+
varrender=function(override){
15+
varoptions={
1616
heading: "Modal",
1717
content: "Body",
1818
action: null,
1919
actionText: "OK",
2020
cancelText: "Cancel",
2121
size: "medium"
2222
};
23-
if(options){
24-
defaultOptions=helper.applyOptions(defaultOptions,options);
23+
if(override){
24+
options=helper.applyOptions(options,override);
2525
};
2626
varmakeModal=function(){
2727
varbody=helper.e("body");
@@ -32,11 +32,11 @@ var modal = (function(){
3232
varmodalWrapper=document.createElement("div");
3333
modalWrapper.setAttribute("class","modal-wrapper");
3434
varmodal=document.createElement("div");
35-
if(defaultOptions.size=="large"){
35+
if(options.size=="large"){
3636
modal.setAttribute("class","modal modal-large");
37-
}elseif(defaultOptions.size=="small"){
37+
}elseif(options.size=="small"){
3838
modal.setAttribute("class","modal modal-small");
39-
}elseif(defaultOptions.size){
39+
}elseif(options.size){
4040
modal.setAttribute("class","modal");
4141
};
4242
modal.destroy=function(){
@@ -59,30 +59,30 @@ var modal = (function(){
5959
varactionButton=document.createElement("button");
6060
actionButton.setAttribute("tabindex","1");
6161
actionButton.setAttribute("class","button button-primary button-block");
62-
actionButton.textContent=defaultOptions.actionText;
62+
actionButton.textContent=options.actionText;
6363
varcancelButton=document.createElement("button");
6464
cancelButton.setAttribute("tabindex","1");
6565
cancelButton.setAttribute("class","button button-primary button-block");
66-
cancelButton.textContent=defaultOptions.cancelText;
66+
cancelButton.textContent=options.cancelText;
6767
modalControls.appendChild(cancelButton);
6868
modalControls.appendChild(actionButton);
69-
if(defaultOptions.heading!=null){
69+
if(options.heading!=null){
7070
varmodalHeading=document.createElement("h1");
7171
modalHeading.setAttribute("tabindex","1");
7272
modalHeading.setAttribute("class","modal-heading");
73-
modalHeading.textContent=defaultOptions.heading;
73+
modalHeading.textContent=options.heading;
7474
modalBody.appendChild(modalHeading);
7575
};
76-
if(defaultOptions.content){
77-
if(typeofdefaultOptions.content=="string"){
76+
if(options.content){
77+
if(typeofoptions.content=="string"){
7878
varcontainer=document.createElement("div");
7979
container.setAttribute("class","container");
8080
varpara=document.createElement("p");
81-
para.textContent=defaultOptions.content;
81+
para.textContent=options.content;
8282
container.appendChild(para);
8383
modalBody.appendChild(container);
8484
}else{
85-
modalBody.appendChild(defaultOptions.content);
85+
modalBody.appendChild(options.content);
8686
};
8787
};
8888
modalWrapper.appendChild(modalBody);
@@ -99,8 +99,8 @@ var modal = (function(){
9999
actionButton.addEventListener("click",function(event){
100100
this.destroy();
101101
shade.destroy();
102-
if(defaultOptions.action){
103-
defaultOptions.action();
102+
if(options.action){
103+
options.action();
104104
};
105105
}.bind(modal),false);
106106
cancelButton.addEventListener("click",function(event){

‎js/shade.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ var shade = (function(){
1111
};
1212
};
1313

14-
varrender=function(options){
15-
vardefaultOptions={
14+
varrender=function(override){
15+
varoptions={
1616
action: null,
1717
includeHeader: false
1818
};
19-
if(options){
20-
defaultOptions=helper.applyOptions(defaultOptions,options);
19+
if(override){
20+
options=helper.applyOptions(options,override);
2121
};
2222
var_destroy_previousShade=function(){
2323
if(previousShade!=null){
@@ -28,7 +28,7 @@ var shade = (function(){
2828
varbody=helper.e("body");
2929
varshade=document.createElement("div");
3030
shade.setAttribute("class","shade");
31-
if(defaultOptions.includeHeader){
31+
if(options.includeHeader){
3232
helper.addClass(shade,"m-shade-top");
3333
};
3434
shade.destroy=function(){
@@ -49,8 +49,8 @@ var shade = (function(){
4949
}.bind(shade),false);
5050
shade.addEventListener("click",function(){
5151
this.destroy();
52-
if(defaultOptions.action){
53-
defaultOptions.action();
52+
if(options.action){
53+
options.action();
5454
};
5555
},false);
5656
previousShade=shade;

‎js/state.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ var state = (function(){
116116
return{
117117
init: init,
118118
get: get,
119-
change: change,
120-
restore: restore
119+
change: change
121120
};
122121

123122
})();

0 commit comments

Comments
(0)