Merge pull request #269 from nhubbard/v2-beta

clockBold's Re-Incarnation
This commit is contained in:
Michael Teeuw 2016-04-29 18:55:55 +02:00
commit e572d544ef
2 changed files with 23 additions and 23 deletions

View File

@ -47,14 +47,21 @@ The following properties can be configured:
</tr> </tr>
<tr> <tr>
<td><code>showPeriod</code></td> <td><code>showPeriod</code></td>
<td>Show the period (am/pm) with 12 hour format<br> <td>Show the period (am/pm) with 12 hour format.<br>
<br><b>Possible values:</b> <code>true</code> or <code>false</code> <br><b>Possible values:</b> <code>true</code> or <code>false</code>
<br><b>Default value:</b> <code>true</code> <br><b>Default value:</b> <code>true</code>
</td> </td>
</tr> </tr>
<tr> <tr>
<td><code>showPeriodUpper</code></td> <td><code>showPeriodUpper</code></td>
<td>Show the period (AM/PM) with 12 hour format as uppercase<br> <td>Show the period (AM/PM) with 12 hour format as uppercase.<br>
<br><b>Possible values:</b> <code>true</code> or <code>false</code>
<br><b>Default value:</b> <code>false</code>
</td>
</tr>
<tr>
<td><code>clockBold</code></td>
<td>Remove the colon and bold the minutes to make a more modern look.<br>
<br><b>Possible values:</b> <code>true</code> or <code>false</code> <br><b>Possible values:</b> <code>true</code> or <code>false</code>
<br><b>Default value:</b> <code>false</code> <br><b>Default value:</b> <code>false</code>
</td> </td>

View File

@ -1,41 +1,34 @@
/* global Log, Module, moment, config */ /* global Log, Module, moment, config */
/* Magic Mirror /* Magic Mirror
* Module: Clock * Module: Clock
* *
* By Michael Teeuw http://michaelteeuw.nl * By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed. * MIT Licensed.
*/ */
Module.register("clock",{ Module.register("clock",{
// Module config defaults. // Module config defaults.
defaults: { defaults: {
timeFormat: config.timeFormat, timeFormat: config.timeFormat,
displaySeconds: true, displaySeconds: true,
showPeriod: true, showPeriod: true,
showPeriodUpper: false, showPeriodUpper: false,
clockBold: false
}, },
// Define required scripts. // Define required scripts.
getScripts: function() { getScripts: function() {
return ["moment.js"]; return ["moment.js"];
}, },
// Define start sequence. // Define start sequence.
start: function() { start: function() {
Log.info("Starting module: " + this.name); Log.info("Starting module: " + this.name);
// Schedule update interval. // Schedule update interval.
var self = this; var self = this;
setInterval(function() { setInterval(function() {
self.updateDom(); self.updateDom();
}, 1000); }, 1000);
// Set locale. // Set locale.
moment.locale(config.language); moment.locale(config.language);
}, },
// Override dom generator. // Override dom generator.
getDom: function() { getDom: function() {
// Create wrappers. // Create wrappers.
@ -44,35 +37,36 @@ Module.register("clock",{
var timeWrapper = document.createElement("div"); var timeWrapper = document.createElement("div");
var secondsWrapper = document.createElement("sup"); var secondsWrapper = document.createElement("sup");
var periodWrapper = document.createElement("span"); var periodWrapper = document.createElement("span");
// Style Wrappers // Style Wrappers
dateWrapper.className = "date normal medium"; dateWrapper.className = "date normal medium";
timeWrapper.className = "time bright large light"; timeWrapper.className = "time bright large light";
secondsWrapper.className = "dimmed"; secondsWrapper.className = "dimmed";
// Set content of wrappers. // Set content of wrappers.
// The moment().format('h') method has a bug on the Raspberry Pi. // The moment().format("h") method has a bug on the Raspberry Pi.
// So we need to generate the timestring manually. // So we need to generate the timestring manually.
// See issue: https://github.com/MichMich/MagicMirror/issues/181 // See issue: https://github.com/MichMich/MagicMirror/issues/181
var timeString = moment().format('HH:mm'); if (this.config.clockBold === true) {
var timeString = moment().format("HH[<span class=\"bold\">]mm[</span>]");
} else {
var timeString = moment().format("HH:mm");
}
if (this.config.timeFormat !== 24) { if (this.config.timeFormat !== 24) {
var now = new Date(); var now = new Date();
var hours = now.getHours() % 12 || 12; var hours = now.getHours() % 12 || 12;
timeString = hours + moment().format(':mm'); if (this.config.clockBold === true) {
timeString = hours + moment().format("[<span class=\"bold\">]mm[</span>]");
} else {
timeString = hours + moment().format(":mm");
}
} }
dateWrapper.innerHTML = moment().format("dddd, LL"); dateWrapper.innerHTML = moment().format("dddd, LL");
timeWrapper.innerHTML = timeString; timeWrapper.innerHTML = timeString;
secondsWrapper.innerHTML = moment().format("ss"); secondsWrapper.innerHTML = moment().format("ss");
if (this.config.showPeriodUpper) { if (this.config.showPeriodUpper) {
periodWrapper.innerHTML = moment().format('A'); periodWrapper.innerHTML = moment().format("A");
} else { } else {
periodWrapper.innerHTML = moment().format('a'); periodWrapper.innerHTML = moment().format("a");
} }
// Combine wrappers. // Combine wrappers.
wrapper.appendChild(dateWrapper); wrapper.appendChild(dateWrapper);
wrapper.appendChild(timeWrapper); wrapper.appendChild(timeWrapper);
@ -82,7 +76,6 @@ Module.register("clock",{
if (this.config.showPeriod && this.config.timeFormat !== 24) { if (this.config.showPeriod && this.config.timeFormat !== 24) {
timeWrapper.appendChild(periodWrapper); timeWrapper.appendChild(periodWrapper);
} }
// Return the wrapper to the dom. // Return the wrapper to the dom.
return wrapper; return wrapper;
} }