1/*jslint browser: true, white: true, plusplus: true, regexp: true, indent: 4, maxerr: 50, es5: true */ 2/*jshint multistr: true, latedef: nofunc */ 3/*global jQuery, $, Swiper*/ 4 5 6// control :focus when using mouse/keyboard 7document.body.addEventListener('mousedown', function () { 8 document.body.classList.add('is_using_mouse'); 9}); 10document.body.addEventListener('keydown', function () { 11 document.body.classList.remove('is_using_mouse'); 12}); 13 14 15$(document).ready(function () { 16 'use strict'; 17 18 // variables 19 const body = $('body'); 20 const header = $('header'); 21 const menu__toggle = $('.menu__toggle.is_main_toggle'); 22 const menu__primary = $('.menu__burger'); 23 const menu__toggle__inner = menu__primary.find('.menu__toggle'); 24 25 const accordion = $('.menu__burger_list > .menu-item-has-children'); 26 accordion.addClass('menu-item-parent'); 27 const menu__a_parent = menu__primary.find('.menu-item-parent > a'); 28 const navPrimaryList = $('.menu__burger_primary_list'); 29 30 31 // reusable change nav posisition and height function for burger menu 32 const navPrimaryPosition = (parent) => { 33 navPrimaryList.animate( 34 {top: `${parseInt(parent.css('top').match(/\d+/)[0]) + parent.height() + 50 + 'px'}`}, 35 {duration: 'fast', easing: 'linear'} 36 ); 37 38 } 39 const navPrimaryHeight = () => { 40 const height = (navPrimaryList.height() * 2) - 20; 41 navPrimaryList.css({ 42 'height': height + 'px', 43 }) 44 } 45 46 //check if sub menu needs to have custom scroll 47 const checkIfMoreThan = (parent, count = 0) => { 48 if (parent.children('li').length <= count) { 49 parent.css({'height': 'auto', 'padding-bottom': '50px'}); 50 menu__primary.addClass('height-auto'); 51 } else { 52 menu__primary.removeClass('height-auto'); 53 } 54 } 55 56 //reusable change of burger list position for burger menu 57 58 const burgerNavPosition = (parent, largeScreen, largeScreenGap = 0, smallScreen, smallScreenGap = 0) => { 59 if ($(window).width() >= 768) { 60 parent 61 .css('top', largeScreen + parent.parent().children('.menu-item-description').outerHeight() + largeScreenGap + "px"); 62 } else { 63 parent 64 .css('top', smallScreen + parent.parent().children('.menu-item-description').outerHeight() + smallScreenGap + "px"); 65 } 66 67 } 68 69 70 $(".menu-item-has-children").each(function () { 71 if ($(this).find("> .i_arrow_down").length === 0) { 72 $(this).append('<a href="javascript:;" class="i_arrow_down" tabindex="-1" aria-hidden="true"></a>'); 73 } 74 }); 75 76 $(document).on("click", ".i_arrow_down", function (e) { 77 e.preventDefault(); 78 let parentLi = $(this).closest(".menu-item-has-children"); 79 parentLi.toggleClass("is_focused"); 80 }); 81 82 // Sets focus trap on menu 83 function handleMenuFocusTrap() { 84 var focusableElements = menu__primary.find( 85 'a:visible, button:visible, input:visible, select:visible, textarea:visible, [tabindex]:not([tabindex="-1"]):visible' 86 ); 87 88 if (focusableElements.length === 0) return; 89 90 var lastFocusable = focusableElements.last(); 91 92 lastFocusable.off('keydown.menuClose').on('keydown.menuClose', function (e) { 93 if (e.key === 'Tab' && !e.shiftKey) { 94 e.preventDefault(); 95 closeMenu(); 96 menu__toggle.focus(); 97 } 98 }); 99 } 100 101 // Closes menu and resets ARIA 102 function closeMenu() { 103 menu__primary.removeClass('is_open'); 104 body.removeClass('is_overflow'); 105 106 menu__toggle.attr({ 107 'aria-expanded': false, 108 'aria-label': 'Open the menu' 109 }); 110 111 menu__primary.attr("aria-hidden", true); 112 113 menu__primary.find('a, button, input, select, textarea, [tabindex]').off('keydown.menuClose'); 114 } 115 116 // Burger toggle button 117 menu__toggle.on('click', function () { 118 menu__primary.stop().toggleClass('is_open'); 119 body.toggleClass('is_overflow'); 120 121 var isOpen = menu__primary.hasClass('is_open'); 122 123 menu__toggle.attr({ 124 'aria-expanded': isOpen, 125 'aria-label': isOpen ? 'Close the menu' : 'Open the menu', 126 'aria-controls': menu__primary.attr('id') 127 }); 128 129 menu__primary.attr("aria-hidden", !isOpen); 130 131 if (isOpen) { 132 setTimeout(function () { 133 var firstFocusable = menu__primary.find( 134 'a:visible, button:visible, input:visible, select:visible, textarea:visible, [tabindex]:not
134([tabindex="-1"]):visible' 135 ).first(); 136 137 if (firstFocusable.length) { 138 firstFocusable.focus(); 139 } 140 141 // ÐодаÑмо обÑÐ¾Ð±ÐºÑ ÑабÑÐ²Ð°Ð½Ð½Ñ 142 handleMenuFocusTrap(); 143 }, 0); 144 } else { 145 closeMenu(); 146 } 147 }); 148 149 // Close burger menu if click target not menu__primary 150 function handleClickOutside() { 151 $(document).on('click.menuOutside', function (e) { 152 var isOpen = menu__primary.hasClass('is_open'); 153 154 if (isOpen) { 155 // ÐеÑевÑÑÑÑмо Ñи клÑк бÑв поза menu__primary Ñ Ð¿Ð¾Ð·Ð° menu__toggle 156 var isClickOutside = !menu__primary.is(e.target) && 157 menu__primary.has(e.target).length === 0 && 158 !menu__toggle.is(e.target) && 159 menu__toggle.has(e.target).length === 0; 160 161 if (isClickOutside) { 162 closeMenu(); 163 } 164 } 165 }); 166 } 167 168 handleClickOutside(); 169 170 menu__toggle.one('click', function () { 171 navPrimaryHeight(); 172 }) 173 menu__toggle__inner.on('click', function () { 174 menu__primary.stop().toggleClass('is_open'); 175 body.removeClass('is_overflow'); 176 $('.menu__burger .menu-item-has-children.is_focused').removeClass('is_focused'); 177 }); 178 // close menu with Esc key 179 body.on('keyup', function (e) { 180 if (e.keyCode === 27) { 181 $('.menu__burger .menu__toggle').click(); 182 // menu__primary.stop().toggleClass('is_open'); 183 body.addClass('is_overflow'); 184 $('.menu__burger .menu-item-parent.is_focused').removeClass('is_focused'); 185 // prevent default for top links 186 const nav__links = $('.menu__burger_list > .menu-item-parent > a'); 187 nav__links.each(function () { 188 $(this).on('click', function (ev) { 189 ev.preventDefault() 190 }); 191 }); 192 193 const menu_lvl0 = $('.menu__burger_list .menu-item-parent.is_focused .level-0'); 194 //change top nav position 195 burgerNavPosition(menu_lvl0, 210, 64, 170) 196 navPrimaryPosition(menu_lvl0) 197 // smooth submenu open 198 const subAccordion = $('.menu__burger_list .menu-item-parent.is_focused .level-1'); 199 200 // append arrow 201 if ($('.menu__burger_list .menu-item-parent.is_focused .level-0 .menu-item-has-children:has(.submenu_arrow)').length === 0) { 202 subAccordion.before('<span class="arrow_golden submenu_arrow" tabindex="0" role="button" aria-label="Sub-menu toggle" aria-expanded="false" />'); 203 } 204 205 //on arrow click 206 $('.submenu_arrow').each(function () { 207 $(this).unbind('click').click(function () { 208 const parent = $(this).parent(); 209 $(this).toggleClass('active'); 210 $(parent).toggleClass('active'); 211 parent.children('.level-1').slideToggle({ 212 duration: 250, 213 start: function () { 214 if ($(this).is(':visible')) { 215 // $(this).stop(); 216 navPrimaryPosition(menu_lvl0); 217 $(this).css('display', 'flex').css('flex-direction', 'column'); 218 } 219 }, 220 complete: function () { 221 navPrimaryPosition(menu_lvl0); 222 }, 223 }).toggleClass('active'); 224 }); 225 $(this).unbind('keypress').on('keypress', function (ev) { 226 const parent = $(this).parent(); 227 if (ev.which == 13) { 228 const parent = $(this).parent(); 229 $(this).toggleClass('active'); 230 $(parent).toggleClass('active'); 231 parent.children('.level-1').slideToggle({ 232 duration: 250, 233 start: function () { 234 if ($(this).is(':visible')) { 235 navPrimaryPosition(menu_lvl0); 236 $(this).css('display', 'flex').css('flex-direction', 'column'); 237 } 238 }, 239 complete: function () { 240 navPrimaryPosition(menu_lvl0); 241 }, 242 }).toggleClass('active'); 243 244 } 245 }); 246 }); 247 // $('a[href="#skip_to_content"]').focus(); 248 } 249 });
250 251 // open/close sub-menu with Tab key 252 menu__a_parent.on('focus', function () { 253 $('.menu__burger .menu-item-has-children.is_focused').removeClass('is_focused'); 254 255 $(this).parent().addClass('is_focused'); 256 257 const menu_lvl0 = $(this).parent().children('.level-0'); 258 checkIfMoreThan(menu_lvl0, 7); 259 //change top nav position 260 burgerNavPosition(menu_lvl0, 210, 40, 160) 261 navPrimaryPosition(menu_lvl0) 262 263 }).on('click', function () { 264 $('.menu__burger .menu-item-has-children.is_focused').removeClass('is_focused'); 265 $(this).parent().addClass('is_focused'); 266 const menu_lvl0 = $(this).parent().children('.level-0'); 267 burgerNavPosition(menu_lvl0, 210, 40, 160); 268 navPrimaryPosition(menu_lvl0); 269 }); 270 271 // $(window).on('resize', function(){ 272 // if ($(window).resize().width() > 1280) { 273 // $(window).scroll(() => { 274 // const asideMenuLimit = (parent) => { 275 // asideMenu.appendTo(parent); 276 // $(window).scrollTop() > parent.height() ? 277 // asideMenu.css({'position': 'absolute', 'top': parent.height() - 200 + 'px'}) : 278 // asideMenu.css({'position': 'fixed', 'top': '320px'}) 279 // } 280 // 281 // asideMenuLimit($('#page')) 282 // }); 283 // } else { 284 // asideMenu.appendTo('#main'); 285 // } 286 // }); 287 288 // header 289 $(window).on('scroll', function () { 290 if ($(this).scrollTop() > 5) { 291 header.addClass('is_sticky'); 292 } else { 293 header.removeClass('is_sticky'); 294 } 295 }); 296 if ($(this).scrollTop() > 4) header.addClass('is_sticky'); 297 298 299 // contact form 7 300 $(this).on('click', '.wpcf7-not-valid-tip', function () { 301 $(this).prev().trigger('focus'); 302 $(this).fadeOut(250, function () { 303 $(this).remove(); 304 }); 305 $(this).parents('.wpcf7-form').find('.wpcf7-response-output').addClass('is_temp_hidden'); 306 }); 307 $(this).on('focus', '.wpcf7-form-control.wpcf7-not-valid', function () { 308 $(this).next('.wpcf7-not-valid-tip').fadeOut(250, function () { 309 $(this).remove(); 310 }); 311 $(this).parents('.wpcf7-form').find('.wpcf7-response-output').addClass('is_temp_hidden'); 312 }); 313 document.addEventListener('wpcf7submit', function (event) { 314 $('.wpcf7-response-output').removeClass('is_temp_hidden'); 315 }, false); 316 317 318 // custom select 319 if ($('select').length > 0) { 320 $('select').selectric({ 321 disableOnMobile: false, 322 nativeOnMobile: false, 323 arrowButtonMarkup: '<span class="select_arrow"></span>' 324 }); 325 // $('select.wpcf7-form-control').each(function () { 326 // $(this).find('option').first().val(''); 327 // }); 328 } 329 330 const fancybox_args = { 331 touch: { 332 vertical: false, 333 momentum: true 334 }, 335 smallBtn: false, 336 beforeLoad: function (instance, slide) { 337 // fix if header is sticky 338 header.addClass('compensate-for-scrollbar'); 339 }, 340 afterClose: function (instance, slide) { 341 // fix if header is sticky 342 header.removeClass('compensate-for-scrollbar'); 343 // remove body class after event 344 if (body.hasClass('is_searching')) { 345 body.removeClass('is_searching'); 346 } 347 } 348 }; 349 350 // fancybox 351 $('[data-fancybox]').fancybox({ 352 ...fancybox_args 353 }); 354 355 // add body class on event 356 $('a[data-src="#search_field"]').on('click', function () { 357 body.addClass('is_searching'); 358 }); 359 360 361 // animations 362 // AOS.init({ 363 // disable: true, 364 // disable: 'mobile', 365 // once: true, 366 // offset: 150, 367 // duration: 600, 368 // easing: 'ease-in-out' 369 // }); 370 371 372 // scroll to 373 $('a[data-scrollto]').on('click', function () { 374 let anchor = $(this).data('scrollto'); 375 376 if ($(anchor).length > 0) { 377 $('html, body').animate({ 378 scrollTop: $(anchor).offset().top - header.outerHeight() 379 }, 700); 380 } 381 });
382 383 384 // block - accordion 385 function acc_action(elem) { 386 let exp = elem.attr('aria-expanded'); 387 let hid = elem.next().attr('aria-hidden'); 388 (exp === 'false') ? elem.attr('aria-expanded', 'true') : elem.attr('aria-expanded', 'false'); 389 (hid === 'true') ? elem.next().attr('aria-hidden', 'false') : elem.next().attr('aria-hidden', 'true'); 390 elem.toggleClass('is_open').next().toggle(); 391 elem.find('.circle_arrow').toggleClass('is_up').toggleClass('is_down'); 392 } 393 394 $('.acc_title').on('click', function () { 395 acc_action($(this)); 396 }).on('keyup', function (e) { 397 if (e.keyCode === 13) { 398 acc_action($(this)); 399 } 400 }); 401 402 403 // wrap tables for responsive design 404 if ($('.content table').length > 0) { 405 $('.content table').wrap('<div class="table_wrapper"></div>'); 406 } 407 408 //Clear empty container in a default_content 409 $('.container.is_8 .content').each(function () { 410 if ($(this).children().length === 0) { 411 $(this).parent().remove(); 412 } 413 }); 414 415}); 416 417// copy link 418const copyLink = (event) => { 419 const linkInput = event.target; 420 421 if (navigator.clipboard) { 422 // Use the modern Clipboard API to copy the text 423 navigator.clipboard.writeText(linkInput.value) 424 .then(() => { 425 // Find the existing copy message element, if it exists 426 let copyMessage = linkInput.nextElementSibling; 427 if (copyMessage && copyMessage.classList.contains("copy-message")) { 428 // Update the text inside the existing element 429 copyMessage.innerText = "Link copied to clipboard!"; 430 } else { 431 // Create a new copy message element and append it next to the input field 432 copyMessage = document.createElement("small"); 433 copyMessage.classList.add("copy-message"); 434 copyMessage.innerText = "Link copied to clipboard!"; 435 linkInput.insertAdjacentElement("afterend", copyMessage); 436 } 437 438 // Remove the message after a few seconds 439 setTimeout(() => { 440 copyMessage.remove(); 441 }, 2000); 442 }) 443 .catch((error) => { 444 console.error("Failed to copy text: ", error); 445 }); 446 } else { 447 // Fallback for browsers that don't support the Clipboard API 448 prompt("Copy the link below:", linkInput.value); 449 } 450}; 451 452// Get all the input elements with the "link-input" class 453const linkInputs = document.querySelectorAll(".link-input"); 454 455// Add the "copyLink" function as the click event listener for each input element 456linkInputs.forEach((linkInput) => { 457 linkInput.addEventListener("click", copyLink); 458}); 459 460 461// close on click outside 462// $(document).on('mouseup', function(e) { 463// let menu = $('.menu__primary'); 464// 465// if (!menu.is(e.target) && !$('.menu__toggle.is_active').is(e.target) && menu.has(e.target).length === 0 && menu.hasClass('is_open')) { 466// $('.menu__toggle.is_active').click(); 467// } 468// }); 469 470 471// proper resize event 472// $(window).resizeEnd(function() { 473// 'use strict'; 474// 475// });
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.