-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcenter-pop-up.js
40 lines (33 loc) · 1.16 KB
/
center-pop-up.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
'use-strict';
function CenterPopup(content) {
Popup.call(this, content);
this.element = this.createPopup();
this.fadeCenterPopup = CenterPopup.prototype.fadeCenterPopup.bind(this);
}
CenterPopup.prototype = Object.create(Popup.prototype);
CenterPopup.prototype.show = function(node) {
Popup.prototype.show.call(this, node);
window.addEventListener("click", this.fadeCenterPopup);
};
CenterPopup.prototype.hide = function() {
Popup.prototype.hide.call(this);
window.removeEventListener("click", this.fadeCenterPopup);
};
CenterPopup.prototype.fadeCenterPopup = function(event) {
if(event) {
if (event.target === this.element) {
this.hide();
}
}
};
CenterPopup.prototype.createPopup = function() {
var centerPopup = document.createElement('div');
centerPopup.classList.add('modal');
var centerPopupContent = document.createElement('div');
centerPopupContent.classList.add('modalWindowContent');
var paragraph = document.createElement('p');
paragraph.innerText = this.content;
centerPopupContent.appendChild(paragraph);
centerPopup.appendChild(centerPopupContent);
return centerPopup;
};