-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
MMM-EmbedYoutube.js
62 lines (57 loc) · 2.12 KB
/
MMM-EmbedYoutube.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
/* Magic Mirror
* Module: Embed Youtube
*
* v 1.4.0
*
* By Nitipoom Unrrom (aka nitpum) https://nitpum.com
* MIT Licensed.
*/
Module.register("MMM-EmbedYoutube", {
defaults: {
autoplay: false,
cc_load_policy: false,
color: "red",
controls : true,
disablekb: false,
fs: true,
height: 315,
width: 560,
loop: false,
modestbranding: false,
rel : false,
showinfo : false,
video_id : "",
playlist: "",
video_list: []
},
getDom: function () {
var wrapper = document.createElement("div");
// Parameter
var params = "";
var videoList = "";
if (this.config.video_list && this.config.video_list.length > 0) {
videoList = "&playlist=";
for (var i = 0; i < this.config.video_list.length; i++) {
videoList += this.config.video_list[i];
if (i + 1 < this.config.video_list.length)
videoList += ",";
}
}
params += (this.config.autoplay) ? "autoplay=1" : "autoplay=0";
params += (this.config.cc_load_policy) ? "&cc_load_policy=1" : "&cc_load_policy=0";
params += (typeof this.config.color !== "undefined" && this.config.color != "red")? "&color=" + this.config.color:"";
params += (this.config.controls)? "&controls=1":"&controls=0";
params += (this.config.disablekb)? "&disablekb=1":"";
params += (this.config.fs)? "":"&fs=0";
params += (videoList != "" && (typeof this.config.playlist === "undefined" || this.config.playlist == "")) ? videoList : "&playlist=" + this.config.video_id; // required playlist to loopable
params += (this.config.loop) ? "&loop=1" : "";
params += (this.config.modestbranding) ? "&modestbranding=1" : "";
params += (this.config.rel)? "&rel=1": "&rel=0";
params += (this.config.showinfo)? "&showinfo=1": "&showinfo=0";
var videoId = this.config.video_id +"?version=3";
if (typeof this.config.playlist !== "undefined" && this.config.playlist != "")
videoId = "playlist?list=" + this.config.playlist + "&";
wrapper.innerHTML = "<iframe width=\"" + this.config.width +"\" height=\"" + this.config.height + "\" src=\"https://www.youtube.com/embed/" + videoId + "&"+ params +"\" frameborder=\"0\" allowfullscreen></iframe>";
return wrapper;
}
});