-
Notifications
You must be signed in to change notification settings - Fork 1
/
block-js.min.js
209 lines (201 loc) · 8.88 KB
/
block-js.min.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
window.isMobile = !1;
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
window.isMobile = !0
}
function t450_showMenu(recid) {
var rec = document.getElementById('rec' + recid);
if (!rec) return;
var menu = rec.querySelector('.t450');
var overlay = rec.querySelector('.t450__overlay');
var menuElements = rec.querySelectorAll('.t450__overlay, .t450__close, a[href*="#"]');
if (typeof t_triggerEvent === 'function') t_triggerEvent(document.body, 'popupShowed');
document.body.classList.add('t450__body_menushowed');
if (menu) menu.classList.add('t450__menu_show');
if (overlay) overlay.classList.add('t450__menu_show');
if (menu) {
menu.addEventListener('clickedAnchorInTooltipMenu', function() {
t450_closeMenu(menu, overlay)
})
}
Array.prototype.forEach.call(menuElements, function(element) {
element.addEventListener('click', function() {
if (element.closest('.tooltipstered, .t-menusub__target-link, .t794__tm-link, .t966__tm-link, .t978__tm-link')) return;
if (element.href && (element.href.substring(0, 7) === '#price:' || element.href.substring(0, 9) === '#submenu:')) return;
t450_closeMenu(menu, overlay)
})
});
document.addEventListener('keydown', function(e) {
if (e.keyCode === 27) {
document.body.classList.remove('t390__body_popupshowed');
var popups = document.querySelectorAll('.t390');
Array.prototype.forEach.call(popups, function(popup) {
popup.classList.remove('t390__popup_show')
})
}
});
rec.addEventListener('click', function(e) {
if (e.target.closest('.t966__tm-link, .t978__tm-link')) {
t450_checkSize(recid);
if (e.target.closest('.t978__tm-link')) {
setTimeout(function() {
var hookLink = e.target.closest('.t978__tm-link');
var menuBlock = hookLink.nextElementSibling;
var submenuLinks = menuBlock ? menuBlock.querySelectorAll('.t978__menu-link') : [];
Array.prototype.forEach.call(submenuLinks, function(link) {
link.addEventListener('click', function() {
t450_checkSize(recid)
})
})
}, 300)
}
}
});
menu.addEventListener('menuOverflow', function() {
t450_checkSize(recid)
});
t450_highlight(recid)
}
function t450_closeMenu(menu, overlay) {
if (typeof t_triggerEvent === 'function') t_triggerEvent(document.body, 'popupHidden');
document.body.classList.remove('t450__body_menushowed');
if (menu) menu.classList.remove('t450__menu_show');
if (overlay) overlay.classList.remove('t450__menu_show')
}
function t450_checkSize(recid) {
var rec = document.getElementById('rec' + recid);
var menu = rec ? rec.querySelector('.t450') : null;
if (!menu) return;
var container = menu.querySelector('.t450__container');
var topContainer = menu.querySelector('.t450__top');
var rightContainer = menu.querySelector('.t450__rightside');
setTimeout(function() {
var topContainerHeight = topContainer ? topContainer.offsetHeight : 0;
var rightContainerHeight = rightContainer ? rightContainer.offsetHeight : 0;
var containerPaddingTop = container ? window.getComputedStyle(container).paddingTop : '0';
var containerPaddingBottom = container ? window.getComputedStyle(container).paddingBottom : '0';
containerPaddingTop = parseInt(containerPaddingTop, 10);
containerPaddingBottom = parseInt(containerPaddingBottom, 10);
if (topContainerHeight + rightContainerHeight + containerPaddingTop + containerPaddingBottom > document.documentElement.clientHeight) {
menu.classList.add('t450__overflowed')
} else {
menu.classList.remove('t450__overflowed')
}
})
}
function t450_appearMenu(recid) {
var rec = document.getElementById('rec' + recid);
var burger = rec ? rec.querySelector('.t450__menu__content') : null;
if (!burger) return;
var burgerAppearOffset = burger ? burger.getAttribute('data-appearoffset') : '';
var burgerHideOffset = burger ? burger.getAttribute('data-hideoffset') : '';
if (burgerAppearOffset) {
burgerAppearOffset = t450_appearMenuParseNumber(burgerAppearOffset);
if (window.pageYOffset >= burgerAppearOffset) {
if (burger.classList.contains('t450__beforeready')) {
burger.classList.remove('t450__beforeready')
}
} else {
burger.classList.add('t450__beforeready')
}
}
if (burgerHideOffset) {
burgerHideOffset = t450_appearMenuParseNumber(burgerHideOffset);
var scrollHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight);
if (window.pageYOffset + window.innerHeight >= scrollHeight - burgerHideOffset) {
if (!burger.classList.contains('t450__beforeready')) {
burger.classList.add('t450__beforeready')
}
} else if (burgerAppearOffset) {
if (window.pageYOffset >= burgerAppearOffset) {
burger.classList.remove('t450__beforeready')
}
} else {
burger.classList.remove('t450__beforeready')
}
}
}
function t450_appearMenuParseNumber(string) {
if (string.indexOf('vh') > -1) {
string = Math.floor((window.innerHeight * (parseInt(string) / 100)))
}
return parseInt(string, 10)
}
function t450_initMenu(recid) {
var rec = document.getElementById('rec' + recid);
var menu = rec ? rec.querySelector('.t450') : null;
var overlay = rec ? rec.querySelector('.t450__overlay') : null;
var burger = rec ? rec.querySelector('.t450__burger_container') : null;
var menuLinks = rec ? rec.querySelectorAll('.t-menu__link-item.t450__link-item_submenu') : [];
var hook = menu ? menu.getAttribute('data-tooltip-hook') : '';
if (hook) {
document.addEventListener('click', function(e) {
if (e.target.closest('a[href="' + hook + '"]')) {
e.preventDefault();
t450_closeMenu(menu, overlay);
t450_showMenu(recid);
t450_checkSize(recid)
}
})
}
if (burger) {
burger.addEventListener('click', function() {
t450_closeMenu(menu, overlay);
t450_showMenu(recid);
t450_checkSize(recid)
})
}
window.addEventListener('resize', function() {
t450_checkSize(recid)
});
if (!window.isMobile) return;
Array.prototype.forEach.call(menuLinks, function(link) {
link.addEventListener('click', function() {
t450_checkSize(recid)
})
})
}
function t450_highlight(recid) {
var url = window.location.href;
var pathname = window.location.pathname;
var hash = window.location.hash;
if (url.substr(url.length - 1) === '/') {
url = url.slice(0, -1)
}
if (pathname.substr(pathname.length - 1) === '/') {
pathname = pathname.slice(0, -1)
}
if (pathname.charAt(0) === '/') {
pathname = pathname.slice(1)
}
if (pathname === '') {
pathname = '/'
}
var shouldBeActiveElements = document.querySelectorAll('.t450__menu a[href=\'' + url + '\'], ' + '.t450__menu a[href=\'' + url + '/\'], ' + '.t450__menu a[href=\'' + pathname + '\'], ' + '.t450__menu a[href=\'/' + pathname + '\'], ' + '.t450__menu a[href=\'' + pathname + '/\'], ' + '.t450__menu a[href=\'/' + pathname + '/\']' + (hash ? ', .t450__menu a[href=\'' + hash + '\']' : ''));
var rec = document.getElementById('rec' + recid);
var menuLinks = rec ? rec.querySelectorAll('.t450__menu a') : [];
Array.prototype.forEach.call(menuLinks, function(link) {
if (link.getAttribute('data-highlighted-by-user') !== 'y') link.classList.remove('t-active')
});
Array.prototype.forEach.call(shouldBeActiveElements, function(link) {
link.classList.add('t-active')
})
}
function t674_init(recid) {
var rec = document.getElementById('rec' + recid);
if (!rec) return;
var backgroundImage = rec.querySelector('.t674__img-holder');
if (!backgroundImage) return;
backgroundImage.onload = function() {
var delay = 0;
var allRecords = document.getElementById('allrecords');
if (allRecords.getAttribute('data-blocks-animationoff') !== 'yes') {
delay = 600
}
setTimeout(function() {
document.body.classList.add('t674__body_with-bg')
}, delay)
};
var event = document.createEvent('HTMLEvents');
event.initEvent('load', !0, !1);
backgroundImage.dispatchEvent(event)
}