This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathMMM-iFrame.js
67 lines (58 loc) · 2.06 KB
/
MMM-iFrame.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
59
60
61
62
63
64
65
66
67
/* global Module */
/* Magic Mirror
* Module: iFrame
*
* By Ben Williams http://desertblade.com
* MIT Licensed.
*/
Module.register("MMM-iFrame",{
// Default module config.
defaults: {
frameWidth: "300",
width:"100%",
updateInterval: 0.5 * 60 * 1000,
url: ["http://magicmirror.builders/"],
scrolling: "no"
},
start: function () {
self = this;
var count = 0;
if (this.config.url.length > 0 ) {
setInterval( function () {
self.updateDom(1000);
console.log('update' + count++)
}, this.config.updateInterval);
}
},
getRandomInt: function (min, max) {
return Math.floor(Math.random() * (max - min)) + min;
},
resume: function() {
console.log("Resuming");
return this.getDom();
},
getStyles: function() {
return [
"MMM-iFrame.css",
];
},
// Override dom generator.
getDom: function() {
var { width, height } = this.config;
var wrapper = document.createElement("div");
wrapper.className = "mmm-iframe"
wrapper.style.width = `${this.config.frameWidth}px`;
var html = `
<div class="mmm-iframe-wrapper" style="padding-top: ${100 / (width / height)}%;">
<iframe
src="${this.config.url[this.getRandomInt(0, this.config.url.length)]}"
width="${width}"
height="${height}"
scrolling="${this.config.scrolling}"
></iframe>
</div>
`;
wrapper.insertAdjacentHTML("afterbegin", html);
return wrapper;
}
});