-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodal.js
More file actions
60 lines (58 loc) · 1.83 KB
/
Copy pathmodal.js
File metadata and controls
60 lines (58 loc) · 1.83 KB
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
//modal component
var pgModal = {
onconnected: function () {
window.addEventListener('statechange', this);
this.addClose();
},
onattributechanged: function (event) {
if (event.attributeName == "isopen" && event.oldValue != event.newValue) {
this.toggleModal();
}
},
onstatechange: function (e) {
if (e.detail.newState.dialogOpen) {
if ((e.detail.newState.dialogOpen) == "true") {
this.el.setAttribute('isopen', 'true');
}
else {
this.el.setAttribute('isopen', 'false');
}
}
},
onOpen: function () {
var openEvent = new CustomEvent('onOpen');
this.el.dispatchEvent(openEvent);
},
onClose: function () {
var closeEvent = new CustomEvent('onClose');
this.el.dispatchEvent(closeEvent);
},
toggleModal: function () {
if (""+this.el.getAttribute('isopen') == "true") {
$(this.el).fadeIn();
if (app.state.dialogOpen != "true") {
app.updateState({ dialogOpen: "true" });
}
this.onOpen();
}
else {
$(this.el).fadeOut();
if (app.state.dialogOpen != "false") {
app.updateState({ dialogOpen: "false" });
}
this.onClose();
}
},
addClose: function () {
var self = this;
var closeEle = document.createElement('span');
closeEle.classList.add('close');
closeEle.innerHTML = "×";
var modalHeader = this.el.querySelector('.pg-modal-header');
modalHeader.appendChild(closeEle);
modalHeader.addEventListener('click', function () {
self.el.setAttribute('isopen', 'false');
});
}
};
wickedElements.define('.pg-modal', pgModal);