2016-03-24 17:19:32 +01:00
|
|
|
/* global Log, Module, moment, config */
|
|
|
|
|
|
|
|
/* Magic Mirror
|
|
|
|
* Module: Clock
|
|
|
|
*
|
|
|
|
* By Michael Teeuw http://michaelteeuw.nl
|
|
|
|
* MIT Licensed.
|
|
|
|
*/
|
|
|
|
|
2016-03-31 13:05:23 +02:00
|
|
|
Module.register('clock',{
|
2016-03-24 17:19:32 +01:00
|
|
|
|
|
|
|
// Module config defaults.
|
|
|
|
defaults: {
|
2016-03-29 13:28:15 +02:00
|
|
|
timeFormat: config.timeFormat,
|
2016-03-24 17:19:32 +01:00
|
|
|
displaySeconds: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
// Define required scripts.
|
|
|
|
getScripts: function() {
|
|
|
|
return ['moment.js'];
|
|
|
|
},
|
|
|
|
|
|
|
|
// Define start sequence.
|
|
|
|
start: function() {
|
|
|
|
Log.info('Starting module: ' + this.name);
|
|
|
|
|
|
|
|
// Schedule update interval.
|
|
|
|
var self = this;
|
|
|
|
setInterval(function() {
|
|
|
|
self.updateDom();
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
// Set locale.
|
|
|
|
moment.locale(config.language);
|
|
|
|
},
|
2016-04-01 22:52:32 +02:00
|
|
|
|
2016-03-24 17:19:32 +01:00
|
|
|
|
|
|
|
// Override dom generator.
|
|
|
|
getDom: function() {
|
|
|
|
// Create wrappers.
|
|
|
|
var wrapper = document.createElement("div");
|
|
|
|
var dateWrapper = document.createElement("div");
|
|
|
|
var timeWrapper = document.createElement("div");
|
|
|
|
var secondsWrapper = document.createElement("sup");
|
|
|
|
|
|
|
|
// Style Wrappers
|
|
|
|
dateWrapper.className = "date normal medium";
|
|
|
|
timeWrapper.className = "time bright large light";
|
|
|
|
secondsWrapper.className = "dimmed";
|
|
|
|
|
|
|
|
// Set content of wrappers.
|
|
|
|
dateWrapper.innerHTML = moment().format('dddd, LL');
|
|
|
|
timeWrapper.innerHTML = moment().format((this.config.timeFormat === 24) ? 'HH:mm' : ('hh:mm'));
|
|
|
|
secondsWrapper.innerHTML = moment().format('ss');
|
2016-04-01 22:52:32 +02:00
|
|
|
|
2016-03-24 17:19:32 +01:00
|
|
|
// Combine wrappers.
|
|
|
|
wrapper.appendChild(dateWrapper);
|
|
|
|
wrapper.appendChild(timeWrapper);
|
|
|
|
if (this.config.displaySeconds) {
|
|
|
|
timeWrapper.appendChild(secondsWrapper);
|
|
|
|
}
|
2016-04-01 22:52:32 +02:00
|
|
|
|
2016-03-24 17:19:32 +01:00
|
|
|
// Return the wrapper to the dom.
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
});
|