[refactor] improve date render and bind

This commit is contained in:
zombieFox 2019-07-15 19:40:10 +01:00
parent faa3471db1
commit acba96b531
4 changed files with 81 additions and 110 deletions

View File

@ -822,8 +822,8 @@ var control = (function() {
func: function() { func: function() {
render(); render();
dependents(); dependents();
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -835,8 +835,8 @@ var control = (function() {
type: "radio", type: "radio",
func: function() { func: function() {
dependents(); dependents();
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -847,8 +847,8 @@ var control = (function() {
path: "header.date.day.weekStart", path: "header.date.day.weekStart",
type: "radio", type: "radio",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -859,8 +859,8 @@ var control = (function() {
path: "header.date.day.weekStart", path: "header.date.day.weekStart",
type: "radio", type: "radio",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -872,8 +872,8 @@ var control = (function() {
type: "radio", type: "radio",
func: function() { func: function() {
dependents(); dependents();
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -884,8 +884,8 @@ var control = (function() {
path: "header.date.day.length", path: "header.date.day.length",
type: "radio", type: "radio",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -896,8 +896,8 @@ var control = (function() {
path: "header.date.day.length", path: "header.date.day.length",
type: "radio", type: "radio",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -910,8 +910,8 @@ var control = (function() {
func: function() { func: function() {
render(); render();
dependents(); dependents();
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -922,8 +922,8 @@ var control = (function() {
path: "header.date.date.display", path: "header.date.date.display",
type: "radio", type: "radio",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -934,8 +934,8 @@ var control = (function() {
path: "header.date.date.display", path: "header.date.date.display",
type: "radio", type: "radio",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -946,8 +946,8 @@ var control = (function() {
path: "header.date.date.ordinal", path: "header.date.date.ordinal",
type: "checkbox", type: "checkbox",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -960,8 +960,8 @@ var control = (function() {
func: function() { func: function() {
render(); render();
dependents(); dependents();
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -973,8 +973,8 @@ var control = (function() {
type: "radio", type: "radio",
func: function() { func: function() {
dependents(); dependents();
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -985,8 +985,8 @@ var control = (function() {
path: "header.date.month.ordinal", path: "header.date.month.ordinal",
type: "checkbox", type: "checkbox",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -998,8 +998,8 @@ var control = (function() {
type: "radio", type: "radio",
func: function() { func: function() {
dependents(); dependents();
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -1010,8 +1010,8 @@ var control = (function() {
path: "header.date.month.length", path: "header.date.month.length",
type: "radio", type: "radio",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -1022,8 +1022,8 @@ var control = (function() {
path: "header.date.month.length", path: "header.date.month.length",
type: "radio", type: "radio",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -1036,8 +1036,8 @@ var control = (function() {
func: function() { func: function() {
render(); render();
dependents(); dependents();
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -1048,8 +1048,8 @@ var control = (function() {
path: "header.date.year.display", path: "header.date.year.display",
type: "radio", type: "radio",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -1060,8 +1060,8 @@ var control = (function() {
path: "header.date.year.display", path: "header.date.year.display",
type: "radio", type: "radio",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -1072,8 +1072,8 @@ var control = (function() {
path: "header.date.separator.show", path: "header.date.separator.show",
type: "checkbox", type: "checkbox",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -1084,8 +1084,8 @@ var control = (function() {
path: "header.date.format", path: "header.date.format",
type: "radio", type: "radio",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();
@ -1096,8 +1096,8 @@ var control = (function() {
path: "header.date.format", path: "header.date.format",
type: "radio", type: "radio",
func: function() { func: function() {
date.clear(); date.render.clear();
date.render(); date.render.all();
greeting.clear(); greeting.clear();
greeting.render(); greeting.render();
transitional.clear(); transitional.clear();

View File

@ -1,22 +1,7 @@
var date = (function() { var date = (function() {
var bind = function() {
window.setInterval(function() {
clear();
render();
}, 1000);
};
var clear = function() {
var date = helper.e(".date");
while (date.lastChild) {
date.removeChild(date.lastChild);
};
};
var _makeTimeObject = function() { var _makeTimeObject = function() {
var date = helper.getDateTime(); return helper.getDateTime();
return date;
}; };
var _month = function(index) { var _month = function(index) {
@ -29,11 +14,29 @@ var date = (function() {
return all[index]; return all[index];
}; };
var render = function() { var bind = {};
var _date = function() {
bind.tick = function() {
window.setInterval(function() {
render.clear();
render.all();
}, 1000);
};
var render = {};
render.clear = function() {
var date = helper.e(".date");
while (date.lastChild) {
date.removeChild(date.lastChild);
};
};
render.all = function() {
if (state.get().header.date.date.show || state.get().header.date.day.show || state.get().header.date.month.show || state.get().header.date.year.show) {
var date = helper.e(".date"); var date = helper.e(".date");
var dateObject = _makeTimeObject(); var dateObject = _makeTimeObject();
var action = { var wordOrNumber = {
day: { day: {
word: function(value) { word: function(value) {
return _day(value); return _day(value);
@ -86,48 +89,20 @@ var date = (function() {
} }
} }
}; };
dateObject.day = action.day[state.get().header.date.day.display](dateObject.day); dateObject.day = wordOrNumber.day[state.get().header.date.day.display](dateObject.day);
dateObject.date = action.date[state.get().header.date.date.display](dateObject.date); dateObject.date = wordOrNumber.date[state.get().header.date.date.display](dateObject.date);
dateObject.month = action.month[state.get().header.date.month.display](dateObject.month); dateObject.month = wordOrNumber.month[state.get().header.date.month.display](dateObject.month);
dateObject.year = action.year[state.get().header.date.year.display](dateObject.year); dateObject.year = wordOrNumber.year[state.get().header.date.year.display](dateObject.year);
if (state.get().header.date.day.display == "word" && state.get().header.date.day.length == "short") { if (state.get().header.date.day.display == "word" && state.get().header.date.day.length == "short") {
dateObject.day = dateObject.day.substring(0, 3); dateObject.day = dateObject.day.substring(0, 3);
}; };
if (state.get().header.date.month.display == "word" && state.get().header.date.month.length == "short") { if (state.get().header.date.month.display == "word" && state.get().header.date.month.length == "short") {
dateObject.month = dateObject.month.substring(0, 3); dateObject.month = dateObject.month.substring(0, 3);
}; };
var elementDay = helper.makeNode({ var elementDay = helper.node("span:" + dateObject.day + "|class:date-item date-day");
tag: "span", var elementDate = helper.node("span:" + dateObject.date + "|class:date-item date-date");
text: dateObject.day, var elementMonth = helper.node("span:" + dateObject.month + "|class:date-item date-month");
attr: [{ var elementyear = helper.node("span:" + dateObject.year + "|class:date-item date-year");
key: "class",
value: "date-item date-day"
}]
});
var elementDate = helper.makeNode({
tag: "span",
text: dateObject.date,
attr: [{
key: "class",
value: "date-item date-date"
}]
});
var elementMonth = helper.makeNode({
tag: "span",
text: dateObject.month,
attr: [{
key: "class",
value: "date-item date-month"
}]
});
var elementyear = helper.makeNode({
tag: "span",
text: dateObject.year,
attr: [{
key: "class",
value: "date-item date-year"
}]
});
if (state.get().header.date.day.show) { if (state.get().header.date.day.show) {
date.appendChild(elementDay); date.appendChild(elementDay);
}; };
@ -178,22 +153,18 @@ var date = (function() {
}; };
}; };
}; };
if (state.get().header.date.date.show || state.get().header.date.day.show || state.get().header.date.month.show || state.get().header.date.year.show) {
_date();
};
}; };
var init = function() { var init = function() {
render(); render.all();
bind(); bind.tick();
}; };
// exposed methods // exposed methods
return { return {
init: init, init: init,
bind: bind, bind: bind,
render: render, render: render
clear: clear
}; };
})(); })();

View File

@ -1,6 +1,6 @@
var version = (function() { var version = (function() {
var current = "3.35.0"; var current = "3.36.0";
var compare = function(a, b) { var compare = function(a, b) {
var pa = a.split("."); var pa = a.split(".");

View File

@ -2,7 +2,7 @@
"name": "nightTab", "name": "nightTab",
"short_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.", "description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.",
"version": "3.35.0", "version": "3.36.0",
"manifest_version": 2, "manifest_version": 2,
"chrome_url_overrides": { "chrome_url_overrides": {
"newtab": "index.html" "newtab": "index.html"