-
Notifications
You must be signed in to change notification settings - Fork 2
/
MMM-HTMLBox.js
61 lines (55 loc) · 1.37 KB
/
MMM-HTMLBox.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
/* Magic Mirror
* Module: MMM-HTMLBox
*
* By eouia
*/
Module.register("MMM-HTMLBox",{
defaults: {
width: "100%",
height: "inherit",
refresh_interval_sec: 0,
content: "There is nothing to display. <br>Put your HTML code into content field in 'config.js'.",
file: "sample.html",
},
start: function() {
this.timer = null
},
notificationReceived: function(noti, payload, sender) {
if (noti == "DOM_OBJECTS_CREATED") {
this.refresh()
}
},
refresh: function() {
if (this.config.file !== "") {
this.readFileTrick("/modules/MMM-HTMLBox/" + this.config.file)
}
this.updateDom()
if (this.config.refresh_interval_sec > 0) {
var self = this
this.timer = setTimeout(function(){
self.refresh()
}, this.config.refresh_interval_sec * 1000)
}
},
getDom: function() {
var wrapper = document.createElement("div")
wrapper.innerHTML = this.config.content
wrapper.className = "HTMLBX"
wrapper.style.width = this.config.width
wrapper.style.height = this.config.height
return wrapper
},
readFileTrick: function (url, callback) {
var xmlHttp = new XMLHttpRequest()
var self = this
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
console.log("EEE!")
self.config.content = xmlHttp.responseText
self.updateDom()
}
}
xmlHttp.open("GET", url, true)
xmlHttp.send(null)
}
})