-
Notifications
You must be signed in to change notification settings - Fork 0
/
sctript.js
71 lines (60 loc) · 2.44 KB
/
sctript.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
'use strict';
;(function () {
var ESC_KEYCODE = 27;
var modalLogin = document.querySelector('.modal-login');
var modalMap = document.querySelector('.modal-map');
var modalOverlay = document.querySelector('.modal-overlay');
var loginButton = document.querySelector('.login-link');
var mapButtons = document.querySelectorAll('a[href="map.html"]');
var loginInput = document.querySelector('#user-login');
var loginPassword = document.querySelector('#user-password');
var modalCloseLogin = document.querySelector('.modal-close-login');
var modalCloseMap = document.querySelector('.modal-close-map');
var closeLoginPopup = function () {
modalLogin.classList.remove('show-modal');
modalOverlay.classList.remove('show-modal');
document.removeEventListener('keydown', onLoginPressEsc);
};
var closeMapPopup = function () {
modalMap.classList.remove('show-modal');
modalOverlay.classList.remove('show-modal');
document.removeEventListener('keydown', onMapPressEsc);
};
var onLoginPressEsc = function (event) {
if (event.keyCode === ESC_KEYCODE && loginInput !== document.activeElement && loginPassword !== document.activeElement) {
closeLoginPopup();
}
};
var onMapPressEsc = function (event) {
if (event.keyCode === ESC_KEYCODE) {
closeMapPopup();
}
};
loginButton.addEventListener('click', function () {
event.preventDefault();
modalLogin.classList.add('show-modal');
modalOverlay.classList.add('show-modal');
modalCloseLogin.addEventListener('click', function () {
closeLoginPopup();
});
modalOverlay.addEventListener('click', function () {
closeLoginPopup();
});
document.addEventListener('keydown', onLoginPressEsc);
});
mapButtons.forEach(function (currentMapButton) {
currentMapButton.addEventListener('click', function () {
event.preventDefault();
modalMap.classList.add('show-modal');
modalOverlay.classList.add('show-modal');
modalCloseMap.addEventListener('click', function () {
closeMapPopup();
});
modalOverlay.addEventListener('click', function () {
closeMapPopup();
});
document.addEventListener('keydown', onMapPressEsc);
});
});
window.main
})();