nightTab/js/date.js

115 lines
2.7 KiB
JavaScript
Raw Normal View History

2019-01-05 21:57:21 +01:00
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 time = helper.getDateTime();
return time;
};
var render = function() {
var _date = function() {
var date = helper.e(".date");
var time = _makeTimeObject();
2019-01-06 06:08:26 +01:00
time.day = helper.day(time.day);
2019-01-05 21:57:21 +01:00
time.month = helper.month(time.month);
if (state.get().header.date.characterLength == "short") {
time.day = time.day.substring(0, 3);
time.month = time.month.substring(0, 3);
};
var sepCha = "/";
var dateNumber = helper.makeNode({
tag: "span",
text: time.date,
attr: [{
key: "class",
value: "date-item date-date"
}]
});
var day = helper.makeNode({
tag: "span",
text: time.day,
attr: [{
key: "class",
value: "date-item date-day"
}]
});
var month = helper.makeNode({
tag: "span",
text: time.month,
attr: [{
key: "class",
value: "date-item date-month"
}]
});
var year = helper.makeNode({
tag: "span",
text: time.year,
attr: [{
key: "class",
value: "date-item date-year"
}]
});
if (state.get().header.date.show.date) {
date.appendChild(dateNumber);
};
if (state.get().header.date.show.day) {
date.appendChild(day);
};
if (state.get().header.date.show.month) {
date.appendChild(month);
};
if (state.get().header.date.show.year) {
date.appendChild(year);
};
2019-01-05 23:35:50 +01:00
if (state.get().header.date.show.separator) {
2019-01-05 21:57:21 +01:00
var parts = date.querySelectorAll("span");
if (parts.length > 1) {
parts.forEach(function(arrayItem, index) {
if (index > 0) {
2019-01-05 23:35:50 +01:00
var separator = helper.makeNode({
2019-01-05 21:57:21 +01:00
tag: "span",
text: sepCha,
attr: [{
key: "class",
2019-01-05 23:35:50 +01:00
value: "date-separator"
2019-01-05 21:57:21 +01:00
}]
});
2019-01-05 23:35:50 +01:00
date.insertBefore(separator, arrayItem);
2019-01-05 21:57:21 +01:00
};
});
};
};
};
if (state.get().header.date.show.date || state.get().header.date.show.day || state.get().header.date.show.month || state.get().header.date.show.year) {
_date();
};
};
var init = function() {
render();
bind();
};
// exposed methods
return {
init: init,
bind: bind,
render: render,
clear: clear
};
})();