1/** 2 * Common JS for shared frontend functionality 3 * At the end of this file, there are calls to some functions to make it work immediately 4 */ 5const FrontendShared = { 6 setHalusky() { 7 if (!$("input[name='halusky2']").val()) { 8 $("input[name='halusky2']").val('8985676015'); 9 } 10 }, 11 12 setScrollbarWidth() { 13 globalShop.scrollbarWidth = window.innerWidth - document.documentElement.offsetWidth; 14 }, 15 16 prepareThankyouPage() { 17 // on thankyou page, preparations for cart page after order is placed 18 if (window.location.href.indexOf('/thankyou') > 0) { 19 if (localStorage.getItem('placed_order_address_saved') !== true) { 20 localStorage.removeItem('previous_address_loaded'); 21 localStorage.setItem('placed_order_address_saved', true); 22 FrontendShared.savedPlacedOrderAddress(); 23 } 24 25 // order placed 26 localStorage.placed_order = true; 27 } 28 }, 29 30 attachUniversalTooltips() { 31 if ($.fn.tooltip) { 32 $('[data-toggle="tooltip"]').tooltip(); 33 } 34 }, 35 36 preventImgDownload() { 37 if (globalShop.preventImgDownload) { 38 $('body').on('contextmenu', 'img', function(e) { 39 e.preventDefault(); 40 e.stopPropagation(); 41 return false; 42 }); 43 } 44 }, 45 46 makeStickyElements() { 47 let make_sticky = $(".make-sticky"); 48 let sticky_elements = []; 49 50 if (make_sticky.length > 0) { 51 var is_theme_kaufmart = (typeof globalShop.theme != 'undefined' && ['kaufmart'].includes(globalShop.theme)); 52 var is_theme_next = (typeof globalShop.theme != 'undefined' && ['next'].includes(globalShop.theme)); 53 var is_body_cart = $('body').hasClass('body-cart'); 54 55 var top_offset = 0; 56 for (var i = 0; i < make_sticky.length; i++) { 57 var $sticky = $(make_sticky[i]); 58 sticky_elements[i] = { 59 selector: make_sticky[i], 60 $selector: $sticky, 61 offsetTop: make_sticky[i].offsetTop, 62 height: $sticky.outerHeight(), 63 top: top_offset, 64 $placeholder: null 65 }; 66 67 top_offset += sticky_elements[i].height; 68 69 // next in cart => no menu => no placeholder 70 if (is_theme_next && is_body_cart) { 71 continue; 72 } 73 74 // put there a placeholder 75 var newHeight = $sticky.outerHeight(true); 76 $sticky.before('<div id="is-sticky-placeholder-' + i + '" style="height:' + newHeight + 'px;display:none"></div>'); 77 sticky_elements[i].$placeholder = $('#is-sticky-placeholder-' + i); 78 } 79 80 const applyStickyState = function() { 81 var $navbar_collapse = $('.navbar-collapse:not(.blog-navbar)'); 82 var navbar_is_visible = $navbar_collapse.is(':visible'); 83 var navbar_header_height = globalShop.theme != 'next' ? $('.navbar-header').outerHeight(true) : 0; 84 85 for (var i = 0; i < sticky_elements.length; i++) { 86 let $sticky_selector = sticky_elements[i].$selector; 87 88 // default - offsetTop of the element 89 let sticky_limit = sticky_elements[i].offsetTop; 90 if (is_theme_kaufmart) { 91 // kaufmart - sum of offsets 92 sticky_limit = top_offset + (is_body_cart ? 50 : 0); 93 } else if (globalShop.sticky_header && is_theme_next) { 94 // next & sticky (whole header) - 0 95 sticky_limit = 0; 96 } 97 98 if (window.scrollY > sticky_limit && !$sticky_selector.hasClass('is-sticky')) { 99 100 if (is_theme_kaufmart) { 101 // for kaufmart, we need to animate the showing of sticky header 102 $sticky_selector 103 .stop(true) 104 .css('opacity', 0) 105 .addClass('is-sticky') 106 .animate({ 107 opacity: 1 108 }, 600); 109 } else { 110 $sticky_selector.addClass('is-sticky'); 111 } 112 113 // "show" the placeholder 114 if (sticky_elements[i].$placeholder) { 115 sticky_elements[i].$placeholder.css('display', 'block'); 116 } 117 118 // set top position of the sticky element 119 $sticky_selector.css('top', sticky_elements[i].top); 120 121 // enable scrolling through the menu on the mobile resolution 122 if ($sticky_selector.is('#top-menu') && navbar_is_visible) { 123 $navbar_collapse.css('overflow', 'visible'); 124 125 if (globalShop.theme != 'next') { 126 $navbar_collapse.css('height', window.innerHeight - (sticky_elements[i].top + navbar_header_height)); 127 } 128 } 129 } else if (window.scrollY <= sticky_limit && $sticky_selector.hasClass('is-sticky')) { 130 $sticky_selector.removeClass('is-sticky'); 131 132 // "hide" the placeholder 133 if (sticky_elements[i].$placeholder) { 134 sticky_elements[i].$placeholder.css('display', 'none'); 135 } 136 137 // reset top position of the sticky element 138 $sticky_selector.css('top', ''); 139 140 if ($sticky_selector.is('#top-menu') && navbar_is_visible) { 141 $navbar_collapse.css('overflow', ''); 142 $navbar_collapse.css('height', ''); 143 } 144 } 145 } 146 }; 147 148 let stickyUpdateScheduled = false;
149 const scheduleStickyUpdate = function() { 150 if (stickyUpdateScheduled) { 151 return; 152 } 153 154 stickyUpdateScheduled = true; 155 const callback = function() { 156 stickyUpdateScheduled = false; 157 applyStickyState(); 158 }; 159 160 if (window.requestAnimationFrame) { 161 window.requestAnimationFrame(callback); 162 } else { 163 setTimeout(callback, 16); 164 } 165 }; 166 167 $(window).on('scroll', scheduleStickyUpdate); 168 applyStickyState(); 169 } 170 }, 171 172 setYoutubeThumbnails() { 173 $(".youtube-thumbnail").click(function() { 174 if ($(this).closest('#long-description').length) { 175 return; 176 } 177 178 let ytIds = $(this).find(".youtube-thumbnail-img").data("youtubeid"); 179 let newElem = '<div class="videoWrapper"><iframe type="text/html" width="640" height="460" loading="lazy" src="https://www.youtube.com/embed/' + ytIds + '" frameborder="0" allowfullscreen></iframe></div>'; 180 181 $(this).hide(); 182 $('.yt-video .col-md-12').append(newElem); 183 }); 184 }, 185 186 setBannerYoutubeThumbnails() { 187 $(".banner-yt-video-wrapper").click(function() { 188 let ytId = $(this).data("youtubeid"); 189 let newElem = '<iframe type="text/html" width="100%" height="100%" loading="lazy" src="https://www.youtube.com/embed/' + ytId + '" frameborder="0" allowfullscreen></iframe>'; 190 191 $(this).find(".banner-yt-video-wrap").hide(); 192 $(this).find(".banner-yt-video-iframe-wrap").append(newElem); 193 $(this).find(".banner-yt-video-iframe-wrap").css('display', 'block'); 194 }); 195 $(".slider-yt-video-wrapper").click(function() { 196 let ytId = $(this).data("youtubeid"); 197 let newElem = '<iframe type="text/html" width="100%" height="100%" loading="lazy" src="https://www.youtube.com/embed/' + ytId + '" frameborder="0" allowfullscreen></iframe>'; 198 199 $(this).find(".banner-yt-video-wrap").hide(); 200 $(this).find(".banner-yt-video-iframe-wrap").append(newElem); 201 $(this).find(".banner-yt-video-iframe-wrap").css('display', 'block'); 202 }); 203 }, 204 205 notificationBarClosing() { 206 $('#notification-bar-close a').click(function() { 207 Cookies.set('notification-bar-closed', $('#notification-bar-text').html(), { 208 expires: 60 209 }); 210 $('#notification-bar').removeClass('is-sticky'); 211 $('#notification-bar').hide(200, function() { 212 // might not work properly when more than 1 item is hidden (that's only case when user hides sth) 213 if (sticky_elements.length == 0) { 214 return; 215 } 216 217 sticky_elements = sticky_elements.filter(function(value, index) { 218 if ($(value.selector).is(':hidden')) { // this element is hidden, to be removed from sticky_elements 219 $('#is-sticky-placeholder-' + index).remove(); // remove its placeholder 220 221 if (index + 1 < sticky_elements.length) { // if this is not last element 222 for (var i = index + 1; i < sticky_elements.length; i++) { // iterate all remaining elements 223 sticky_elements[i].top -= value.height; // as of this element will be removed, we need to remove its height from the all remaining elements 224 $('#is-sticky-placeholder-' + i).attr('id', 'is-sticky-placeholder-' + (i - 1)); // also placeholders must be renumbered; (i-1) = new index after this element is removed 225 } 226 } 227 return false; 228 } 229 return true; 230 }); 231 $(window).scroll(); 232 }); 233 return false; 234 }); 235 }, 236 237 openFancyboxUniversal() { 238 $('img.fancybox-universal').on('click', function(e) { 239 $.fancybox.open({ 240 src: $(this).attr('src'), 241 baseClass: 'fancybox-universal', 242 }); 243 }); 244 }, 245 246 tryOpenTermsPopup() { 247 var urlHash = window.location.hash; 248 if (urlHash && ['#podminky', '#zzou_terms'].includes(urlHash)) { 249 var elem = $('a[data-src="' + urlHash + '"]')[0]; 250 if (elem) { 251 elem.click(); 252 } 253 // reset hash without scrolling to top
254 // (hashchange is fired when the value after # changes) 255 history.replaceState(null, null, window.location.pathname + "#"); 256 } 257 }, 258 259 initializeCmsModals() { 260 // Remove existing event listeners 261 $('body').off('click', 'a[href="#podminky"], a[data-src="#podminky"]'); 262 $('body').off('click', 'a[data-src="#zzou_terms"]'); 263 $('body').off('click', 'a[data-src="#heureka_terms"]'); 264 $('body').off('click', 'a[data-src="#newsletter_terms"]'); 265 266 // terms - get via ajax 267 $('body').on('click', 'a[href="#podminky"], a[data-src="#podminky"]', function(e) { 268 e.preventDefault(); 269 e.stopPropagation(); 270 let touch_enabled = FrontendShared.isTouchEnabled(); 271 $.fancybox.open({ 272 src: globalShop.url + 'get_terms/content_terms', 273 type: 'ajax', 274 touch: touch_enabled, 275 afterClose: function() { 276 // when fancybox is active, it sometimes shifts top menu 277 $('.navbar-fixed-top').css('padding-right', '0px'); 278 }, 279 beforeShow: function() { 280 // when fancybox is active, it sometimes shifts top menu by the width of scrollbar 281 $('.navbar-fixed-top').css('padding-right', globalShop.scrollbarWidth + 'px'); 282 }, 283 }); 284 }); 285 $('body').on('click', 'a[data-src="#zzou_terms"]', function(e) { 286 e.preventDefault(); 287 e.stopPropagation(); 288 let touch_enabled = FrontendShared.isTouchEnabled(); 289 $.fancybox.open({ 290 src: globalShop.url + 'get_terms/c_zzou_terms', 291 type: 'ajax', 292 touch: touch_enabled, 293 afterClose: function() { 294 // when fancybox is active, it sometimes shifts top menu 295 $('.navbar-fixed-top').css('padding-right', '0px'); 296 }, 297 beforeShow: function() { 298 // when fancybox is active, it sometimes shifts top menu by the width of scrollbar 299 $('.navbar-fixed-top').css('padding-right', globalShop.scrollbarWidth + 'px'); 300 }, 301 }); 302 }); 303 $('body').on('click', 'a[data-src="#heureka_terms"]', function(e) { 304 e.preventDefault(); 305 e.stopPropagation(); 306 let touch_enabled = FrontendShared.isTouchEnabled(); 307 $.fancybox.open({ 308 src: globalShop.url + 'get_terms/c_heureka_terms', 309 type: 'ajax', 310 touch: touch_enabled, 311 afterClose: function() { 312 // when fancybox is active, it sometimes shifts top menu 313 $('.navbar-fixed-top').css('padding-right', '0px'); 314 }, 315 beforeShow: function() { 316 // when fancybox is active, it sometimes shifts top menu by the width of scrollbar 317 $('.navbar-fixed-top').css('padding-right', globalShop.scrollbarWidth + 'px'); 318 }, 319 }); 320 }); 321 $('body').on('click', 'a[data-src="#newsletter_terms"]', function(e) { 322 e.preventDefault(); 323 e.stopPropagation(); 324 let touch_enabled = FrontendShared.isTouchEnabled(); 325 $.fancybox.open({ 326 src: globalShop.url + 'get_terms/c_newsletter_terms', 327 type: 'ajax', 328 touch: touch_enabled, 329 afterClose: function() { 330 // when fancybox is active, it sometimes shifts top menu 331 $('.navbar-fixed-top').css('padding-right', '0px'); 332 }, 333 beforeShow: function() { 334 // when fancybox is active, it sometimes shifts top menu by the width of scrollbar 335 $('.navbar-fixed-top').css('padding-right', globalShop.scrollbarWidth + 'px'); 336 }, 337 }); 338 }); 339 }, 340 341 validateEmail(email) {
342 var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; 343 return re.test(email); 344 }, 345 346 initializeOwlSlider() { 347 if (typeof jQuery().owlCarousel === "undefined") { 348 return false; 349 } 350 351 var owlSlideshow = $("#owl-slideshow"); 352 if (owlSlideshow.length === 0) { 353 return false; 354 } 355 356 var autoplayTimeout = owlSlideshow.data("autoplay-timeout") * 1000; 357 var autoplay = (autoplayTimeout == 0) ? false : true; 358 359 var nav = (owlSlideshow.find("div.item").length > 1) ? true : false; 360 361 var is_theme_next = (typeof globalShop.theme != 'undefined' && globalShop.theme == 'next'); 362 363 owlSlideshow.owlCarousel({ 364 autoplay: autoplay, 365 autoplayTimeout: autoplayTimeout, 366 items: 1, 367 loop: nav, 368 nav: nav, 369 dots: is_theme_next, 370 navText: "" 371 }); 372 373 $('.active .itembox-item:first').css({ 374 border: "0px" 375 }); 376 }, 377 378 initializeOwlCarousels() { 379 if (typeof jQuery().owlCarousel === "undefined") { 380 return false; 381 } 382 383 var itemboxes = $(".itembox:not(.gallery)"); 384 if (itemboxes.length === 0) { 385 return false; 386 } 387 388 itemboxes.each(function() { 389 390 // dont activate if in leftbox and theme next 391 var is_theme_next = (typeof globalShop.theme != 'undefined' && globalShop.theme == 'next'); 392 if ($(this).closest('.left-box').length && is_theme_next) { 393 return true; 394 } 395 396 // only if not already initialized (doesnt have class .owl-loaded) 397 var carusel = $(this).find('.owl-carousel').not('.owl-loaded'); 398 if (carusel.length === 0) { 399 return true; 400 } 401 402 // some exceptions 403 var is_theme_kauf = (typeof globalShop.theme != 'undefined' && ['kaufmania', 'kaufmart'].includes(globalShop.theme)); 404 var is_it_zel = (typeof globalShop.userId != 'undefined' && globalShop.userId == 3857); 405 var is_blog_post = $('body').hasClass('body-blogpost'); 406 407 var stage_width = $(this).width(); 408 409 // how many items show 410 var items = is_theme_kauf ? (is_blog_post ? 3 : 4) : 5; 411 if (stage_width <= 480) { 412 items = 1; 413 } else if (stage_width <= 768) { 414 items = 3; 415 } 416 var nav = carusel.find(".itembox-item").length > items ? true : false; 417 418 // left border of first item 419 if (!is_theme_next) { 420 $(this).find(".itembox-item").first().css({ 421 "border": "0px" 422 }); 423 } 424 425 // navigation 426 let nav_text = ["â¹", "âº"]; 427 if (is_theme_kauf) { 428 nav_text = ["", ""]; 429 } 430 if (is_theme_next) { 431 nav_text = ["<i class=\"bi bi-chevron-left\"></i>", "<i class=\"bi bi-chevron-right\"></i>"]; 432 } 433 434 // go 435 carusel.owlCarousel({ 436 autoplay: false, 437 loop: false, 438 dots: false, 439 items: items, 440 nav: nav, 441 navText: nav_text, 442 stagePadding: ((is_theme_kauf || is_it_zel) && stage_width <= 768) ? 45 : 0 443 }).on("translated.owl.carousel", function(e) { 444 // hide or show left border 445 if (!is_theme_next) { 446 $('.itembox .owl-item .itembox-item').css({ 447 "border-left": "1px solid #e5e5e5" 448 }); 449 $('.itembox .owl-item.active .itembox-item').first().css({ 450 "border-left": "0px solid #e5e5e5" 451 }); 452 } 453 }); 454 }); 455 }, 456 457 // for itemboxes, fire this after full page load to face responsive problems 458 refreshOwlCarousels() { 459 if (typeof jQuery().owlCarousel === "undefined") { 460 return false;
461 } 462 463 var owlCarousels = $(".itembox:not(.gallery) .owl-carousel"); 464 if (owlCarousels.length === 0) { 465 return false; 466 } 467 468 owlCarousels.each(function() { 469 $(this).trigger('refresh.owl.carousel'); 470 }); 471 }, 472 473 roundToAny(value, decimals) { 474 return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals); 475 }, 476 477 langToCountry(country) { 478 return country === 'cs' ? 'cz' : country; 479 }, 480 481 // php number_format eqvivalent 482 numberFormat(number, decimals = 0, decPoint = '.', thousandsSep = ' ') { 483 484 number = (number + '').replace(/[^0-9+\-Ee.]/g, ''); 485 var n = !isFinite(+number) ? 0 : +number; 486 var prec = !isFinite(+decimals) ? 0 : Math.abs(decimals); 487 var sep = (typeof thousandsSep === 'undefined') ? ',' : thousandsSep; 488 var dec = (typeof decPoint === 'undefined') ? '.' : decPoint; 489 var s = ''; 490 491 var toFixedFix = function(n, prec) { 492 if (('' + n).indexOf('e') === -1) { 493 return +(Math.round(n + 'e+' + prec) + 'e-' + prec); 494 } else { 495 var arr = ('' + n).split('e'); 496 var sig = ''; 497 if (+arr[1] + prec > 0) { 498 sig = '+'; 499 } 500 return (+(Math.round(+arr[0] + 'e' + sig + (+arr[1] + prec)) + 'e-' + prec)).toFixed(prec); 501 } 502 }; 503 504 // @todo: for IE parseFloat(0.55).toFixed(0) = 0; 505 s = (prec ? toFixedFix(n, prec).toString() : '' + Math.round(n)).split('.'); 506 if (s[0].length > 3) { 507 s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep); 508 } 509 if ((s[1] || '').length < prec) { 510 s[1] = s[1] || ''; 511 s[1] += new Array(prec - s[1].length + 1).join('0'); 512 } 513 514 return s.join(dec); 515 }, 516 517 isTouchEnabled() { 518 return ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0); 519 }, 520 521 savedPlacedOrderAddress() { 522 const keys = ['email', 'title', 'phone', 'jmeno', 'prijmeni', 'company', 'ulice', 'cp', 'nr', 'sec', 'bl', 'et', 'ap', 'sc', 'interfon', 'mesto', 'psc', 'country', 'fa_jmeno', 'fa_prijmeni', 'fa_ulice', 'fa_cp', 'fa_mesto', 'fa_psc', 'fa_ic', 'fa_dic']; 523 524 keys.forEach(key => { 525 if (localStorage.getItem(key) !== null) { 526 localStorage.setItem('placed_order_' + key, localStorage.getItem(key)); 527 localStorage.removeItem(key); 528 } 529 }); 530 531 localStorage.removeItem('customer_note'); 532 localStorage.removeItem('carrier_note'); 533 }, 534 535 exitshopDebounce(delay, callback) { 536 let timeout; 537 return function(...args) { 538 const context = this; 539 clearTimeout(timeout); 540 timeout = setTimeout(() => callback.apply(context, args), delay); 541 }; 542 }, 543 544 getUserEmailFromStorage() { 545 let visitor_email = null; 546 547 if (localStorage.getItem('placed_order_email') !== null && FrontendShared.validateEmail(localStorage.getItem('placed_order_email'))) { 548 visitor_email = localStorage.getItem('placed_order_email'); 549 } else if (Cookies.get('user_email') !== null && FrontendShared.validateEmail(Cookies.get('user_email'))) { 550 visitor_email = Cookies.get('user_email'); 551 } 552 553 return visitor_email; 554 }, 555 556 toggle(className, obj) { 557 var $input = $(obj); 558 if ($input.prop('checked')) { 559 $(className).show(); 560 } else { 561 $(className).hide(); 562 } 563 } 564}; 565 566$(document).ready(function() { 567 $(window).on('resize load', FrontendShared.setScrollbarWidth); 568 $(window).on('load', FrontendShared.refreshOwlCarousels); 569 $(window).on('hashchange', FrontendShared.tryOpenTermsPopup); 570 571 FrontendShared.setHalusky(); 572 FrontendShared.tryOpenTermsPopup(); 573 FrontendShared.initializeCmsModals(); 574 FrontendShared.openFancyboxUniversal(); 575 FrontendShared.prepareThankyouPage(); 576 FrontendShared.attachUniversalTooltips(); 577 FrontendShared.preventImgDownload(); 578 FrontendShared.makeStickyElements(); 579 FrontendShared.notificationBarClosing(); 580 FrontendShared.initializeOwlSlider(); 581 FrontendShared.initializeOwlCarousels();
582 FrontendShared.setYoutubeThumbnails(); 583 FrontendShared.setBannerYoutubeThumbnails(); 584});
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.