-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMMM-quotes.js
More file actions
56 lines (46 loc) · 1.44 KB
/
MMM-quotes.js
File metadata and controls
56 lines (46 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Module.register('MMM-quotes',{
// Module config defaults.
defaults: {
services: [ 'favqs', 'forismatic_en' ],
showAuthor: true,
updateInterval: 30000,
fadeSpeed: 4000,
classes: 'medium bright',
authorClasses: 'small normal align-right',
},
// Define start sequence.
start: function() {
Log.info('Starting module: ' + this.name);
this.quote = {content: '', author: ''};
var self = this;
this.interval = setInterval(function() {
self.getNewQuote();
}, this.config.updateInterval);
this.getNewQuote();
},
getNewQuote: function() {
var service = this.config.services[ Math.floor(Math.random() * this.config.services.length) ];
this.sendSocketNotification('GET_NEW_QUOTE', { service: service });
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'NEW_QUOTE') {
this.quote = payload;
this.updateDom(this.config.fadeSpeed);
}
},
getDom: function() {
var content = document.createTextNode(this.quote.content);
var wrapper = document.createElement('div');
wrapper.className = this.config.classes;
wrapper.appendChild(content);
// show the quote's author
if (this.config.showAuthor) {
var author = document.createTextNode(this.quote.author);
var authorWrapper = document.createElement('div');
authorWrapper.className = this.config.authorClasses;
authorWrapper.appendChild(author);
wrapper.appendChild(authorWrapper);
}
return wrapper;
},
});