mirror of
https://github.com/zombieFox/nightTab.git
synced 2025-01-14 09:58:21 +01:00
[refactor] improve link and data module
This commit is contained in:
parent
eba414733d
commit
eeabdcaf2c
@ -4,10 +4,7 @@ var control = (function() {
|
||||
element: helper.e(".control-menu-open"),
|
||||
type: "button",
|
||||
func: function() {
|
||||
menu.mod.open();
|
||||
menu.render.toggle();
|
||||
menu.render.tabindex.toggle();
|
||||
pagelock.render.toggle();
|
||||
menu.open();
|
||||
}
|
||||
}, {
|
||||
element: helper.e(".control-menu-layout"),
|
||||
@ -55,17 +52,13 @@ var control = (function() {
|
||||
element: helper.e(".control-menu-close"),
|
||||
type: "button",
|
||||
func: function() {
|
||||
shade.destroy();
|
||||
menu.mod.close();
|
||||
menu.render.toggle();
|
||||
menu.render.tabindex.toggle();
|
||||
pagelock.render.toggle();
|
||||
menu.close();
|
||||
}
|
||||
}, {
|
||||
element: helper.e(".control-link-add"),
|
||||
type: "button",
|
||||
func: function() {
|
||||
link.render.add();
|
||||
link.add();
|
||||
}
|
||||
}, {
|
||||
element: helper.e(".control-link-edit"),
|
||||
@ -73,6 +66,7 @@ var control = (function() {
|
||||
type: "checkbox",
|
||||
func: function() {
|
||||
render();
|
||||
link.render.tabindex();
|
||||
}
|
||||
}, {
|
||||
element: helper.e(".control-theme-accent-current"),
|
||||
@ -2144,7 +2138,7 @@ var control = (function() {
|
||||
element: helper.e(".control-background-image-file"),
|
||||
type: "file",
|
||||
func: function() {
|
||||
background.importData();
|
||||
background.mod.import();
|
||||
}
|
||||
}, {
|
||||
element: helper.e(".control-background-image-file-clear"),
|
||||
@ -2214,20 +2208,20 @@ var control = (function() {
|
||||
element: helper.e(".control-data-import"),
|
||||
type: "file",
|
||||
func: function() {
|
||||
data.importData();
|
||||
data.mod.import();
|
||||
}
|
||||
}, {
|
||||
element: helper.e(".control-data-export"),
|
||||
type: "a",
|
||||
func: function() {
|
||||
data.exportData();
|
||||
data.mod.export();
|
||||
}
|
||||
}, {
|
||||
element: helper.e(".control-data-clear"),
|
||||
type: "a",
|
||||
func: function() {
|
||||
menu.close();
|
||||
data.clearData();
|
||||
data.render.clear();
|
||||
}
|
||||
}];
|
||||
|
||||
@ -2465,7 +2459,6 @@ var control = (function() {
|
||||
helper.removeClass(html, "is-link-style-list");
|
||||
helper.removeClass(html, "is-link-style-block");
|
||||
helper.removeClass(html, "is-link-edit");
|
||||
link.render.tabIndex();
|
||||
if (state.get().link.show) {
|
||||
helper.addClass(html, "is-link-show");
|
||||
helper.addClass(html, "is-link-area-alignment-" + state.get().link.area.alignment);
|
||||
@ -2488,7 +2481,6 @@ var control = (function() {
|
||||
};
|
||||
if (state.get().link.edit) {
|
||||
helper.addClass(html, "is-link-edit");
|
||||
link.render.tabIndex();
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -95,7 +95,7 @@ var data = (function() {
|
||||
var para2 = helper.node("p:This can not be undone.");
|
||||
clearContent.appendChild(para1);
|
||||
clearContent.appendChild(para2);
|
||||
modal.render({
|
||||
modal.render.make({
|
||||
heading: "Clear all nightTab data?",
|
||||
content: clearContent,
|
||||
successAction: function() {
|
||||
|
@ -10,11 +10,10 @@ var keyboard = (function() {
|
||||
edge.render.clear();
|
||||
} else if (state.get().menu) {
|
||||
menu.close();
|
||||
shade.destroy();
|
||||
} else if (state.get().autoSuggest) {
|
||||
autoSuggest.destroy();
|
||||
} else if (state.get().modal) {
|
||||
modal.destroy();
|
||||
modal.render.clear();
|
||||
shade.destroy();
|
||||
} else if (state.get().link.edit) {
|
||||
helper.setObject({
|
||||
@ -34,9 +33,14 @@ var keyboard = (function() {
|
||||
window.addEventListener("keydown", function(event) {
|
||||
// ctrl+alt+a
|
||||
if (event.ctrlKey && event.altKey && event.keyCode == 65) {
|
||||
if (state.get().link.show) {
|
||||
if (!state.get().link.add) {
|
||||
if (state.get().menu) {
|
||||
menu.close();
|
||||
link.render.add();
|
||||
};
|
||||
if (state.get().modal) {
|
||||
modal.render.clear();
|
||||
};
|
||||
link.add();
|
||||
};
|
||||
};
|
||||
}, false);
|
||||
@ -58,8 +62,9 @@ var keyboard = (function() {
|
||||
window.addEventListener("keydown", function(event) {
|
||||
// ctrl+alt+m
|
||||
if (event.ctrlKey && event.altKey && event.keyCode == 77) {
|
||||
shade.destroy();
|
||||
modal.destroy();
|
||||
if (state.get().modal) {
|
||||
modal.render.clear();
|
||||
};
|
||||
menu.toggle();
|
||||
};
|
||||
}, false);
|
||||
@ -69,25 +74,12 @@ var keyboard = (function() {
|
||||
window.addEventListener("keydown", function(event) {
|
||||
// ctrl+alt+e
|
||||
if (event.ctrlKey && event.altKey && event.keyCode == 69) {
|
||||
if (state.get().link.show && bookmarks.get().length > 0) {
|
||||
if (state.get().link.edit) {
|
||||
helper.setObject({
|
||||
object: state.get(),
|
||||
path: "link.edit",
|
||||
newValue: false
|
||||
});
|
||||
} else {
|
||||
helper.setObject({
|
||||
object: state.get(),
|
||||
path: "link.edit",
|
||||
newValue: true
|
||||
});
|
||||
};
|
||||
link.mod.edit.toggle();
|
||||
link.render.tabindex();
|
||||
control.update();
|
||||
control.render();
|
||||
data.save();
|
||||
};
|
||||
};
|
||||
}, false);
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,37 @@ var link = (function() {
|
||||
}
|
||||
};
|
||||
|
||||
mod.edit = function() {
|
||||
mod.edit = {
|
||||
open: function() {
|
||||
helper.setObject({
|
||||
object: state.get(),
|
||||
path: "link.edit",
|
||||
newValue: true
|
||||
});
|
||||
},
|
||||
close: function() {
|
||||
helper.setObject({
|
||||
object: state.get(),
|
||||
path: "link.edit",
|
||||
newValue: false
|
||||
});
|
||||
},
|
||||
toggle: function() {
|
||||
if (state.get().link.edit) {
|
||||
helper.setObject({
|
||||
object: state.get(),
|
||||
path: "link.edit",
|
||||
newValue: false
|
||||
});
|
||||
} else {
|
||||
helper.setObject({
|
||||
object: state.get(),
|
||||
path: "link.edit",
|
||||
newValue: true
|
||||
});
|
||||
};
|
||||
},
|
||||
check: function() {
|
||||
if (bookmarks.get().length <= 0) {
|
||||
helper.setObject({
|
||||
object: state.get(),
|
||||
@ -38,6 +68,39 @@ var link = (function() {
|
||||
newValue: false
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
mod.add = {
|
||||
open: function() {
|
||||
helper.setObject({
|
||||
object: state.get(),
|
||||
path: "link.add",
|
||||
newValue: true
|
||||
});
|
||||
},
|
||||
close: function() {
|
||||
helper.setObject({
|
||||
object: state.get(),
|
||||
path: "link.add",
|
||||
newValue: false
|
||||
});
|
||||
},
|
||||
toggle: function() {
|
||||
if (state.get().link.add) {
|
||||
helper.setObject({
|
||||
object: state.get(),
|
||||
path: "link.add",
|
||||
newValue: false
|
||||
});
|
||||
} else {
|
||||
helper.setObject({
|
||||
object: state.get(),
|
||||
path: "link.add",
|
||||
newValue: true
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
var bind = {};
|
||||
@ -104,21 +167,23 @@ var link = (function() {
|
||||
render.add = function() {
|
||||
stagedLink.init();
|
||||
var form = render.form();
|
||||
modal.render({
|
||||
modal.render.make({
|
||||
heading: "Add a new bookmark",
|
||||
successAction: function() {
|
||||
stagedLink.data.timeStamp = new Date().getTime();
|
||||
bookmarks.add(JSON.parse(JSON.stringify(stagedLink.data)));
|
||||
data.save();
|
||||
mod.add.close();
|
||||
render.clear();
|
||||
render.item.all();
|
||||
render.tabIndex();
|
||||
render.tabindex();
|
||||
sortable(".link-area");
|
||||
control.dependents();
|
||||
control.render();
|
||||
stagedLink.reset();
|
||||
},
|
||||
cancelAction: function() {
|
||||
mod.add.close();
|
||||
stagedLink.reset();
|
||||
autoSuggest.destroy();
|
||||
},
|
||||
@ -159,14 +224,14 @@ var link = (function() {
|
||||
if (stagedLink.data.accent.override) {
|
||||
form.querySelector(".link-form-input-color").value = helper.rgbToHex(stagedLink.data.accent.color);
|
||||
};
|
||||
modal.render({
|
||||
modal.render.make({
|
||||
heading: "Edit " + stagedLink.data.name,
|
||||
successAction: function() {
|
||||
bookmarks.edit(JSON.parse(JSON.stringify(stagedLink.data)));
|
||||
data.save();
|
||||
render.clear();
|
||||
render.item.all();
|
||||
render.tabIndex();
|
||||
render.tabindex();
|
||||
render.previousFocus();
|
||||
sortable(".link-area");
|
||||
stagedLink.reset();
|
||||
@ -182,13 +247,13 @@ var link = (function() {
|
||||
};
|
||||
|
||||
render.remove = function(bookmarkData) {
|
||||
modal.render({
|
||||
modal.render.make({
|
||||
heading: "Remove " + bookmarkData.name + " bookmark",
|
||||
content: "Are you sure you want to remove this bookmark? This can not be undone.",
|
||||
successAction: function() {
|
||||
_previousFocus = _previousFocus - 1;
|
||||
bookmarks.remove(bookmarkData);
|
||||
mod.edit();
|
||||
mod.edit.check();
|
||||
header.render.button.edit();
|
||||
data.save();
|
||||
render.clear();
|
||||
@ -517,7 +582,7 @@ var link = (function() {
|
||||
}
|
||||
};
|
||||
|
||||
render.tabIndex = function() {
|
||||
render.tabindex = function() {
|
||||
var allLinkControlItem = helper.eA(".link-control-item");
|
||||
if (state.get().link.edit) {
|
||||
allLinkControlItem.forEach(function(arrayItem, index) {
|
||||
@ -694,7 +759,8 @@ var link = (function() {
|
||||
};
|
||||
|
||||
var add = function() {
|
||||
link.render.add();
|
||||
mod.add.open();
|
||||
render.add();
|
||||
};
|
||||
|
||||
var init = function() {
|
||||
|
@ -166,6 +166,7 @@ var state = (function() {
|
||||
},
|
||||
show: true,
|
||||
edit: false,
|
||||
add: false,
|
||||
style: "block"
|
||||
},
|
||||
layout: {
|
||||
|
@ -1,6 +1,6 @@
|
||||
var version = (function() {
|
||||
|
||||
var current = "3.46.0";
|
||||
var current = "3.48.0";
|
||||
|
||||
var compare = function(a, b) {
|
||||
var pa = a.split(".");
|
||||
|
@ -2,7 +2,7 @@
|
||||
"name": "nightTab",
|
||||
"short_name": "nightTab",
|
||||
"description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.",
|
||||
"version": "3.46.0",
|
||||
"version": "3.47.0",
|
||||
"manifest_version": 2,
|
||||
"chrome_url_overrides": {
|
||||
"newtab": "index.html"
|
||||
|
Loading…
Reference in New Issue
Block a user