-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMMT-Modal.js
112 lines (90 loc) · 2.35 KB
/
MMMT-Modal.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Module.register("MMMT-Modal",{
url: "",
youtube: "",
// Default module config.
defaults: {
animationSpeed: 1000,
},
// Define required styles
getStyles: function() {
return [
'MMMT-Modal.css' // this file will be loaded from the bootstrapcdn servers.
]
},
// Define required scripts.
getScripts: function() {
return [
"moment.js",
];
},
start: function() {
this.hide(this.config.animationSpeed);
},
// Override dom generator.
getDom: function() {
//Only create the modal if nessesary
if (this.url != "" || this.youtube != "")
{
var wrapper = document.createElement("div");
// Creates the modal without content
var modal = document.createElement("div");
modal.className = "modal";
modal.id = "myModal";
var modalContent = document.createElement("div");
modalContent.className = "modal-content";
modal.appendChild(modalContent);
var closeButton = document.createElement("span");
closeButton.className = "close";
closeButton.innerHTML = "×";
modalContent.appendChild(closeButton);
var self = this;
closeButton.addEventListener("click", function () {
self.hide(self.config.animationSpeed,function () {
self.url = "";
self.updateDom();
});
});
modalContent.appendChild(closeButton);
// Creates the content
if (this.url != "")
{
var iframe = document.createElement("iframe");
iframe.className = "iframe";
iframe.height = "100%";
iframe.width = "100%";
iframe.src = this.url;
modalContent.appendChild(iframe);
window.onclick = function(event) {
if (event.target == modal) {
self.hide(self.config.animationSpeed,function () {
self.url = "";
self.updateDom();
});
}
};
}
else if (this.youtube != "")
{
}
else
{
return document.createElement("div");
}
modal.appendChild(modalContent);
modal.style.display = "block";
wrapper.appendChild(modal);
return wrapper;
}
return document.createElement("div");
},
// Override the default NotificationRecieved function
notificationReceived: function (notification, payload, sender) {
if (notification === "OPEN_URL") {
var self = this;
this.show(this.config.animationSpeed,function () {
self.url = payload;
self.updateDom();
});
}
},
});