Add module subfolder support.

This commit is contained in:
Michael Teeuw
2016-04-01 17:35:29 +02:00
parent 671338425a
commit e4c54cc655
27 changed files with 56 additions and 21 deletions

View File

@@ -0,0 +1,49 @@
# Module: Clock
The `clock` module is one of the default modules of the MagicMirror.
This module displays the current date and time. The information will be updated realtime.
## Using the module
To use this module, add it to the modules array in the `config/config.js` file:
````javascript
modules: [
{
module: 'clock',
position: 'top_left', // This can be any of the regions.
config: {
// The config property is optional.
// See 'Configuration options' for more information.
}
}
]
````
## Configuration options
The following properties can be configured:
<table width="100%">
<!-- why, markdown... -->
<thead>
<tr>
<th>Option</th>
<th width="100%">Description</th>
</tr>
<thead>
<tbody>
<tr>
<td><code>timeFormat</code></td>
<td>Use 12 or 24 hour format.<br>
<br><b>Possible values:</b> <code>12</code> or <code>24</code>
<br><b>Default value:</b> uses value of <i>config.timeFormat</i>
</td>
</tr>
<tr>
<td><code>displaySeconds</code></td>
<td>Display seconds.<br>
<br><b>Possible values:</b> <code>true</code> or <code>false</code>
<br><b>Default value:</b> <code>true</code>
</td>
</tr>
</tbody>
</table>

View File

@@ -0,0 +1,67 @@
/* global Log, Module, moment, config */
/* Magic Mirror
* Module: Clock
*
* By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed.
*/
Module.register('clock',{
// Module config defaults.
defaults: {
timeFormat: config.timeFormat,
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);
},
// 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');
// Combine wrappers.
wrapper.appendChild(dateWrapper);
wrapper.appendChild(timeWrapper);
if (this.config.displaySeconds) {
timeWrapper.appendChild(secondsWrapper);
}
// Return the wrapper to the dom.
return wrapper;
}
});