forked from urfu-2017/markup-task-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.js
35 lines (25 loc) · 1004 Bytes
/
global.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
(function (window, document) {
var n = window.location.href.match(/(\d+)\.html/)[1];
var count = 20;
var next = +n + 1;
var prev = +n - 1;
document.querySelector('.global-heading').innerHTML = 'Задача №' + n;
var prevHref = (next > count ? 1 : next) + '.html';
var nextHref = (prev < 1 ? count : prev) + '.html';
document.querySelector('.global-next').href = prevHref;
document.querySelector('.global-prev').href = nextHref;
document.querySelector('.global-scope').classList.add('global-scope_' + n);
var goal = document.querySelector('.global-goal');
goal.src = '../goals/' + n + '.png';
goal.alt = 'Цель ' + n;
window.addEventListener('keydown', function (event) {
switch (event.keyCode) {
case 37:
window.location.href = nextHref;
break;
case 39:
window.location.href = prevHref;
break;
}
});
})(window, document);