-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
140 lines (115 loc) · 4.27 KB
/
script.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
function $(id) {
return document.getElementById(id);
}
let oldScroll = 0
function reveal() {
let isDown = oldScroll < this.scrollY;
oldScroll = this.scrollY;
var reveals = document.querySelectorAll('.reveal');
for (var i = 0; i < reveals.length; i++) {
var windowHeight = window.innerHeight;
var elementTop = reveals[i].getBoundingClientRect().top;
var elementVisible = 50;
if (isDown && elementTop < windowHeight - elementVisible) {
reveals[i].classList.add('active');
} else if (!isDown && elementTop > windowHeight - elementVisible * 2.5) {
reveals[i].classList.remove('active');
}
}
}
window.addEventListener('scroll', reveal);
function setup() {
function dropdownHandler(event) {
if ($('topnav').classList.contains('responsive') && event.type !== 'click') {
return
}
var dropdowns = document.getElementsByClassName('dropdown-content');
for (var i = dropdowns.length - 1; i >= 0; i--) {
dropdowns[i].classList.add('hidden');
}
if (event.type === 'mouseleave') {
return;
}
var el = $('dropdown-' + (event.type === 'click' ? event.target.parentElement : event.target).getAttribute('data-dropdown'));
if (el) {
el.classList.remove('hidden');
}
}
var dropdowns = document.getElementsByClassName('dropdown')
for (var i = 0; i < dropdowns.length; i++) {
var dropdown = dropdowns[i]
dropdown.addEventListener('click', dropdownHandler);
dropdown.addEventListener('mouseenter', dropdownHandler);
dropdown.addEventListener('mouseleave', dropdownHandler);
}
setTimeout(function () {
var el;
if (el = $('zatvor')) {
el.style.display = 'none';
}
}, 10000);
var imgs = document.getElementsByClassName('galeria');
if (imgs.length > 0) {
window.fullscreenViewer = {
currentImage: -1,
imgs: imgs
}
fullscreenViewer.div = document.createElement('div');
fullscreenViewer.div.setAttribute('id', 'fullscreen-viewer');
var obrazok = document.createElement('img');
var popis = document.createElement('span');
var close = document.createElement('span');
var previous = document.createElement('span');
var next = document.createElement('span');
close.innerHTML = '×';
close.setAttribute('class', 'fullscreen-viewer-close');
popis.setAttribute('class', 'fullscreen-viewer-description');
obrazok.setAttribute('class', 'fullscreen-viewer-image fullscreen-viewer-no-close');
previous.setAttribute('class', 'fullscreen-viewer-previous fullscreen-viewer-no-close');
next.setAttribute('class', 'fullscreen-viewer-next fullscreen-viewer-no-close');
fullscreenViewer.div.addEventListener('click', function (e) {
if (!e.target.classList.contains('fullscreen-viewer-no-close')) {
document.body.classList.remove('fullscreen-viewer-active');
}
});
for (let i = 0; i < imgs.length; i++) {
imgs[i].addEventListener('click', function () {
console.log('test');
fullscreenViewer.currentImage = i;
obrazok.src = '';
//next
previous.onclick = function () {
if (fullscreenViewer.currentImage > 0) {
fullscreenViewer.imgs[fullscreenViewer.currentImage - 1].click()
}
}
next.onclick = function () {
if (fullscreenViewer.currentImage < fullscreenViewer.imgs.length - 1) {
fullscreenViewer.imgs[fullscreenViewer.currentImage + 1].click()
}
}
obrazok.src = this.hasAttribute('data-src') ? this.getAttribute('data-src') : this.getAttribute('src');
var _popis = this.getAttribute('data-popis');
if (_popis && _popis !== '') {
popis.innerHTML = _popis
popis.style.display = null;
} else {
popis.style.display = 'none'
}
document.body.classList.add('fullscreen-viewer-active');
return false
})
}
fullscreenViewer.div.appendChild(obrazok);
fullscreenViewer.div.appendChild(popis);
fullscreenViewer.div.appendChild(close);
fullscreenViewer.div.appendChild(previous);
fullscreenViewer.div.appendChild(next);
document.body.appendChild(fullscreenViewer.div);
}
}
if (document.readyState !== 'loading') {
setup()
} else {
document.addEventListener('DOMContentLoaded', setup);
}