1/* global FontFaceObserver, Promise */ 2 3"use strict"; 4 5// Vanilla JS functions 6// eslint-disable-next-line no-unused-vars, no-shadow-restricted-names 7// noinspection JSVoidFunctionReturnValueUsed 8(function(window, document, undefined) { 9 // ---------------- 10 // FontFaceObserver 11 // ---------------- 12 var font = new FontFaceObserver("Poppins", {}); 13 var fontAlt = new FontFaceObserver("myriad-pro", {}); 14 15 Promise 16 .all([ 17 font.load(), 18 fontAlt.load() 19 ]) 20 .then(function() { 21 document.documentElement.classList.add("fonts-loaded"); 22 localStorage.setItem("FontFaceObserver", "fontIsLoaded"); 23 }) 24 .catch(function() { 25 console.log("Fonts are not available"); 26 }); 27 28 /** 29 * detect IE 30 * returns version of IE or false, if browser is not Internet Explorer 31 */ 32 function detectIE() { 33 var ua = window.navigator.userAgent; 34 35 var msie = ua.indexOf("MSIE "); 36 if (msie > 0) { 37 // IE 10 or older => return version number 38 return parseInt(ua.substring(msie + 5, ua.indexOf(".", msie)), 10); 39 } 40 41 var trident = ua.indexOf("Trident/"); 42 if (trident > 0) { 43 // IE 11 => return version number 44 var rv = ua.indexOf("rv:"); 45 return parseInt(ua.substring(rv + 3, ua.indexOf(".", rv)), 10); 46 } 47 48 var edge = ua.indexOf("Edge/"); 49 if (edge > 0) { 50 // Edge (IE 12+) => return version number 51 return parseInt(ua.substring(edge + 5, ua.indexOf(".", edge)), 10); 52 } 53 54 // other browser 55 return false; 56 } 57 58 // ---------------- 59 // LazyLoadObserver 60 // ---------------- 61 window.LazyLoadObserver = function() { 62 if (detectIE() && detectIE() < 12) { 63 return; 64 } 65 66 // Get all of the images that are marked up to lazy load 67 var images = document.querySelectorAll("[data-src], [data-srcset]"); 68 var observer; 69 70 function preloadImage(image) { 71 var src = image.dataset.src; 72 var srcset = image.dataset.srcset; 73 74 if (!src && !srcset) { 75 return; 76 } 77 78 image.addEventListener("load", function() { 79 image.classList.add("show"); 80 image.classList.remove("hide"); 81 }); 82 83 if (srcset) { 84 image.setAttribute("srcset", srcset); 85 } else { 86 image.setAttribute("src", src); 87 } 88 } 89 90 function onIntersection(entries) { 91 // Loop through the entries 92 entries.forEach(function(entry) { 93 // Are we in viewport? 94 if (entry.intersectionRatio > 0) { 95 // Stop watching and load the image 96 observer.unobserve(entry.target); 97 preloadImage(entry.target); 98 } 99 }); 100 } 101 102 if (!("IntersectionObserver" in window)) { 103 // Fallback 104 for (var i = 0; i < images.length; i++) { 105 images[i].classList.add("hide"); 106 preloadImage(images[i]); 107 } 108 } else { 109 var config = { 110 // If the image gets within 50px in the Y axis, start the download. 111 rootMargin: "100px 0px", 112 threshold: 0.01 113 }; 114 115 observer = new IntersectionObserver(onIntersection, config); 116 117 images.forEach(function(image) { 118 if (image.getAttribute("srcset") === image.dataset.srcset) { 119 return; 120 } 121 122 if (image.getAttribute("src") === image.dataset.src) { 123 return; 124 } 125 126 image.classList.add("hide"); 127 observer.observe(image); 128 }); 129 } 130 }; 131 132 LazyLoadObserver(); 133 134 // Funcions after document is ready 135 function ready(fn) { 136 if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") { 137 fn(); 138 } else { 139 document.addEventListener("DOMContentLoaded", fn); 140 } 141 } 142 143 ready(function() { 144 /** 145 * Element.closest() polyfill 146 * https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill 147 */ 148 if (!Element.prototype.closest) { 149 if (!Element.prototype.matches) { 150 Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector; 151 } 152 Element.prototype.closest = function(s) { 153 var el = this; 154 var ancestor = this; 155 if (!document.documentElement.contains(el)) return null; 156 do { 157 if (ancestor.matches(s)) return ancestor; 158 ancestor = ancestor.parentElement; 159 } while (ancestor !== null); 160 return null; 161 }; 162 } 163 164 // ---------------- 165 // Side menu controller 166 var sideMenu = document.querySelector(".js-menu"); 167 var sideMenuToggler = document.querySelector(".js-menu-toggler"); 168 var sideMenuBody = document.querySelector("body"); 169 170 if (!window.sideMenuConfiguration) { 171 window.sideMenuConfiguration = { 172 "defaultState": "opened", 173 "forceState": "", 174 "breakpoint": 1900 175 }; 176 } 177 178 sideMenuToggler.addEventListener("click", function() { 179 if (localStorage.getItem("sideMenuStatus") === "hidden") { 180 localStorage.setItem("sideMenuStatus", "visible"); 181 } else { 182 localStorage.setItem("sideMenuStatus", "hidden"); 183 } 184 }); 185 186 function sideMenuToggle(state) { 187 switch (state) { 188 case "show": 189 if (sideMenuConfiguration.forceState !== "closed") localStorage.setItem("sideMenuStatus", "visible"); 190 sideMenuToggler.classList.add("is-active"); 191 sideMenuBody.classList.add("is-opened"); 192 break; 193 case "hide": 194 if (sideMenuConfiguration.forceState !== "closed") localStorage.setItem("sideMenuStatus", "hidden"); 195 sideMenuToggler.classList.remove("is-active"); 196 sideMenuBody.classList.remove("is-opened"); 197 break; 198 default: 199 console.info("Missing configuration for side menu!"); 200 } 201 } 202 203 if (sideMenuConfiguration.forceState === "closed") { 204 sideMenuToggle("hide"); 205 } else if (window.innerWidth < sideMenuConfiguration.breakpoint) { 206 sideMenuToggle("hide"); 207 } else if (localStorage.getItem("sideMenuStatus") === "hidden") { 208 sideMenuToggle("hide"); 209 } else if (sideMenuConfiguration.defaultState === "opened") { 210 sideMenuToggle("show"); 211 } 212 213 window.addEventListener("resize", function() { 214 if ((window.innerWidth < sideMenuConfiguration.breakpoint) && (localStorage.getItem("sideMenuStatus") !== "hidden")) { 215 sideMenuToggle("hide"); 216 } 217 }); 218 219 // ---------------- 220 // Initialization of individual reCaptcha blocks 221 var grecaptcha = window.grecaptcha; 222 window.grecaptchaSiteKey = "6LcYgGQaAAAAALz61uy-x2JqCIa-ANWWkwXWcnI7"; 223 224 function reCaptchaExecute(index, elements) { 225 window.grecaptcha.execute(window.grecaptchaSiteKey, { action: elements[index].dataset.action }).then(function(token) { 226 elements[index].querySelector("[name='g-recaptcha-response']").value = token; 227 }); 228 } 229 230 window.initGoogleReCaptcha = function() { 231 var recaptchaElements = document.getElementsByClassName("g-recaptcha"); 232 for (var i = 0; i < recaptchaElements.length; i++) { 233 reCaptchaExecute(i, recaptchaElements); 234 } 235 }; 236 237 setInterval(function() { 238 initGoogleReCaptcha(); 239 }, 150000); 240 241 /* Nacteni externiho scriptu google reCaptcha, pokud jeste neni nacten odjinud */ 242 if (document.getElementsByClassName("g-recaptcha").length > 0 && typeof grecaptcha === "undefined") { 243 var scriptTag = document.createElement("script"); 244 var firstScriptTag = document.getElementsByTagName("script")[0]; 245 scriptTag.src = "//www.google.com/recaptcha/api.js?render=" + window.grecaptchaSiteKey + "&onload=initGoogleReCaptcha&hl=" + document.documentElement.lang; 246 firstScriptTag.parentNode.insertBefore(scriptTag, firstScriptTag); 247 } 248 249 // ---------------- 250 // Search autocomplete whisperer 251 var headerSearchInput = document.querySelectorAll(".js-search-input")[0]; 252 var headerSearchTarget = document.querySelectorAll(".js-search-target")[0]; 253 254 if (headerSearchInput || headerSearchTarget) { 255 function headerSearchTermInterval(headerSearchTerm) { 256 if ((headerSearchTerm !== headerSearchBeforeTerm) && (headerSearchTerm.length >= headerSearchChars)) { 257 headerSearchTerm = encodeURI(headerSearchTerm); 258 259 var headerSearchRequest = new XMLHttpRequest(); 260 headerSearchRequest.open("GET", "/search/search-ajax.htm?search=" + headerSearchTerm + "&template=include/ajax_search", true); 261 headerSearchRequest.setRequestHeader("X-Requested-With", "XMLHttpRequest"); 262 263 headerSearchRequest.onload = function() { 264 if (this.status >= 200 && this.status < 400) { 265 var headerSearchRequestData = JSON.parse(this.response); 266 // noinspection JSUnresolvedVariable 267 headerSearchTarget.innerHTML = headerSearchRequestData.template; 268 } else { 269 console.error("Error returned!"); 270 } 271 }; 272 273 headerSearchRequest.onerror = function() { 274 console.error("Connection error!"); 275 }; 276 277 headerSearchRequest.send(); 278 } 279 } 280 281 var headerSearchBeforeTerm, 282 headerSearchTerm, 283 headerSearchChars, 284 headerSearchDelay, 285 headerSearchSelf, 286 headerSearchTime; 287 288 headerSearchInput.addEventListener("keyup", function() { 289 headerSearchChars = 3; 290 headerSearchDelay = 250; 291 headerSearchSelf = this; 292 293 clearTimeout(headerSearchTime); 294 headerSearchTime = setTimeout(function() { 295 headerSearchTerm = headerSearchSelf.value; 296 headerSearchTermInterval(headerSearchTerm); 297 }, headerSearchDelay); 298 299 headerSearchTarget.style.display = "block"; 300 301 document.body.addEventListener("click", function() { 302 headerSearchTarget.style.display = "none"; 303 }); 304 }); 305 306 headerSearchInput.addEventListener("click", function() { 307 headerSearchTarget.style.display = "block"; 308 }); 309 } 310 311 // ---------------- 312 // Vanilla content toggler 313 document.addEventListener("click", function(e) { 314 if (!e.target.closest("[data-toggle]")) return; 315 316 e.preventDefault(); 317 318 var toggler = e.target.closest("[data-toggle]"); 319 var selector = toggler.getAttribute("data-toggle"); 320 321 toggler.classList.toggle("is-active"); 322 if (selector) { 323 document.querySelectorAll(selector).forEach(function(c) { 324 c.classList.toggle("is-opened"); 325 }); 326 } else { 327 toggler.parentNode.classList.toggle("is-opened"); 328 } 329 }, false); 330 331 // ---------------- 332 // Homepage Swiper 333 var homepageSwiperClass = "js-homepage-swiper"; 334 var homepageSwiperDOM = document.getElementsByClassName(homepageSwiperClass); 335 336 for (var i = 0; i < homepageSwiperDOM.length; i++) { 337 var homepageSwiperParameters = { 338 slidesPerView: 1, 339 speed: 1000, 340 loop: false, 341 342 // Autoplay 343 autoplay: { 344 delay: 5000, 345 disableOnInteraction: false, 346 }, 347 348 // Navigation arrows 349 navigation: { 350 nextEl: homepageSwiperDOM[i].parentElement.getElementsByClassName("swiper-button-next"), 351 prevEl: homepageSwiperDOM[i].parentElement.getElementsByClassName("swiper-button-prev") 352 }, 353 354 on: { 355 init: function() { 356 this.el.classList.add("swiper-initialized"); 357 }, 358 beforeDestroy: function() { 359 this.el.classList.remove("swiper-initialized"); 360 } 361 }, 362 }; 363 var homepageSwiper = new Swiper(homepageSwiperDOM[i], homepageSwiperParameters); 364 } 365 366 // ---------------- 367 // Product Swiper 368 var productSwiperClass = "js-product-swiper"; 369 var productSwiperDOM = document.getElementsByClassName(productSwiperClass); 370 371 for (var i = 0; i < productSwiperDOM.length; i++) { 372 var productSwiperParameters = { 373 spaceBetween: 25, 374 slidesPerView: 1, 375 speed: 1000, 376 loop: false, 377
378 // Breakpoints 379 breakpoints: { 380 1279: { 381 slidesPerView: 4, 382 }, 383 1070: { 384 slidesPerView: 3 385 }, 386 715: { 387 slidesPerView: 2, 388 } 389 }, 390 391 // Navigation arrows 392 navigation: { 393 nextEl: productSwiperDOM[i].parentElement.getElementsByClassName("swiper-button-next"), 394 prevEl: productSwiperDOM[i].parentElement.getElementsByClassName("swiper-button-prev") 395 }, 396 397 on: { 398 init: function() { 399 this.el.classList.add("swiper-initialized"); 400 }, 401 beforeDestroy: function() { 402 this.el.classList.remove("swiper-initialized"); 403 } 404 }, 405 }; 406 var productSwiper = new Swiper(productSwiperDOM[i], productSwiperParameters); 407 } 408 409 // ---------------- 410 // Side offer 411 if (localStorage.getItem("sideOffer") === null) { 412 var sideOffer = document.querySelector(".js-side-offer"); 413 414 if (sideOffer) { 415 var sideOfferToggler = sideOffer.querySelector(".js-side-offer-close"); 416 417 sideOfferToggler.addEventListener("click", function() { 418 localStorage.setItem("sideOffer", "isOpened"); 419 }, { once: true }); 420 421 setTimeout(function () { 422 sideOffer.classList.toggle("is-opened"); 423 sideOfferToggler.classList.toggle("is-active"); 424 }, 4000); 425 } 426 } 427 }); 428}(window, document)); 429 430// jQuery functions 431$(function() { 432 // ---------------- 433 // Product already in cart 434 function highlightCartProducts() { 435 var $productList = $(".items"); 436 var $cartProductsUrl = "/cart/detail.htm?template=include/ajax-products_cart"; 437 438 if ($productList.length > 0) { 439 $.getJSON($cartProductsUrl, function(data) { 440 var $cartProductsTemplate = $("<div />"); 441 $cartProductsTemplate.html(data.template); 442 var $cartProducts = $cartProductsTemplate.find(".js-cart-product"); 443 444 $cartProducts.each(function() { 445 var $product = $(this); 446 var $productCode = $product.data("code"); 447 448 var $productCartBadge = $product.find(".js-cart-badge"); 449 var $productCartQuantity = $product.find(".js-cart-quantity"); 450 451 var $productItem = $productList.find('.item[data-code=' + $productCode + ']'); 452 453 if ($productItem) { 454 $productItem.removeClass("has-spinner").removeClass("in-cart"); 455 $productItem.find(".js-cart-badge").remove(); 456 $productItem.find(".js-cart-quantity").remove(); 457 458 $productItem.addClass("in-cart"); 459 $productItem.append($productCartBadge); 460 $productItem.find(".js-cart-button").parent().append($productCartQuantity); 461 } 462 }); 463 }) 464 .fail(function(jqxhr, textStatus, error) { 465 var err = " - " + textStatus + "\nerror: " + jqxhr.status + " (" + error + ")\ncall url: " + $(this)[0].url + "\ncall param: " + $(this)[0].data; 466 console.error("Request Failed" + err); 467 }); 468 } 469 } 470 471 highlightCartProducts(); 472 473 // ---------------- 474 // Ajax - replace objects 475 function ajaxReplaceObject(options, cb) { 476 /** @namespace options.object */ 477 /** @namespace options.ajaxUrl */ 478 /** @namespace options.ajaxFormData */ 479 var $object = options.object || null; 480 var ajaxUrl = options.ajaxUrl || null; 481 var ajaxFormData = options.ajaxFormData || null; 482 483 $.getJSON(ajaxUrl, function(data) { 484 $object.html(data.template); 485 }) 486 .done(function() { 487 $("body").removeClass("has-spinner"); 488 if (typeof cb === "function") { cb(true); } 489 }) 490 .fail(function(jqxhr, textStatus, error) { 491 var err = " - " + textStatus + "\nerror: " + jqxhr.status + " (" + error + ")\ncall url: " + $(this)[0].url + "\ncall param: " + $(this)[0].data; 492 console.error("Request Failed" + err); 493 }); 494 if (typeof cb === "function") { cb(); } 495 } 496 497 // ---------------- 498 // Ajax - cart in header 499 function reloadHeaderCart() { 500 var $headerCart = $(".js-replace-cart"); 501 var ajaxUrl = "?template=include/ajax-header_cart"; 502 ajaxReplaceObject({ object: $headerCart, ajaxUrl: ajaxUrl }); 503 } 504 505 // ---------------- 506 // Custom number inputs 507 $(document).on("click", ".js-quantity-change", function(e) { 508 var $quantityInput = $(this).parent().find(".js-quantity-input"); 509 var $quantityChange = $(this).data("quantity"); 510 511 if ($quantityChange === "plus") { 512 var $quantityInputStep = parseFloat($quantityInput.attr("step")); 513 $quantityInput[0].value -= -$quantityInputStep; 514 } else if ($quantityChange === "minus") { 515 var $quantityInputStep = parseFloat($quantityInput.attr("step")); 516 $quantityInput[0].value = Math.max($quantityInputStep, $quantityInput[0].value - $quantityInputStep) 517 } 518 519 if ($quantityInput.data("product")) { 520 $(".js-header-cart-items").addClass("has-spinner"); 521 522 $.post($quantityInput.data("url"), "quantity[" + $quantityInput.data("product") + "]=" + $quantityInput.val() + "&system_cart_update=", function() { 523 reloadHeaderCart(); 524 }); 525 } 526 527 if ($quantityInput.data("refresh")) { 528 $quantityInput.parents(".item[data-code]").addClass("has-spinner"); 529 highlightCartProducts(); 530 } 531 }); 532 533 $(document).on("click", ".js-cart-delete", function(e) { 534 e.preventDefault(); 535 $(".js-header-cart-items").addClass("has-spinner"); 536 537 $.post($(this).data("url"), "remove=" + $(this).data("product") + "&system_remove_item=", function() { 538 reloadHeaderCart(); 539 }); 540
541 if ($(this).data("code")) { 542 $(".items").find(".item[data-code=" + $(this).data("code") + "]").removeClass("in-cart"); 543 } 544 }); 545 546 $(document).on("change", ".js-quantity-input", function() { 547 $(".js-header-cart-items").addClass("has-spinner"); 548 549 $.post($(this).data("url"), "quantity[" + $(this).data("product") + "]=" + $(this).val() + "&system_cart_update=", function() { 550 reloadHeaderCart(); 551 }); 552 553 if (($(this).val() === "0") && ($(this).data("refresh"))) { 554 $(this).parents(".item[data-code]").removeClass("has-spinner").removeClass("in-cart"); 555 } else if ($(this).data("refresh")) { 556 $(this).parents(".item[data-code]").addClass("has-spinner"); 557 highlightCartProducts(); 558 } 559 }); 560 561 // ---------------- 562 // Fixed header 563 var $html = $("html"); 564 565 if ($(document).scrollTop() > 140) { 566 $html.addClass("header-smaller"); 567 } 568 569 $(document).scroll(function() { 570 var y = $(this).scrollTop(); 571 if (y >= 140) { 572 $html.addClass("header-smaller"); 573 } else { 574 $html.removeClass("header-smaller"); 575 } 576 }); 577 578 // ---------------- 579 // Responsive tabs 580 $(".js-responsive-tabs").responsiveTabs({ 581 startCollapsed: "tabs", 582 setHash: true, 583 scrollToAccordionOnLoad: false 584 }); 585 $(window).on("load", function() { 586 if (window.location.hash && window.location.hash.indexOf("tab-") === 1) { 587 $(window).scrollTop($(".r-tabs").offset().top - ($("header").outerHeight()) - 20); 588 } 589 }); 590 591 // ---------------- 592 // Mnozstevni slevy u produktu 593 function recalculateProductQuantityDiscount(quantity) { 594 var $volumeDiscounts = $(".js-volumes-informations > label"); 595 596 $volumeDiscounts.each(function() { 597 var $discountInput = $(this).find("input"); 598 599 if (quantity >= $discountInput.data("limit")) { 600 $discountInput.prop("checked", true); 601 } else { 602 $discountInput.prop("checked", false); 603 } 604 605 if ($discountInput.is(":checked")) { 606 var $productPrice = $discountInput.data("price"); 607 var $productPriceExclVat = $discountInput.data("price-excl-vat"); 608 609 $(".js-product-price").html($productPrice); 610 $(".js-product-price-exl-vat").html($productPriceExclVat); 611 } 612 }); 613 } 614 615 $(".js-quantity-input").on("change", function() { 616 recalculateProductQuantityDiscount($(this).val()); 617 }); 618 619 $(".js-quantity-change").on("click", function() { 620 var $this = $(this); 621 setTimeout(function() { 622 recalculateProductQuantityDiscount($this.parent().find("input").val()); 623 }, 0); 624 }); 625 626 // ---------------- 627 // Vkladani produktu do oblibenych ve vypisu produktu 628 /* global Cookies */ 629 function setCount(type) { 630 var count = Object.keys(Cookies.getJSON()).filter(function(i) { return i.includes(type); }).length; 631 $(".js-" + type + "-count").text(count); 632 } 633 634 setCount("favourite_product"); 635 636 $(document).on("click", "[data-favourite]", function(e) { 637 e.preventDefault(); 638 e.stopPropagation(); 639 640 var $item = $(this); 641 var productId = $item.data("product_id"); 642 643 if ($item.hasClass("is-active")) { 644 Cookies.remove("favourite_product[" + productId + "]", { path: "/" }); 645 fetch($item.data("remove")); 646 } else { 647 Cookies.set("favourite_product[" + productId + "]", productId, { expires: 14, path: "/" }); 648 fetch($item.data("add")); 649 } 650 651 $item.toggleClass("is-active"); 652 653 setCount("favourite_product"); 654 655 if ($item.data("remove-parent")) { 656 $item.parents($item.data("remove-parent")).remove(); 657 } 658 }); 659 660 // ---------------- 661 // Hromadne vkladani produktu do kosiku 662 /* global Promise */ 663 $(document).on("click", ".js-forms-submit", function(e) { 664 e.preventDefault(); 665 666 $.fancybox.open("<div class='popup-insert_all'><p><strong>Vkládám produkty do koÅ¡Ãku…</strong></p></div>"); 667 668 Promise.all( 669 $(".js-product-insert").map(function() { 670 var ajaxUrl = $(this).attr("data-insert_ajax"); 671 var insertPost = $(this).serialize(); 672 673 if (!ajaxUrl) { 674 return Promise.reject(Error("missing data-insert_ajax")); 675 } 676 677 return new Promise(function(resolve, reject) { 678 $.post(ajaxUrl, insertPost, function(data) { 679 /** @namespace data.error_list.cart_insert */ 680 /** @namespace data.html_data.cart_product.template */ 681 if (data.error_list && data.error_list.cart_insert) { 682 $.fancybox.getInstance().setContent($.fancybox.getInstance().current, '<div class="popup popup-message popup-error"><div class="capt">Error</div><div class="cont">' + data.error_list.cart_insert + "</div></div>"); 683 return reject(Error("error")); 684 } 685 return resolve("ok - " + insertPost); 686 }, "json"); 687 }); 688 }) 689 ).then(function(value) { 690 $.fancybox.getInstance().setContent($.fancybox.getInstance().current, '<div class="popup-insert_all"><h3 class="mt0 mb40">Produkty byly úspÄÅ¡nÄ vloženy do koÅ¡Ãku</h3><a href="/kosik/detail.htm" class="btn btn-primary"><svg role="img" class="icon mr10">
690<use xlink:href="/templates/img/icons.svg#cart"></use></svg>Objednat produkty</a></div>'); 691 }); 692 }); 693 694 // ---------------- 695 // Ajax - insert product to cart 696 $(document).on("submit", ".js-product-insert", function() { 697 var $productForm = $(this); 698 var $productItem = $productForm.closest(".item"); 699 700 var insert_post = $(this).serialize(); 701 insert_post += "&system_cart_insert="; 702 703 if (!$(this).attr("data-insert_ajax")) console.error("missing data-insert_ajax"); 704 705 $productItem.addClass("has-spinner"); 706 707 $.post($(this).attr("data-insert_ajax"), insert_post, function(data) { 708 /** @namespace data.error_list.cart_insert */ 709 /** @namespace data.html_data.cart_product.template */ 710 $.fancybox.close(); 711 if (data.error_list && data.error_list.cart_insert) { 712 $.fancybox.open('<div class="popup popup-message popup-error"><div class="capt">Error</div><div class="cont">' + data.error_list.cart_insert + "</div></div>"); 713 $productItem.removeClass("has-spinner"); 714 } else { 715 if ($productForm.data("popup") === "hidden") { 716 dataLayer.push({ 717 "event": "addToCart", 718 "content_name": $productItem.data("name"), 719 "content_category": $productItem.data("category"), 720 "content_ids": $productItem.data("id"), 721 "quantity": $productItem.data("quantity"), 722 "value": $productItem.data("price"), 723 }); 724 } else { 725 $.fancybox.open(data.html_data.cart_product.template); 726 727 var $togetherProducts = $(".js-together-items"); 728 var $togetherPopup = $(".js-popup-together"); 729 730 if (($togetherProducts.length > 0) && ($togetherPopup.length > 0)) { 731 $togetherPopup.find(".popup-items").html($togetherProducts.html()); 732 $togetherPopup.css("display", "block"); 733 } 734 } 735 736 reloadHeaderCart(); 737 highlightCartProducts(); 738 } 739 }, "json"); 740 return false; 741 }); 742 743 // ---------------- 744 // Ajax - load more articles 745 var ajaxReplacingArticles = ["pagination"]; 746 747 $.each(ajaxReplacingArticles, function(i, value) { 748 $(".js-" + value).remove(); 749 }); 750 751 function ajaxLoadArticles($button, ajaxUrl) { 752 var $ajaxArticles = $(".js-articles"); 753 var url = ajaxUrl + ((ajaxUrl.indexOf("?") >= 0) ? "&" : "?") + "template=include/ajax_articles"; 754 $.getJSON(url, function(data) { 755 $ajaxArticles.append(data.template); 756 757 var $temp = $("<div />"); 758 $temp.html(data.template); 759 $.each(ajaxReplacingArticles, function(i, value) { 760 $(".js-" + value).remove(); 761 }); 762 $(".pagination").html($temp.find(".js-pagination").html()); 763 if (typeof LazyLoadObserver === "function") { LazyLoadObserver(); } 764 }) 765 .fail(function(jqxhr, textStatus, error) { 766 var err = " - " + textStatus + "\nerror: " + jqxhr.status + " (" + error + ")\ncall url: " + $(this)[0].url + "\ncall param: " + $(this)[0].data; 767 console.error("Request Failed" + err); 768 }); 769 } 770 $(document).on("click", ".js-load-articles", function(e) { 771 e.preventDefault(); 772 ajaxLoadArticles($(this), $(this).attr("href")); 773 }); 774 775 // ---------------- 776 // Ajax - load more products 777 var ajaxReplacingProducts = ["pagination"]; 778 779 $.each(ajaxReplacingProducts, function(i, value) { 780 $(".js-" + value).remove(); 781 }); 782 783 function ajaxLoadProducts($button, ajaxUrl) { 784 var $ajaxProducts = $(".js-products"); 785 var url = ajaxUrl + ((ajaxUrl.indexOf("?") >= 0) ? "&" : "?") + "template=include/ajax_products"; 786 $.getJSON(url, function(data) { 787 $ajaxProducts.find(".js-item-empty").remove(); 788 $ajaxProducts.append(data.template); 789 790 var $temp = $("<div />"); 791 $temp.html(data.template); 792 $.each(ajaxReplacingProducts, function(i, value) { 793 $(".js-" + value).remove(); 794 }); 795 $(".pagination").html($temp.find(".js-pagination").html()); 796 if (typeof LazyLoadObserver === "function") { LazyLoadObserver(); } 797 if (typeof highlightCartProducts === "function") { highlightCartProducts(); } 798 }) 799 .fail(function(jqxhr, textStatus, error) { 800 var err = " - " + textStatus + "\nerror: " + jqxhr.status + " (" + error + ")\ncall url: " + $(this)[0].url + "\ncall param: " + $(this)[0].data; 801 console.error("Request Failed" + err); 802 }); 803 } 804 $(document).on("click", ".js-load-products", function(e) { 805 e.preventDefault(); 806 ajaxLoadProducts($(this), $(this).attr("href")); 807 }); 808 809 // ---------------- 810 // Ajax - filtering 811 var $formProductList = $(".js-form-products-list"); 812 813 $formProductList.on("change", "select, input", function(e) { 814 e.preventDefault(); 815 $formProductList.submit(); 816 }); 817 818 // ------------------ 819 // Script pro ajaxove odesilani newsletteru 820 $(".js-form-rating, .js-form-discussion, .js-form-newsletter").on("submit", function(e) { 821 e.preventDefault(); 822 823 var $thisForm = $(this); 824 var $recaptcha = $thisForm.find(".g-recaptcha").length > 0 ? $thisForm.find(".g-recaptcha") : false;
825 var formAction = $thisForm.data("ajax_action") || $thisForm.attr("action"); 826 var formData = $thisForm.serialize(); 827 828 if ($recaptcha) $recaptcha.removeClass("error"); 829 830 $.post(formAction, formData, function(data) { 831 if (data === true) { 832 $thisForm[0].reset(); 833 834 var $successMessage = $thisForm.find(".js-message-success"); 835 if (!$successMessage.length) { 836 console.error("U formulare chybi .message-success se zpravou o uspesnem odeslani!"); 837 } else { 838 $.fancybox.open($successMessage.html()); 839 } 840 } else { 841 var errorMessage = "Undefined error"; 842 if ($recaptcha && data.error && data.error === "missing-input-response") { 843 var $errorMessageRecaptcha = $thisForm.find(".js-message-error-recaptcha"); 844 if (!$errorMessageRecaptcha.length) { 845 console.error("U formulare chybi .message-error-recaptcha se zpravou o nepotvrzeni google reCaptchy!"); 846 } else { 847 errorMessage = $errorMessageRecaptcha.html(); 848 } 849 $recaptcha.addClass("error"); 850 } else { 851 var $errorMessage = $thisForm.find(".js-message-error"); 852 if (!$errorMessage.length) { 853 console.error("U formulare chybi .message-error-recaptcha se zpravou o nespravnem vyplneni udaju!"); 854 } else { 855 errorMessage = $errorMessage.html(); 856 } 857 } 858 $.fancybox.open(errorMessage); 859 } 860 }, "json") 861 .fail(function(jqxhr, textStatus, error) { 862 var errorMessage = " - " + textStatus + "\nerror: " + jqxhr.status + " (" + error + ")\ncall url: " + $(this)[0].url + "\ncall param: " + $(this)[0].data; 863 console.error("Request Failed" + errorMessage); 864 }); 865 }); 866 867 // ------------------ 868 // Script pro obecne odesilani formularu 869 $(".js-form-general").on("submit", function() { 870 var $this = $(this); 871 var $btnSubmit = $this.find("button[type=submit]"); 872 var $recaptcha = $this.find(".g-recaptcha"); 873 var $redirect = $this.find("input[name=redirect]"); 874 var redirectToPopup = $redirect.data("redirect-to-popup"); 875 var formData = new FormData($this[0]); 876 877 formData.append("submitted", 1); 878 $recaptcha.removeClass("error"); 879 880 $.ajax({ 881 url : $this.attr("action"), 882 type: "POST", 883 data : formData, 884 processData: false, 885 contentType: false, 886 success: function(data){ 887 if (data === "true") { 888 if (redirectToPopup) { 889 $.fancybox.close(); 890 $.fancybox.open({ 891 src: $redirect.val() 892 }); 893 } else { 894 window.location.href = $redirect.val(); 895 } 896 } else { 897 $btnSubmit.addClass("btn-error"); 898 setTimeout(function() { 899 $btnSubmit.removeClass("btn-error"); 900 }, 2000); 901 console.log(data); 902 if (data === "captchaMissing") $recaptcha.addClass("error"); 903 } 904 } 905 }) 906 .fail(function(jqxhr, textStatus, error) { 907 var err = " - " + textStatus + "\nerror: " + jqxhr.status + " (" + error + ")\ncall url: " + $(this)[0].url + "\ncall param: " + $(this)[0].data; 908 console.error("Request Failed" + err); 909 }); 910 911 return false; 912 }); 913 914 // ------------------- 915 // Odesilani registracniho formulare 916 $(".js-register-form").on("submit", function() { 917 var $this = $(this); 918 var $btnSubmit = $this.find(".btn[type=submit]"); 919 var formData = new FormData($this[0]); 920 921 $.ajax({ 922 url : $this.attr("action"), 923 type: "POST", 924 data : formData, 925 processData: false, 926 contentType: false, 927 success: function(rawData) { 928 var data = JSON.parse(rawData); 929 if (data.success) { 930 window.location.href = $this.find(".js-redirect").val(); 931 } else { 932 $btnSubmit.addClass("btn-error"); 933 setTimeout(function() { 934 $btnSubmit.removeClass("btn-error"); 935 }, 2000); 936 console.log(data); 937 $.fancybox.open('<div class="popup popup-message popup-error"><div id="error_window"><div class="capt">CHYBA</div><div class="cont">Jedna Äi vÃce povinných položek nenà nebo je chybnÄ vyplnÄna. ProsÃm zkontrolujte a opravte následujÃcà chyby:<div class="error_message error-list-all"><ul><li>' + data.error + '</li></lu></ul></div></div></div></div>'); 938 } 939 } 940 }) 941 .fail(function(jqxhr, textStatus, error) { 942 var err = " - " + textStatus + "\nerror: " + jqxhr.status + " (" + error + ")\ncall url: " + $(this)[0].url + "\ncall param: " + $(this)[0].data; 943 console.error("Request Failed" + err); 944 }); 945 946 return false;
947 }); 948 949 // ------------------- 950 // Customer registration form 951 function prep_os_firm_form(time) { 952 if ($("input[name=buy]:checked").val() === "1") { 953 $(".company-input").parent("div").slideUp(time); 954 } else { 955 $(".company-input").parent("div").slideDown(time); 956 } 957 } 958 959 function prep_delivery_form(time) { 960 if ($(".toggle_delivery_address").is(":checked")) $(".address-hide").slideDown(time); 961 else $(".address-hide").slideUp(time); 962 } 963 964 if ($("#customer-reg-form").is("form")) { 965 if ($("input[name='billing_ic']").val() !== "") { 966 $(".buy_company").trigger("click"); 967 } else { 968 $(".buy_private").trigger("click"); 969 } 970 prep_os_firm_form(0); 971 $(this).on("click", "input[name=buy]", function() { prep_os_firm_form(400); }); 972 973 if ($("input[name='delivery_address']").val() !== "" || $("input[name='delivery_city']").val() !== "") { 974 $(".toggle_delivery_address").attr("checked", true).trigger("change"); 975 } 976 prep_delivery_form(0); 977 $(this).on("change click", ".toggle_delivery_address", function() { prep_delivery_form(400); }); 978 979 var er_m = $(".error_message-wrap"); 980 if (er_m.length) { 981 er_m.hide(); 982 setTimeout(function() { 983 $.fancybox.open(er_m.html(), { padding: 0, maxWidth: 500, minHeight: 80 }); 984 }, 250); 985 } 986 } 987 988 // ------------------- 989 // Customer registration - loading company from ARES 990 function searchInAres(ico, companyInputId, dicInputId, streetInputId, cityInputId, zipInputId) { 991 var icoIntVal = parseInt(ico, 10); 992 if (!isNaN(icoIntVal) && ico.toString().length === 8) { 993 /** @namespace data.name */ 994 /** @namespace data.dic */ 995 /** @namespace data.address.ulice */ 996 /** @namespace data.address.mesto */ 997 /** @namespace data.address.psc */ 998 999 var domainName = window.location.hostname; 1000 domainName = domainName.replace("www.", ""); 1001 1002 $.getJSON(`https://admin.${domainName}/extensions/data_bridge/external_data/eso9_ares/?ic=${ico}`) 1003 .done(function(data) { 1004 if (data) { 1005 $("#" + companyInputId).val(data.name).attr("readonly", true); 1006 $("#" + dicInputId).val(data.dic).attr("readonly", true); 1007 $("#" + streetInputId).val(data.address.ulice).attr("readonly", true); 1008 $("#" + cityInputId).val(data.address.mesto).attr("readonly", true); 1009 $("#" + zipInputId).val(data.address.psc).attr("readonly", true); 1010 $("#cf_billing_country").attr("readonly", true); 1011 } else { 1012 $.fancybox.open('<div class="popup popup-message popup-error"><div id="error_window"><div class="capt">CHYBA</div><div class="cont">Jedna Äi vÃce povinných položek nenà nebo je chybnÄ vyplnÄna. ProsÃm zkontrolujte a opravte následujÃcà chyby:<div class="error_message error-list-all"><ul><li>Zadané IÄ nebylo nalezeno v databázi ARES</li></lu></ul></div></div></div></div>'); 1013 $("#" + companyInputId).val("").attr("readonly", false); 1014 $("#" + dicInputId).val("").attr("readonly", false); 1015 $("#" + streetInputId).val("").attr("readonly", false); 1016 $("#" + cityInputId).val("").attr("readonly", false); 1017 $("#" + zipInputId).val("").attr("readonly", false); 1018 $("#cf_billing_country").attr("readonly", false); 1019 } 1020 }) 1021 .fail(function(jqxhr, textStatus, error) { 1022 var err = " - " + textStatus + "\nerror: " + jqxhr.status + " (" + error + ")\ncall url: " + $(this)[0].url + "\ncall param: " + $(this)[0].data; 1023 console.error("Request Failed" + err); 1024 }); 1025 } 1026 } 1027 1028 if ($html.attr("lang") === "cs") { 1029 $("#register-form").on("input", "#cf_billing_ic", function() { 1030 searchInAres($(this).val(), "cf_billing_company", "cf_billing_dic", "cf_billing_address", "cf_billing_city", "cf_billing_psc"); 1031 }); 1032 } 1033 1034 // ------------------- 1035 // Customer profile - billing address restriction 1036 function restrictBillingAddress(addressForm) { 1037 var $addressInputs = addressForm.find("input, select"); 1038 1039 $addressInputs.each(function() { 1040 var $input = $(this); 1041 1042 if ($input.is("#cf_billing_ic")) { 1043 $input.removeAttr("readonly"); 1044 } else if ($input.val()) { 1045 $input.attr("readonly", "readonly"); 1046 if ($input.is("select")) $input.css("pointer-events", "none"); 1047 } 1048 }); 1049 } 1050 1051 $(function() { 1052 var $customerBillingAddressForm = $("#user-profile #system_billing_address"); 1053 var $customerBillingAddressIc = $("#user-profile #cf_billing_ic").val(); 1054 1055 if (($customerBillingAddressForm.length > 0) && $customerBillingAddressIc) { 1056 restrictBillingAddress($customerBillingAddressForm); 1057 } 1058 }); 1059});
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.