diff --git a/index.html b/index.html
index 7f575d37..95e595b8 100644
--- a/index.html
+++ b/index.html
@@ -286,6 +286,7 @@
+
diff --git a/js/bookmarks.js b/js/bookmarks.js
index 876e6721..ec0174d8 100644
--- a/js/bookmarks.js
+++ b/js/bookmarks.js
@@ -215,8 +215,7 @@ var bookmarks = (function() {
get: get,
add: add,
edit: edit,
- remove: remove,
- restore: restore
+ remove: remove
};
})();
diff --git a/js/control.js b/js/control.js
index 05c0c49a..d50d608a 100644
--- a/js/control.js
+++ b/js/control.js
@@ -108,7 +108,7 @@ var control = (function() {
_layout();
};
- var _dependents = function(options) {
+ var _dependents = function() {
var _date = function() {
var activeCount = 0;
var toCheck = [state.get().header.date.show.date, state.get().header.date.show.day, state.get().header.date.show.month, state.get().header.date.show.year];
diff --git a/js/data.js b/js/data.js
index 6180e921..053a76f7 100644
--- a/js/data.js
+++ b/js/data.js
@@ -16,6 +16,7 @@ var data = (function() {
var save = function() {
var data = {
+ version: version.get(),
state: state.get(),
bookmarks: bookmarks.get()
};
@@ -28,17 +29,37 @@ var data = (function() {
return data;
};
+ var _checkForSavedData = function(data) {
+ if (data) {
+ console.log("data loaded");
+ if (!("version" in data) || data.version != version.get()) {
+ console.log("data version found less than current");
+ data = update.render(data);
+ set(saveName, JSON.stringify(data));
+ } else {
+ console.log("data version =", version.get());
+ };
+ } else {
+ console.log("no data found to load");
+ };
+ };
+
+ var init = function() {
+ _checkForSavedData(load());
+ };
+
var wipe = function() {
clear(saveName);
};
return {
+ init: init,
save: save,
clear: clear,
set: set,
get: get,
- wipe: wipe,
- load: load
+ load: load,
+ wipe: wipe
};
})();
diff --git a/js/helper.js b/js/helper.js
index d879f7e5..7b882fe0 100644
--- a/js/helper.js
+++ b/js/helper.js
@@ -69,16 +69,16 @@ var helper = (function() {
return object;
};
- var applyOptions = function(defaultOptions, options) {
- if (defaultOptions && options) {
- if (options) {
- for (var key in options) {
- if (key in defaultOptions) {
- defaultOptions[key] = options[key];
+ var applyOptions = function(options, override) {
+ if (options && override) {
+ if (override) {
+ for (var key in override) {
+ if (key in options) {
+ options[key] = override[key];
};
};
};
- return defaultOptions;
+ return options;
} else {
return null;
};
@@ -156,75 +156,75 @@ var helper = (function() {
return array;
};
- function setObject(options) {
- var defaultOptions = {
+ function setObject(override) {
+ var options = {
path: null,
object: null,
newValue: null
};
- if (options) {
- var defaultOptions = applyOptions(defaultOptions, options);
+ if (override) {
+ var options = applyOptions(options, override);
};
- var address = _makeAddress(defaultOptions.path);
+ var address = _makeAddress(options.path);
var _setData = function() {
while (address.length > 1) {
// shift off and store the first key
var currentKey = address.shift();
// if the key is not found make a new object
- if (!(currentKey in defaultOptions.object)) {
+ if (!(currentKey in options.object)) {
// make an empty object in the current object level
if (isNaN(currentKey)) {
- defaultOptions.object[currentKey] = {};
+ options.object[currentKey] = {};
} else {
- defaultOptions.object[currentKey] = [];
+ options.object[currentKey] = [];
};
};
// drill down the object with the first key
- defaultOptions.object = defaultOptions.object[currentKey];
+ options.object = options.object[currentKey];
};
var finalKey = address.shift();
- defaultOptions.object[finalKey] = defaultOptions.newValue;
+ options.object[finalKey] = options.newValue;
};
- if (defaultOptions.object != null && defaultOptions.path != null && defaultOptions.newValue != null) {
+ if (options.object != null && options.path != null && options.newValue != null) {
_setData();
} else {
return false;
};
};
- function getObject(options) {
- var defaultOptions = {
+ function getObject(override) {
+ var options = {
object: null,
path: null
};
- if (options) {
- var defaultOptions = applyOptions(defaultOptions, options);
+ if (override) {
+ var options = applyOptions(options, override);
};
- var address = _makeAddress(defaultOptions.path);
+ var address = _makeAddress(options.path);
var _getData = function() {
while (address.length > 1) {
// shift off and store the first key
var currentKey = address.shift();
// if the key is not found make a new object
- if (!(currentKey in defaultOptions.object)) {
+ if (!(currentKey in options.object)) {
// make an empty object in the current object level
if (isNaN(currentKey)) {
- defaultOptions.object[currentKey] = {};
+ options.object[currentKey] = {};
} else {
- defaultOptions.object[currentKey] = [];
+ options.object[currentKey] = [];
};
};
// drill down the object with the first key
- defaultOptions.object = defaultOptions.object[currentKey];
+ options.object = options.object[currentKey];
};
var finalKey = address.shift();
- if (!(finalKey in defaultOptions.object)) {
+ if (!(finalKey in options.object)) {
return "";
} else {
- return defaultOptions.object[finalKey];
+ return options.object[finalKey];
};
};
- if (defaultOptions.object != null && defaultOptions.path != null) {
+ if (options.object != null && options.path != null) {
return _getData();
} else {
return false;
diff --git a/js/init.js b/js/init.js
index 7990c530..409f4282 100644
--- a/js/init.js
+++ b/js/init.js
@@ -1,16 +1,19 @@
// log version
console.log("nightTab v", version.get(), "loaded");
+// check for old versions
+data.init();
+
// bind and update controls
// render states
state.init();
-// close menu if left open
-menu.init();
-
// restore bookmarks
bookmarks.init();
+// close menu if left open
+menu.init();
+
// render input color value
// render css accent var
theme.init();
diff --git a/js/modal.js b/js/modal.js
index c4b45083..19add079 100644
--- a/js/modal.js
+++ b/js/modal.js
@@ -11,8 +11,8 @@ var modal = (function() {
};
};
- var render = function(options) {
- var defaultOptions = {
+ var render = function(override) {
+ var options = {
heading: "Modal",
content: "Body",
action: null,
@@ -20,8 +20,8 @@ var modal = (function() {
cancelText: "Cancel",
size: "medium"
};
- if (options) {
- defaultOptions = helper.applyOptions(defaultOptions, options);
+ if (override) {
+ options = helper.applyOptions(options, override);
};
var makeModal = function() {
var body = helper.e("body");
@@ -32,11 +32,11 @@ var modal = (function() {
var modalWrapper = document.createElement("div");
modalWrapper.setAttribute("class", "modal-wrapper");
var modal = document.createElement("div");
- if (defaultOptions.size == "large") {
+ if (options.size == "large") {
modal.setAttribute("class", "modal modal-large");
- } else if (defaultOptions.size == "small") {
+ } else if (options.size == "small") {
modal.setAttribute("class", "modal modal-small");
- } else if (defaultOptions.size) {
+ } else if (options.size) {
modal.setAttribute("class", "modal");
};
modal.destroy = function() {
@@ -59,30 +59,30 @@ var modal = (function() {
var actionButton = document.createElement("button");
actionButton.setAttribute("tabindex", "1");
actionButton.setAttribute("class", "button button-primary button-block");
- actionButton.textContent = defaultOptions.actionText;
+ actionButton.textContent = options.actionText;
var cancelButton = document.createElement("button");
cancelButton.setAttribute("tabindex", "1");
cancelButton.setAttribute("class", "button button-primary button-block");
- cancelButton.textContent = defaultOptions.cancelText;
+ cancelButton.textContent = options.cancelText;
modalControls.appendChild(cancelButton);
modalControls.appendChild(actionButton);
- if (defaultOptions.heading != null) {
+ if (options.heading != null) {
var modalHeading = document.createElement("h1");
modalHeading.setAttribute("tabindex", "1");
modalHeading.setAttribute("class", "modal-heading");
- modalHeading.textContent = defaultOptions.heading;
+ modalHeading.textContent = options.heading;
modalBody.appendChild(modalHeading);
};
- if (defaultOptions.content) {
- if (typeof defaultOptions.content == "string") {
+ if (options.content) {
+ if (typeof options.content == "string") {
var container = document.createElement("div");
container.setAttribute("class", "container");
var para = document.createElement("p");
- para.textContent = defaultOptions.content;
+ para.textContent = options.content;
container.appendChild(para);
modalBody.appendChild(container);
} else {
- modalBody.appendChild(defaultOptions.content);
+ modalBody.appendChild(options.content);
};
};
modalWrapper.appendChild(modalBody);
@@ -99,8 +99,8 @@ var modal = (function() {
actionButton.addEventListener("click", function(event) {
this.destroy();
shade.destroy();
- if (defaultOptions.action) {
- defaultOptions.action();
+ if (options.action) {
+ options.action();
};
}.bind(modal), false);
cancelButton.addEventListener("click", function(event) {
diff --git a/js/shade.js b/js/shade.js
index cd10b9ef..d795a2fb 100644
--- a/js/shade.js
+++ b/js/shade.js
@@ -11,13 +11,13 @@ var shade = (function() {
};
};
- var render = function(options) {
- var defaultOptions = {
+ var render = function(override) {
+ var options = {
action: null,
includeHeader: false
};
- if (options) {
- defaultOptions = helper.applyOptions(defaultOptions, options);
+ if (override) {
+ options = helper.applyOptions(options, override);
};
var _destroy_previousShade = function() {
if (previousShade != null) {
@@ -28,7 +28,7 @@ var shade = (function() {
var body = helper.e("body");
var shade = document.createElement("div");
shade.setAttribute("class", "shade");
- if (defaultOptions.includeHeader) {
+ if (options.includeHeader) {
helper.addClass(shade, "m-shade-top");
};
shade.destroy = function() {
@@ -49,8 +49,8 @@ var shade = (function() {
}.bind(shade), false);
shade.addEventListener("click", function() {
this.destroy();
- if (defaultOptions.action) {
- defaultOptions.action();
+ if (options.action) {
+ options.action();
};
}, false);
previousShade = shade;
diff --git a/js/state.js b/js/state.js
index 198f85f6..7245ecb8 100644
--- a/js/state.js
+++ b/js/state.js
@@ -116,8 +116,7 @@ var state = (function() {
return {
init: init,
get: get,
- change: change,
- restore: restore
+ change: change
};
})();
diff --git a/js/update.js b/js/update.js
new file mode 100644
index 00000000..df8edee9
--- /dev/null
+++ b/js/update.js
@@ -0,0 +1,52 @@
+var update = (function() {
+
+ var _update_100 = function(data) {
+ var time = new Date().getTime();
+ data.bookmarks.forEach(function(arrayItem, index) {
+ time = time + 1;
+ arrayItem.timeStamp = time;
+ });
+ data.version = 1.00;
+ return data;
+ };
+
+ var _update_200 = function(data) {
+ state.change({
+ path: "layout.theme",
+ value: data.theme
+ });
+ data = {
+ state: state.get(),
+ bookmarks: data.bookmarks
+ };
+ data.version = 2.00;
+ return data;
+ };
+
+ // var _update_300 = function(data) {
+ // data.version = 3.00;
+ // return data;
+ // };
+
+ function render(data) {
+ if (!("version" in data)) {
+ console.log("\trunning update", 1.00);
+ data = _update_100(data);
+ };
+ if (data.version < 2.00) {
+ console.log("\trunning update", 2.00);
+ data = _update_200(data);
+ };
+ // if (data.version < 3.00) {
+ // console.log("\t# running update", 3.00);
+ // data = _update_300(data);
+ // };
+ return data;
+ };
+
+ // exposed methods
+ return {
+ render: render
+ };
+
+})();
diff --git a/js/version.js b/js/version.js
index 44b2da31..9d42a0fe 100644
--- a/js/version.js
+++ b/js/version.js
@@ -1,9 +1,10 @@
var version = (function() {
- var current = 2.0;
+ var current = "2.0.0";
var get = function() {
- return current;
+ var number = current.split(".");
+ return parseFloat(number.shift() + "." + number.join(""));
};
// exposed methods