-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.js
36 lines (31 loc) · 1.07 KB
/
menu.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
var modal = {
modalHolder: document.getElementById('modalHolder'),
box: document.createElement('div'),
boxPhoto: document.createElement('img'),
closeButton: document.createElement('span'),
openModal: function(source) {
this.modalHolder.appendChild(this.box);
this.box.appendChild(this.boxPhoto);
this.box.appendChild(this.closeButton);
this.closeButton.textContent = 'x';
this.boxPhoto.src = source;
this.box.className = 'modal';
this.closeButton.className = 'closeButton';
this.modalHolder.className = 'modalHolder';
this.boxPhoto.className = 'boxPhoto';
this.closeButton.addEventListener('click', handlers.close);
},
closeModal: function() {
this.modalHolder.innerHTML = '';
this.modalHolder.className = '';
}
}
var handlers = {
open: function(n) {
var imageSource = document.getElementsByTagName('img')[n].src;
modal.openModal(imageSource);
},
close: function() {
modal.closeModal();
}
}