-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
48 lines (35 loc) · 1.43 KB
/
popup.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
'use strict';
var smq = {
Popup: function(config) {
this.conf = config || {};
this.init = function() {
var conf = config || {};
//if there are <smq-popup>, remove nodes
var existingNodes = document.getElementsByTagName("smq-popup");
if(existingNodes && existingNodes.length > 0) {
for(var i = 0; i<existingNodes.length; i++) {
document.body.removeChild(existingNodes[i]);
}
}
//create popup nodes
this.nodePopup = document.createElement("smq-popup");
this.nodePopup.innerHTML = '<div class="window"><a class="close">x</a class="close"><header class="api-header"><h1 class="api-title"></h1></header><div class="api-content"></div></div>';
this.nodePopup.getElementsByClassName("api-title")[0].innerHTML = this.conf.title || "";
this.nodePopup.getElementsByClassName("api-content")[0].innerHTML = this.conf.innerHtml || "";
//click "x" button to close popup window
this.nodeClose = this.nodePopup.getElementsByClassName("close")[0];
this.nodeClose.addEventListener("click", function() {
this.close();
}.bind(this), false);
};
this.show = function() {
//insert nodePopup in body
document.body.appendChild(this.nodePopup);
};
this.close = function() {
this.nodePopup ? document.body.removeChild(this.nodePopup) : null;
this.nodePopup = undefined;
};
this.init(config);
}
};