forked from dv336699/MMM-RandomPhoto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-RandomPhoto.js
58 lines (48 loc) · 1.36 KB
/
MMM-RandomPhoto.js
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
57
58
/* global Module */
/* Magic Mirror
* Module: MMM-RandomPhoto
*
* By Diego Vieira <diego@protos.inf.br>
* ICS Licensed.
*/
Module.register("MMM-RandomPhoto",{
defaults: {
opacity: 0.3,
animationSpeed: 500,
updateInterval: 60,
url: 'https://unsplash.it/1920/1080/?random'
},
start: function() {
this.load();
},
load: function() {
var self = this;
var url = self.config.url + (self.config.url.indexOf('?') > -1 ? '&' : '?') + (new Date().getTime());
var img = $('<img />').attr('src', url);
img.on('load', function() {
$('#mmm-photos-placeholder1').attr('src', url).animate({
opacity: self.config.opacity
}, self.config.animationSpeed, function() {
$(this).attr('id', 'mmm-photos-placeholder2');
});
$('#mmm-photos-placeholder2').animate({
opacity: 0
}, self.config.animationSpeed, function() {
$(this).attr('id', 'mmm-photos-placeholder1');
});
});
setTimeout(function() {
self.load();
}, (self.config.updateInterval * 1000));
},
getDom: function() {
var wrapper = document.createElement("div");
wrapper.innerHTML = '<img id="mmm-photos-placeholder1" style="opacity: 0; position: absolute" /><img id="mmm-photos-placeholder2" style="opacity: 0; position: absolute" />';
return wrapper;
},
getScripts: function() {
return [
this.file('node_modules/jquery/dist/jquery.min.js')
]
}
});