-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMMM-QRCode.js
65 lines (51 loc) · 1.37 KB
/
MMM-QRCode.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
/* global Module */
/* Magic Mirror
* Module: QRCode
*
* By Evghenii Marinescu https://github.com/MarinescuEvghenii/
* MIT Licensed.
*/
'use strict';
Module.register("MMM-QRCode", {
defaults: {
text : 'https://github.com/MarinescuEvghenii/MMM-QRCode',
colorDark : "#fff",
colorLight : "#000",
imageSize : 150,
showRaw : true
},
getStyles: function() {
return ["MMM-QRCode.css"];
},
getScripts: function() {
return ["qrcode.min.js"];
},
start: function() {
this.config = Object.assign({}, this.defaults, this.config);
Log.log("Starting module: " + this.name);
},
getDom: function() {
const wrapperEl = document.createElement("div");
wrapperEl.classList.add('qrcode');
const qrcodeEl = document.createElement("div");
new QRCode(qrcodeEl, {
text: this.config.text,
width: this.config.imageSize,
height: this.config.imageSize,
colorDark : this.config.colorDark,
colorLight : this.config.colorLight,
correctLevel : QRCode.CorrectLevel.H
});
const imageEl = document.createElement("div");
imageEl.classList.add('qrcode__image');
imageEl.appendChild(qrcodeEl);
wrapperEl.appendChild(imageEl);
if(this.config.showRaw) {
const textEl = document.createElement("div");
textEl.classList.add('qrcode__text');
textEl.innerHTML = this.config.text;
wrapperEl.appendChild(textEl);
}
return wrapperEl;
}
});