mirror of
https://github.com/zombieFox/nightTab.git
synced 2025-08-17 17:21:11 +02:00
[feature] adding update module
This commit is contained in:
@@ -286,6 +286,7 @@
|
|||||||
|
|
||||||
<script src="js/helper.js"></script>
|
<script src="js/helper.js"></script>
|
||||||
<script src="js/data.js"></script>
|
<script src="js/data.js"></script>
|
||||||
|
<script src="js/update.js"></script>
|
||||||
<script src="js/state.js"></script>
|
<script src="js/state.js"></script>
|
||||||
<script src="js/bookmarks.js"></script>
|
<script src="js/bookmarks.js"></script>
|
||||||
<script src="js/control.js"></script>
|
<script src="js/control.js"></script>
|
||||||
|
@@ -215,8 +215,7 @@ var bookmarks = (function() {
|
|||||||
get: get,
|
get: get,
|
||||||
add: add,
|
add: add,
|
||||||
edit: edit,
|
edit: edit,
|
||||||
remove: remove,
|
remove: remove
|
||||||
restore: restore
|
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@@ -108,7 +108,7 @@ var control = (function() {
|
|||||||
_layout();
|
_layout();
|
||||||
};
|
};
|
||||||
|
|
||||||
var _dependents = function(options) {
|
var _dependents = function() {
|
||||||
var _date = function() {
|
var _date = function() {
|
||||||
var activeCount = 0;
|
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];
|
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];
|
||||||
|
25
js/data.js
25
js/data.js
@@ -16,6 +16,7 @@ var data = (function() {
|
|||||||
|
|
||||||
var save = function() {
|
var save = function() {
|
||||||
var data = {
|
var data = {
|
||||||
|
version: version.get(),
|
||||||
state: state.get(),
|
state: state.get(),
|
||||||
bookmarks: bookmarks.get()
|
bookmarks: bookmarks.get()
|
||||||
};
|
};
|
||||||
@@ -28,17 +29,37 @@ var data = (function() {
|
|||||||
return data;
|
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() {
|
var wipe = function() {
|
||||||
clear(saveName);
|
clear(saveName);
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
init: init,
|
||||||
save: save,
|
save: save,
|
||||||
clear: clear,
|
clear: clear,
|
||||||
set: set,
|
set: set,
|
||||||
get: get,
|
get: get,
|
||||||
wipe: wipe,
|
load: load,
|
||||||
load: load
|
wipe: wipe
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
60
js/helper.js
60
js/helper.js
@@ -69,16 +69,16 @@ var helper = (function() {
|
|||||||
return object;
|
return object;
|
||||||
};
|
};
|
||||||
|
|
||||||
var applyOptions = function(defaultOptions, options) {
|
var applyOptions = function(options, override) {
|
||||||
if (defaultOptions && options) {
|
if (options && override) {
|
||||||
if (options) {
|
if (override) {
|
||||||
for (var key in options) {
|
for (var key in override) {
|
||||||
if (key in defaultOptions) {
|
if (key in options) {
|
||||||
defaultOptions[key] = options[key];
|
options[key] = override[key];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return defaultOptions;
|
return options;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
@@ -156,75 +156,75 @@ var helper = (function() {
|
|||||||
return array;
|
return array;
|
||||||
};
|
};
|
||||||
|
|
||||||
function setObject(options) {
|
function setObject(override) {
|
||||||
var defaultOptions = {
|
var options = {
|
||||||
path: null,
|
path: null,
|
||||||
object: null,
|
object: null,
|
||||||
newValue: null
|
newValue: null
|
||||||
};
|
};
|
||||||
if (options) {
|
if (override) {
|
||||||
var defaultOptions = applyOptions(defaultOptions, options);
|
var options = applyOptions(options, override);
|
||||||
};
|
};
|
||||||
var address = _makeAddress(defaultOptions.path);
|
var address = _makeAddress(options.path);
|
||||||
var _setData = function() {
|
var _setData = function() {
|
||||||
while (address.length > 1) {
|
while (address.length > 1) {
|
||||||
// shift off and store the first key
|
// shift off and store the first key
|
||||||
var currentKey = address.shift();
|
var currentKey = address.shift();
|
||||||
// if the key is not found make a new object
|
// 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
|
// make an empty object in the current object level
|
||||||
if (isNaN(currentKey)) {
|
if (isNaN(currentKey)) {
|
||||||
defaultOptions.object[currentKey] = {};
|
options.object[currentKey] = {};
|
||||||
} else {
|
} else {
|
||||||
defaultOptions.object[currentKey] = [];
|
options.object[currentKey] = [];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
// drill down the object with the first key
|
// drill down the object with the first key
|
||||||
defaultOptions.object = defaultOptions.object[currentKey];
|
options.object = options.object[currentKey];
|
||||||
};
|
};
|
||||||
var finalKey = address.shift();
|
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();
|
_setData();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function getObject(options) {
|
function getObject(override) {
|
||||||
var defaultOptions = {
|
var options = {
|
||||||
object: null,
|
object: null,
|
||||||
path: null
|
path: null
|
||||||
};
|
};
|
||||||
if (options) {
|
if (override) {
|
||||||
var defaultOptions = applyOptions(defaultOptions, options);
|
var options = applyOptions(options, override);
|
||||||
};
|
};
|
||||||
var address = _makeAddress(defaultOptions.path);
|
var address = _makeAddress(options.path);
|
||||||
var _getData = function() {
|
var _getData = function() {
|
||||||
while (address.length > 1) {
|
while (address.length > 1) {
|
||||||
// shift off and store the first key
|
// shift off and store the first key
|
||||||
var currentKey = address.shift();
|
var currentKey = address.shift();
|
||||||
// if the key is not found make a new object
|
// 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
|
// make an empty object in the current object level
|
||||||
if (isNaN(currentKey)) {
|
if (isNaN(currentKey)) {
|
||||||
defaultOptions.object[currentKey] = {};
|
options.object[currentKey] = {};
|
||||||
} else {
|
} else {
|
||||||
defaultOptions.object[currentKey] = [];
|
options.object[currentKey] = [];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
// drill down the object with the first key
|
// drill down the object with the first key
|
||||||
defaultOptions.object = defaultOptions.object[currentKey];
|
options.object = options.object[currentKey];
|
||||||
};
|
};
|
||||||
var finalKey = address.shift();
|
var finalKey = address.shift();
|
||||||
if (!(finalKey in defaultOptions.object)) {
|
if (!(finalKey in options.object)) {
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} 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();
|
return _getData();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@@ -1,16 +1,19 @@
|
|||||||
// log version
|
// log version
|
||||||
console.log("nightTab v", version.get(), "loaded");
|
console.log("nightTab v", version.get(), "loaded");
|
||||||
|
|
||||||
|
// check for old versions
|
||||||
|
data.init();
|
||||||
|
|
||||||
// bind and update controls
|
// bind and update controls
|
||||||
// render states
|
// render states
|
||||||
state.init();
|
state.init();
|
||||||
|
|
||||||
// close menu if left open
|
|
||||||
menu.init();
|
|
||||||
|
|
||||||
// restore bookmarks
|
// restore bookmarks
|
||||||
bookmarks.init();
|
bookmarks.init();
|
||||||
|
|
||||||
|
// close menu if left open
|
||||||
|
menu.init();
|
||||||
|
|
||||||
// render input color value
|
// render input color value
|
||||||
// render css accent var
|
// render css accent var
|
||||||
theme.init();
|
theme.init();
|
||||||
|
34
js/modal.js
34
js/modal.js
@@ -11,8 +11,8 @@ var modal = (function() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var render = function(options) {
|
var render = function(override) {
|
||||||
var defaultOptions = {
|
var options = {
|
||||||
heading: "Modal",
|
heading: "Modal",
|
||||||
content: "Body",
|
content: "Body",
|
||||||
action: null,
|
action: null,
|
||||||
@@ -20,8 +20,8 @@ var modal = (function() {
|
|||||||
cancelText: "Cancel",
|
cancelText: "Cancel",
|
||||||
size: "medium"
|
size: "medium"
|
||||||
};
|
};
|
||||||
if (options) {
|
if (override) {
|
||||||
defaultOptions = helper.applyOptions(defaultOptions, options);
|
options = helper.applyOptions(options, override);
|
||||||
};
|
};
|
||||||
var makeModal = function() {
|
var makeModal = function() {
|
||||||
var body = helper.e("body");
|
var body = helper.e("body");
|
||||||
@@ -32,11 +32,11 @@ var modal = (function() {
|
|||||||
var modalWrapper = document.createElement("div");
|
var modalWrapper = document.createElement("div");
|
||||||
modalWrapper.setAttribute("class", "modal-wrapper");
|
modalWrapper.setAttribute("class", "modal-wrapper");
|
||||||
var modal = document.createElement("div");
|
var modal = document.createElement("div");
|
||||||
if (defaultOptions.size == "large") {
|
if (options.size == "large") {
|
||||||
modal.setAttribute("class", "modal modal-large");
|
modal.setAttribute("class", "modal modal-large");
|
||||||
} else if (defaultOptions.size == "small") {
|
} else if (options.size == "small") {
|
||||||
modal.setAttribute("class", "modal modal-small");
|
modal.setAttribute("class", "modal modal-small");
|
||||||
} else if (defaultOptions.size) {
|
} else if (options.size) {
|
||||||
modal.setAttribute("class", "modal");
|
modal.setAttribute("class", "modal");
|
||||||
};
|
};
|
||||||
modal.destroy = function() {
|
modal.destroy = function() {
|
||||||
@@ -59,30 +59,30 @@ var modal = (function() {
|
|||||||
var actionButton = document.createElement("button");
|
var actionButton = document.createElement("button");
|
||||||
actionButton.setAttribute("tabindex", "1");
|
actionButton.setAttribute("tabindex", "1");
|
||||||
actionButton.setAttribute("class", "button button-primary button-block");
|
actionButton.setAttribute("class", "button button-primary button-block");
|
||||||
actionButton.textContent = defaultOptions.actionText;
|
actionButton.textContent = options.actionText;
|
||||||
var cancelButton = document.createElement("button");
|
var cancelButton = document.createElement("button");
|
||||||
cancelButton.setAttribute("tabindex", "1");
|
cancelButton.setAttribute("tabindex", "1");
|
||||||
cancelButton.setAttribute("class", "button button-primary button-block");
|
cancelButton.setAttribute("class", "button button-primary button-block");
|
||||||
cancelButton.textContent = defaultOptions.cancelText;
|
cancelButton.textContent = options.cancelText;
|
||||||
modalControls.appendChild(cancelButton);
|
modalControls.appendChild(cancelButton);
|
||||||
modalControls.appendChild(actionButton);
|
modalControls.appendChild(actionButton);
|
||||||
if (defaultOptions.heading != null) {
|
if (options.heading != null) {
|
||||||
var modalHeading = document.createElement("h1");
|
var modalHeading = document.createElement("h1");
|
||||||
modalHeading.setAttribute("tabindex", "1");
|
modalHeading.setAttribute("tabindex", "1");
|
||||||
modalHeading.setAttribute("class", "modal-heading");
|
modalHeading.setAttribute("class", "modal-heading");
|
||||||
modalHeading.textContent = defaultOptions.heading;
|
modalHeading.textContent = options.heading;
|
||||||
modalBody.appendChild(modalHeading);
|
modalBody.appendChild(modalHeading);
|
||||||
};
|
};
|
||||||
if (defaultOptions.content) {
|
if (options.content) {
|
||||||
if (typeof defaultOptions.content == "string") {
|
if (typeof options.content == "string") {
|
||||||
var container = document.createElement("div");
|
var container = document.createElement("div");
|
||||||
container.setAttribute("class", "container");
|
container.setAttribute("class", "container");
|
||||||
var para = document.createElement("p");
|
var para = document.createElement("p");
|
||||||
para.textContent = defaultOptions.content;
|
para.textContent = options.content;
|
||||||
container.appendChild(para);
|
container.appendChild(para);
|
||||||
modalBody.appendChild(container);
|
modalBody.appendChild(container);
|
||||||
} else {
|
} else {
|
||||||
modalBody.appendChild(defaultOptions.content);
|
modalBody.appendChild(options.content);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
modalWrapper.appendChild(modalBody);
|
modalWrapper.appendChild(modalBody);
|
||||||
@@ -99,8 +99,8 @@ var modal = (function() {
|
|||||||
actionButton.addEventListener("click", function(event) {
|
actionButton.addEventListener("click", function(event) {
|
||||||
this.destroy();
|
this.destroy();
|
||||||
shade.destroy();
|
shade.destroy();
|
||||||
if (defaultOptions.action) {
|
if (options.action) {
|
||||||
defaultOptions.action();
|
options.action();
|
||||||
};
|
};
|
||||||
}.bind(modal), false);
|
}.bind(modal), false);
|
||||||
cancelButton.addEventListener("click", function(event) {
|
cancelButton.addEventListener("click", function(event) {
|
||||||
|
14
js/shade.js
14
js/shade.js
@@ -11,13 +11,13 @@ var shade = (function() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var render = function(options) {
|
var render = function(override) {
|
||||||
var defaultOptions = {
|
var options = {
|
||||||
action: null,
|
action: null,
|
||||||
includeHeader: false
|
includeHeader: false
|
||||||
};
|
};
|
||||||
if (options) {
|
if (override) {
|
||||||
defaultOptions = helper.applyOptions(defaultOptions, options);
|
options = helper.applyOptions(options, override);
|
||||||
};
|
};
|
||||||
var _destroy_previousShade = function() {
|
var _destroy_previousShade = function() {
|
||||||
if (previousShade != null) {
|
if (previousShade != null) {
|
||||||
@@ -28,7 +28,7 @@ var shade = (function() {
|
|||||||
var body = helper.e("body");
|
var body = helper.e("body");
|
||||||
var shade = document.createElement("div");
|
var shade = document.createElement("div");
|
||||||
shade.setAttribute("class", "shade");
|
shade.setAttribute("class", "shade");
|
||||||
if (defaultOptions.includeHeader) {
|
if (options.includeHeader) {
|
||||||
helper.addClass(shade, "m-shade-top");
|
helper.addClass(shade, "m-shade-top");
|
||||||
};
|
};
|
||||||
shade.destroy = function() {
|
shade.destroy = function() {
|
||||||
@@ -49,8 +49,8 @@ var shade = (function() {
|
|||||||
}.bind(shade), false);
|
}.bind(shade), false);
|
||||||
shade.addEventListener("click", function() {
|
shade.addEventListener("click", function() {
|
||||||
this.destroy();
|
this.destroy();
|
||||||
if (defaultOptions.action) {
|
if (options.action) {
|
||||||
defaultOptions.action();
|
options.action();
|
||||||
};
|
};
|
||||||
}, false);
|
}, false);
|
||||||
previousShade = shade;
|
previousShade = shade;
|
||||||
|
@@ -116,8 +116,7 @@ var state = (function() {
|
|||||||
return {
|
return {
|
||||||
init: init,
|
init: init,
|
||||||
get: get,
|
get: get,
|
||||||
change: change,
|
change: change
|
||||||
restore: restore
|
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
52
js/update.js
Normal file
52
js/update.js
Normal file
@@ -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
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
@@ -1,9 +1,10 @@
|
|||||||
var version = (function() {
|
var version = (function() {
|
||||||
|
|
||||||
var current = 2.0;
|
var current = "2.0.0";
|
||||||
|
|
||||||
var get = function() {
|
var get = function() {
|
||||||
return current;
|
var number = current.split(".");
|
||||||
|
return parseFloat(number.shift() + "." + number.join(""));
|
||||||
};
|
};
|
||||||
|
|
||||||
// exposed methods
|
// exposed methods
|
||||||
|
Reference in New Issue
Block a user