1/*global jQuery*/ 2/*global kadence_pg*/ 3/*global Splide*/ 4/*global GLightbox*/ 5jQuery(function ($) { 6 var KadenceProductGalleryisMobile = { 7 Android: function () { 8 return navigator.userAgent.match(/Android/i); 9 }, 10 BlackBerry: function () { 11 return navigator.userAgent.match(/BlackBerry/i); 12 }, 13 iOS: function () { 14 return navigator.userAgent.match(/iPhone|iPad|iPod/i); 15 }, 16 Opera: function () { 17 return navigator.userAgent.match(/Opera Mini/i); 18 }, 19 Windows: function () { 20 return navigator.userAgent.match(/IEMobile/i); 21 }, 22 any: function () { 23 return ( 24 KadenceProductGalleryisMobile.Android() || 25 KadenceProductGalleryisMobile.BlackBerry() || 26 KadenceProductGalleryisMobile.iOS() || 27 KadenceProductGalleryisMobile.Opera() || 28 KadenceProductGalleryisMobile.Windows() 29 ); 30 }, 31 }; 32 /** 33 * Product gallery class. 34 */ 35 var KadenceProductGallery = function ($gallery) { 36 const self = this; 37 self.$gallery = $gallery; 38 var splide_speed = $gallery.data("speed"), 39 product_id = $gallery.data("product-id"), 40 splide_animation = $gallery.data("animation"), 41 splide_animation_speed = $gallery.data("animation-speed"), 42 slick_arrows = $gallery.data("arrows"), 43 slick_pagination = $gallery.data("pagination"), 44 layout = $gallery.data("layout"), 45 mdLayout = $gallery.data("md-layout"), 46 smLayout = $gallery.data("sm-layout"), 47 items_count = $gallery.data("gallery-items"), 48 splide_thumbs_show = $gallery.data("thumb-show"), 49 splide_thumbs_tablet_show = $gallery.data("md-thumb-show"), 50 splide_thumbs_mobile_show = $gallery.data("sm-thumb-show"), 51 splide_thumbs_width = $gallery.data("thumb-width"), 52 splide_thumbs_tablet_width = $gallery.data("md-thumb-width"), 53 splide_thumbs_mobile_width = $gallery.data("sm-thumb-width"), 54 splide_thumbs_gap = $gallery.data("thumb-gap"), 55 splide_thumbs_tablet_gap = $gallery.data("md-thumb-gap"), 56 splide_thumbs_mobile_gap = $gallery.data("sm-thumb-gap"), 57 splide_thumbs_center = $gallery.data("thumb-center"), 58 splide_auto = $gallery.data("auto"), 59 splide_auto_height = $gallery.data("auto-height"),
60 visible_captions = $gallery.data("visible-captions"), 61 $zoom = $gallery.data("zoom-active"), 62 $zoom_type = $gallery.data("zoom-type"), 63 splide_thumbs_on_hover = $gallery.data("thumb-hover"), 64 //$items = $gallery.data('gallery-items'), 65 fixedHeight = $gallery.find(".splide__track").height(), 66 pauseonhover = false, 67 thumbnails_have_changed = false, 68 sliderDirection = "ltr"; 69 var $datathumbs = false; 70 var original_items_count = items_count; 71 self.$galleryThumbnails = $gallery 72 .closest(".ksk-gallery") 73 .find("#pg-thumbnails-" + product_id); 74 self.$galleryExtra = $gallery 75 .closest(".ksk-gallery") 76 .siblings("#pg-extra-" + product_id); 77 78 if (self.$galleryExtra.length) { 79 $datathumbs = self.$galleryExtra.data("product_variation_images"); 80 if ( 81 $datathumbs["is_ajax"] === false && 82 $datathumbs["has_variation_images"] === false 83 ) { 84 $datathumbs = false; 85 } 86 } 87 if ($('html[dir="rtl"]').length) { 88 sliderDirection = "rtl"; 89 } 90 if ( 91 $zoom && 92 !KadenceProductGalleryisMobile.any() && 93 $(window).width() > 790 94 ) { 95 pauseonhover = true; 96 } 97 $gallery.addClass("splide-initial"); 98 var current_layout = layout; 99 var current_thumb_width = splide_thumbs_width; 100 var current_thumbs_show = splide_thumbs_show; 101 if ($(window).width() < 769) { 102 current_layout = smLayout; 103 current_thumb_width = splide_thumbs_mobile_width; 104 current_thumbs_show = splide_thumbs_mobile_show; 105 } else if ($(window).width() < 1024) { 106 current_layout = mdLayout; 107 current_thumb_width = splide_thumbs_tablet_width; 108 current_thumbs_show = splide_thumbs_tablet_show; 109 } 110 if ( 111 current_layout === "tiles" || 112 current_layout === "grid" || 113 current_layout === "list" 114 ) { 115 splide_auto = false; 116 } 117 var splideMain = new Splide(self.$gallery[0], { 118 type: splide_animation ? "fade" : "slide", 119 autoplay: splide_auto === true ? true : false, 120 lazyLoad: "nearby", 121 rewind: true, 122 pagination: slick_pagination ? true : false, 123 arrows: slick_arrows ? true : false, 124 perPage: 1, 125 pauseOnHover: pauseonhover === false ? false : true, 126 direction: sliderDirection, 127 interval: undefined !== splide_speed ? splide_speed : 7000, 128 speed: 129 undefined !== splide_animation_speed 130 ? splide_animation_speed 131 : 400, 132 easing: 133 undefined !== splide_animation_speed && 134 splide_animation_speed > 1000 135 ? "linear" 136 : "cubic-bezier(0.25, 1, 0.5, 1)", 137 }); 138 splideMain.on("mounted", function () { 139 $gallery.addClass("kt-product-gal-loaded"); 140 }); 141 if ( 142 splide_auto_height === true && 143 (current_layout === "above" || current_layout === "slider") 144 ) { 145 var updateSlideHeight = (newIndex) => { 146 var slide = splideMain.Components.Slides.getAt( 147 typeof newIndex == "number" ? newIndex : splideMain.index 148 ).slide; 149 slide.parentElement.style.height = 150 slide.firstChild.offsetHeight + "px"; 151 }; 152 splideMain.on("mounted move resize", updateSlideHeight); 153 var updateSlideHeightRefresh = (newIndex) => { 154 var slide = splideMain.Components.Slides.getAt( 155 typeof newIndex == "number" ? newIndex : splideMain.index 156 ).slide; 157 setTimeout(() => { 158 slide.parentElement.style.height = 159 slide.firstChild.offsetHeight + "px"; 160 }, 100); 161 }; 162 splideMain.on("refresh", updateSlideHeightRefresh); 163 } 164 self.kt_thumb_slideHeight = () => { 165 self.$gallery.css("height", "auto"); 166 setTimeout(function () { 167 var imageheight = self.$gallery.find(".splide__track").height(); 168 self.$galleryThumbnails.css("height", imageheight); 169 self.$gallery.css("height", imageheight); 170 }, 30); 171 }; 172 if (current_layout === "left" || current_layout === "right") { 173 self.kt_thumb_slideHeight(); 174 splideMain.on("mounted", function () { 175 setTimeout(function () { 176 self.kt_thumb_slideHeight(); 177 }, 100); 178 }); 179 } 180 self.clear_slide_layout = ( 181 the_layout, 182 the_width, 183 the_columns, 184 the_count 185 ) => { 186 if (the_layout === "left") { 187 setTimeout(function () { 188 self.$galleryThumbnails.css("width", the_width + "%"); 189 self.$galleryThumbnails 190 .find(".thumb-wrapper") 191 .css("maxWidth", ""); 192 self.$gallery.css("margin-left", the_width + "%"); 193 self.$gallery.css("margin-right", ""); 194 }, 30); 195 setTimeout(function () { 196 //this is a backup in case the first timeout is still too early. 197 self.$gallery.css("margin-left", the_width + "%"); 198 self.$gallery.css("margin-right", ""); 199 }, 300); 200 self.kt_thumb_slideHeight(); 201 } else if (the_layout === "right") { 202 setTimeout(function () { 203 self.$galleryThumbnails.css("width", the_width + "%"); 204 self.$galleryThumbnails 205 .find(".thumb-wrapper") 206 .css("maxWidth", ""); 207 self.$gallery.css("margin-right", the_width + "%"); 208 self.$gallery.css("margin-left", ""); 209 }, 30); 210 setTimeout(function () { 211 //this is a backup in case the first timeout is still too early. 212 self.$gallery.css("margin-right", the_width + "%"); 213 self.$gallery.css("margin-left", ""); 214 }, 300); 215 self.kt_thumb_slideHeight(); 216 } else { 217 self.$gallery.css("margin-left", ""); 218 self.$gallery.css("margin-right", ""); 219 self.$gallery.css("height", ""); 220 self.$galleryThumbnails.css("height", ""); 221 self.$galleryThumbnails.css("width", ""); 222 if (the_count < the_columns) { 223 self.$galleryThumbnails 224 .find(".thumb-wrapper") 225 .css( 226 "maxWidth", 227 Math.floor((100 / the_columns) * the_count) + "%" 228 ); 229 } else { 230 self.$galleryThumbnails 231 .find(".thumb-wrapper") 232 .css("maxWidth", "none"); 233 } 234 } 235 }; 236 self.clear_slide_layout( 237 current_layout, 238 current_thumb_width, 239 current_thumbs_show, 240 items_count 241 ); 242 if (self.$galleryThumbnails.length) {
243 var thumbnails = new Splide(self.$galleryThumbnails[0], { 244 direction: 245 layout === "left" || layout === "right" 246 ? "ttb" 247 : sliderDirection, 248 focus: 249 splide_thumbs_center && 250 ((current_layout !== "left" && 251 current_layout !== "right") || 252 (items_count > splide_thumbs_show && 253 (current_layout === "left" || 254 current_layout === "right"))) 255 ? "center" 256 : undefined, 257 height: "100%", 258 perPage: 259 items_count < splide_thumbs_show && 260 layout !== "left" && 261 layout !== "right" 262 ? items_count 263 : splide_thumbs_show, 264 gap: splide_thumbs_gap, 265 rewind: true, 266 pagination: false, 267 isNavigation: true, 268 drag: false, 269 arrows: true, 270 breakpoints: { 271 767: { 272 direction: 273 smLayout === "left" || smLayout === "right" 274 ? "ttb" 275 : sliderDirection, 276 perPage: 277 items_count < splide_thumbs_mobile_show && 278 smLayout !== "left" && 279 smLayout !== "right" 280 ? items_count 281 : splide_thumbs_mobile_show, 282 gap: splide_thumbs_mobile_gap, 283 }, 284 1024: { 285 direction: 286 mdLayout === "left" || mdLayout === "right" 287 ? "ttb" 288 : sliderDirection, 289 perPage: 290 items_count < splide_thumbs_tablet_show && 291 mdLayout !== "left" && 292 mdLayout !== "right" 293 ? items_count 294 : splide_thumbs_tablet_show, 295 gap: splide_thumbs_tablet_gap, 296 }, 297 }, 298 }); 299 300 splideMain.sync(thumbnails); 301 splideMain.mount(); 302 thumbnails.mount(); 303 } else { 304 splideMain.mount(); 305 } 306 self.galleryChangeLayout = () => { 307 // Mobile. 308 if ($(window).width() < 769) { 309 self.clear_slide_layout( 310 smLayout, 311 splide_thumbs_mobile_width, 312 splide_thumbs_mobile_show, 313 items_count 314 ); 315 } else if ($(window).width() < 1024) { 316 self.clear_slide_layout( 317 mdLayout, 318 splide_thumbs_tablet_width, 319 splide_thumbs_tablet_show, 320 items_count 321 ); 322 } else { 323 self.clear_slide_layout( 324 layout, 325 splide_thumbs_width, 326 splide_thumbs_show, 327 items_count 328 ); 329 } 330 }; 331 var galleryLayoutResizeTimer; 332 $(window).on("resize", function () { 333 clearTimeout(galleryLayoutResizeTimer); 334 galleryLayoutResizeTimer = setTimeout( 335 self.galleryChangeLayout(), 336 100 337 ); 338 }); 339 self.galleryUpdateThumbHover = () => { 340 var galleryHoverClickTimer; 341 self.$galleryThumbnails.find(".splide__slide").hover(function () { 342 $thumb = $(this); 343 clearTimeout(galleryHoverClickTimer); 344 galleryHoverClickTimer = setTimeout(function () { 345 $thumb.trigger("click"); 346 }, 100); 347 }); 348 }; 349 if (splide_thumbs_on_hover && thumbnails) { 350 self.galleryUpdateThumbHover(); 351 } 352 353 self.init_product_zoom = () => { 354 $(".zoomContainer").remove(); 355 self.$gallery.find(".is-active img").removeData("elevateZoom"); 356 self.$gallery.find(".is-active img").removeData("zoomImage"); 357 self.$gallery.find(".is-active img").elevateZoom({ 358 zoomType: $zoom_type, 359 cursor: "crosshair", 360 zoomWindowFadeIn: 300, 361 zoomWindowFadeOut: 300, 362 }); 363 }; 364 if ( 365 $zoom && 366 !KadenceProductGalleryisMobile.any() && 367 $(window).width() > 790 368 ) { 369 splideMain.on("move", function () { 370 $(".zoomContainer").remove(); 371 }); 372 splideMain.on("moved", function () { 373 setTimeout(function () { 374 self.init_product_zoom(); 375 }, 100); 376 }); 377 var ktwoozoomresizeTimer; 378 $(window).on("resize", function () { 379 clearTimeout(ktwoozoomresizeTimer); 380 ktwoozoomresizeTimer = setTimeout(self.init_product_zoom, 200); 381 }); 382 self.init_product_zoom(); 383 } 384 self.init_product_lightbox = () => { 385 if (kadence_pg.lightbox) { 386 return GLightbox({ 387 selector: 388 "#pg-main-" + 389 product_id + 390 ' .splide__slide a[data-rel^="lightbox"]:not([target="_blank"])', 391 touchNavigation: true, 392 skin: kadence_pg.lightbox_style, 393 loop: true, 394 openEffect: "fade", 395 closeEffect: "fade", 396 autoplayVideos: true, 397 plyr: { 398 css: kadence_pg.plyr_css, 399 js: kadence_pg.plyr_js, 400 config: { 401 hideControls: true, 402 }, 403 }, 404 }); 405 } 406 }; 407 var glightbox = self.init_product_lightbox(); 408 self.reload_product_lightbox = () => { 409 if (kadence_pg.lightbox) { 410 if (glightbox) { 411 glightbox.reload(); 412 } 413 } 414 }; 415 $(".variations_form") 416 .find(".single_variation") 417 .on("show_variation", function (event, variation, purchasable) { 418 var $product_img_wrap = self.$gallery.find( 419 ".woocommerce-main-image" 420 ); 421 var $product_img = kadence_pg.lightbox 422 ? $product_img_wrap.find("img") 423 : self.$gallery.find(".woo-main-slide img"); 424 var $product_thumb_wrap = self.$galleryThumbnails.find( 425 ".woocommerce-main-image-thumb" 426 ); 427 var $product_thumb_img = $product_thumb_wrap.find("img"); 428 // Change zoom image 429 if ( 430 variation && 431 variation.image.src && 432 variation.image.src.length > 1 433 ) { 434 // See if the gallery has an image with the same original src as the image we want to switch to. 435 var galleryHasImage = 436 self.$gallery.find( 437 '.splide__slide img[data-o_src="' + 438 variation.image.src + 439 '"]' 440 ).length > 0; 441 // If the gallery has the image, reset the images. We'll scroll to the correct one. 442 if (galleryHasImage) { 443 self.kt_wc_variations_image_reset(); 444 } 445 // See if gallery has a matching image we can slide to.
446 var gal_non_retina = 447 variation.image.gallery_thumbnail_src.replace( 448 variation.image.gallery_thumbnail_src_w + 449 "x" + 450 variation.image.gallery_thumbnail_src_h, 451 Math.floor( 452 variation.image.gallery_thumbnail_src_w / 2 453 ) + 454 "x" + 455 Math.floor( 456 variation.image.gallery_thumbnail_src_h / 2 457 ) 458 ); 459 var slideToImage = self.$galleryThumbnails.find( 460 '.splide__slide img[src="' + gal_non_retina + '"]' 461 ); 462 if (slideToImage.length == 0) { 463 slideToImage = self.$galleryThumbnails.find( 464 '.splide__slide img[src="' + 465 variation.image.gallery_thumbnail_src + 466 '"]' 467 ); 468 } 469 470 if (slideToImage.length > 0 && !$datathumbs) { 471 //var galIndex = slideToImage.parent().data( 'slick-index' ) .trigger( 'click' ); 472 slideToImage.parent().trigger("click"); 473 if ( 474 self.$gallery.data("zoom-active") && 475 !KadenceProductGalleryisMobile.any() 476 ) { 477 $(".zoomContainer").remove(); 478 self.$gallery
479 .find(".is-active img") 480 .removeData("elevateZoom"); 481 self.$gallery 482 .find(".is-active img") 483 .removeData("zoomImage"); 484 self.$gallery.find(".is-active img").elevateZoom({ 485 zoomType: $zoom_type, 486 cursor: "crosshair", 487 zoomWindowFadeIn: 300, 488 zoomWindowFadeOut: 300, 489 }); 490 } 491 return; 492 } 493 494 // Go to first slide 495 var slideCount = splideMain.length; 496 if (1 < slideCount) { 497 splideMain.go(0); 498 } 499 $product_img.kt_wc_set_variation_attr( 500 "data-zoom-image", 501 variation.image.full_src 502 ); 503 $product_img.kt_wc_set_variation_attr( 504 "src", 505 variation.image.src 506 ); 507 if (variation.image.srcset) { 508 $product_img.kt_wc_set_variation_attr( 509 "srcset", 510 variation.image.srcset 511 ); 512 } else { 513 $product_img.kt_wc_set_variation_attr("srcset", ""); 514 } 515 if (variation.image.title) { 516 $product_img.kt_wc_set_variation_attr( 517 "title", 518 variation.image.title 519 ); 520 } else { 521 $product_img.kt_wc_set_variation_attr("title", ""); 522 } 523 if (variation.image.caption) { 524 $product_img.kt_wc_set_variation_attr( 525 "data-caption", 526 variation.image.caption 527 ); 528 } else { 529 $product_img.kt_wc_set_variation_attr( 530 "data-caption", 531 "" 532 ); 533 } 534 if (visible_captions === true) { 535 if (variation.image.caption) { 536 $product_img_wrap 537 .find(".sp-gal-image-caption") 538 .html(variation.image.caption); 539 $product_img_wrap 540 .find(".sp-gal-image-caption") 541 .fadeIn(); 542 } else { 543 $product_img_wrap 544 .find(".sp-gal-image-caption") 545 .fadeOut(); 546 } 547 } 548 if ($product_img_wrap.hasClass("kt-woo-video-link")) { 549 $product_img_wrap.find(".kt-woo-play-btn").hide(); 550 $product_thumb_wrap.find(".kt-woo-play-btn").hide(); 551 $product_img_wrap.removeClass("kt-woo-video-link"); 552 $product_img_wrap.addClass("kt-woo-orig-video-link"); 553 } 554 $product_img.kt_wc_set_variation_attr( 555 "alt", 556 variation.image.alt 557 ); 558 $product_img_wrap.kt_wc_set_variation_attr( 559 "href", 560 variation.image.full_src 561 ); 562 $product_thumb_img.kt_wc_set_variation_attr( 563 "src", 564 variation.image.gallery_thumbnail_src 565 ); 566 if (variation.image.gallery_thumbnail_srcset) { 567 $product_thumb_img.kt_wc_set_variation_attr( 568 "srcset", 569 variation.image.gallery_thumbnail_srcset 570 ); 571 } else { 572 $product_thumb_img.kt_wc_set_variation_attr( 573 "srcset", 574 "" 575 ); 576 } 577 $product_thumb_img.kt_wc_set_variation_attr( 578 "alt", 579 variation.image.alt 580 ); 581 if ($datathumbs) { 582 if ($datathumbs["is_ajax"]) { 583 self.kt_wc_variations_run_ajax_call( 584 variation.variation_id 585 ); 586 } else { 587 self.kt_wc_variations_run_thumbnails( 588 variation.variation_id 589 ); 590 } 591 } 592 splideMain.refresh(); 593 if ( 594 self.$gallery.data("zoom-active") && 595 !KadenceProductGalleryisMobile.any() 596 ) { 597 $(".zoomContainer").remove(); 598 self.$gallery
599 .find(".is-active img") 600 .removeData("elevateZoom"); 601 self.$gallery 602 .find(".is-active img") 603 .removeData("zoomImage"); 604 self.$gallery.find(".is-active img").elevateZoom({ 605 zoomType: $zoom_type, 606 cursor: "crosshair", 607 zoomWindowFadeIn: 300, 608 zoomWindowFadeOut: 300, 609 }); 610 } 611 self.reload_product_lightbox(); 612 } else { 613 self.kt_wc_variations_image_reset(); 614 } 615 }); 616 self.kt_wc_variations_original_thumbnails = () => { 617 if (thumbnails_have_changed) { 618 splideMain.remove(".splide__slide:not(.woo-main-slide)"); 619 splideMain.add($datathumbs["original"]["images"]); 620 items_count = original_items_count; 621 if (thumbnails) { 622 thumbnails.remove( 623 ".splide__slide:not(.woocommerce-main-image-thumb)" 624 ); 625 self.$galleryThumbnails.css("height", "auto"); 626 if ( 627 items_count < current_thumbs_show && 628 current_layout !== "left" && 629 current_layout !== "right" 630 ) { 631 thumbnails.options.perPage = items_count; 632 } else if ( 633 thumbnails.options.perPage < current_thumbs_show 634 ) { 635 thumbnails.options.perPage = current_thumbs_show; 636 if (splide_thumbs_center) { 637 thumbnails.options.focus = 638 (current_layout !== "left" && 639 current_layout !== "right") || 640 (items_count > current_thumbs_show && 641 (current_layout === "left" || 642 current_layout === "right")) 643 ? "center" 644 : undefined; 645 } 646 } else if ( 647 thumbnails.options.perPage >= current_thumbs_show 648 ) { 649 if (splide_thumbs_center) { 650 thumbnails.options.focus = 651 (current_layout !== "left" && 652 current_layout !== "right") || 653 (items_count > current_thumbs_show && 654 (current_layout === "left" || 655 current_layout === "right")) 656 ? "center" 657 : undefined; 658 } 659 } 660 thumbnails.add($datathumbs["original"]["thumbnails"]); 661 if (splide_thumbs_on_hover) { 662 self.galleryUpdateThumbHover(); 663 } 664 } 665 self.clear_slide_layout( 666 current_layout, 667 current_thumb_width, 668 current_thumbs_show, 669 original_items_count 670 ); 671 self.reload_product_lightbox(); 672 thumbnails_have_changed = false; 673 } 674 }; 675 self.kt_wc_variations_run_thumbnails = (variation_id) => { 676 if (false === $datathumbs[variation_id]) { 677 self.kt_wc_variations_original_thumbnails(); 678 } else { 679 self.kt_wc_variations_switch_thumbnails( 680 $datathumbs[variation_id] 681 ); 682 } 683 }; 684 self.kt_wc_variations_switch_thumbnails = (thumbnails_data) => { 685 thumbnails_have_changed = true; 686 splideMain.remove(".splide__slide:not(.woo-main-slide)"); 687 splideMain.add(thumbnails_data["images"]); 688 items_count = thumbnails_data["thumbnails"].length + 1; 689 if (thumbnails) { 690 thumbnails.remove( 691 ".splide__slide:not(.woocommerce-main-image-thumb)" 692 ); 693 self.$galleryThumbnails.css("height", "auto"); 694 if ( 695 items_count < current_thumbs_show && 696 current_layout !== "left" && 697 current_layout !== "right" 698 ) { 699 thumbnails.options.perPage = items_count; 700 } else if (thumbnails.options.perPage < current_thumbs_show) { 701 thumbnails.options.perPage = current_thumbs_show; 702 if (splide_thumbs_center) { 703 thumbnails.options.focus = 704 (current_layout !== "left" && 705 current_layout !== "right") || 706 (items_count > current_thumbs_show && 707 (current_layout === "left" || 708 current_layout === "right")) 709 ? "center" 710 : undefined; 711 } 712 } else if (thumbnails.options.perPage >= current_thumbs_show) { 713 if (splide_thumbs_center) { 714 thumbnails.options.focus = 715 (current_layout !== "left" && 716 current_layout !== "right") || 717 (items_count > current_thumbs_show && 718 (current_layout === "left" || 719 current_layout === "right")) 720 ? "center" 721 : undefined; 722 } 723 } 724 thumbnails.add(thumbnails_data["thumbnails"]); 725 if (splide_thumbs_on_hover) { 726 self.galleryUpdateThumbHover(); 727 } 728 } 729 self.clear_slide_layout( 730 current_layout, 731 current_thumb_width, 732 current_thumbs_show, 733 items_count 734 ); 735 self.reload_product_lightbox(); 736 }; 737 self.kt_wc_variations_run_ajax_call = (variation_id) => { 738 var $data = { 739 action: "kadence_variation_images_load_frontend_ajax", 740 ajaxkwsvNonce: kadence_pg.ajax_nonce, 741 variation_id: variation_id, 742 post_id: product_id, 743 }; 744 $.post(kadence_pg.ajax_url, $data, function (response) { 745 if (response.length) { 746 response = JSON.parse(response); 747 // replace with new image set 748 self.kt_wc_variations_switch_thumbnails(response); 749 } else { 750 // replace with original image set 751 self.kt_wc_variations_original_thumbnails(); 752 } 753 }); 754 }; 755 self.kt_wc_variations_image_reset = () => { 756 var $product_img_wrap = self.$gallery.find( 757 ".woocommerce-main-image" 758 ); 759 var $product_img = kadence_pg.lightbox 760 ? $product_img_wrap.find("img") 761 : self.$gallery.find(".woo-main-slide img"); 762 var $product_thumb_wrap = self.$galleryThumbnails.find( 763 ".woocommerce-main-image-thumb" 764 ); 765 var $product_thumb_img = $product_thumb_wrap.find("img"); 766 $product_img.kt_wc_reset_variation_attr("src"); 767 $product_img.kt_wc_reset_variation_attr("srcset"); 768 $product_img.kt_wc_reset_variation_attr("data-caption"); 769 $product_img.kt_wc_reset_variation_attr("alt");
770 if (visible_captions === true) { 771 if (undefined !== $product_img.attr("data-o_data-caption")) { 772 $product_img_wrap 773 .find(".sp-gal-image-caption") 774 .html($product_img.attr("data-o_data-caption")); 775 $product_img_wrap.find(".sp-gal-image-caption").fadeIn(); 776 } else { 777 $product_img_wrap.find(".sp-gal-image-caption").fadeOut(); 778 } 779 } 780 if ($product_img_wrap.hasClass("kt-woo-orig-video-link")) { 781 $product_img_wrap.addClass("kt-woo-video-link"); 782 $product_img_wrap.find(".kt-woo-play-btn").show(); 783 $product_thumb_wrap.find(".kt-woo-play-btn").show(); 784 $product_img_wrap.removeClass("kt-woo-orig-video-link"); 785 } 786 $product_img.kt_wc_reset_variation_attr("title"); 787 $product_img.kt_wc_reset_variation_attr("data-zoom-image"); 788 $product_thumb_img.kt_wc_reset_variation_attr("src"); 789 $product_thumb_img.kt_wc_reset_variation_attr("srcset"); 790 $product_thumb_img.kt_wc_reset_variation_attr("alt"); 791 $product_img_wrap.kt_wc_reset_variation_attr("href"); 792 self.kt_wc_variations_original_thumbnails(); 793 if ( 794 self.$gallery.data("zoom-active") && 795 !KadenceProductGalleryisMobile.any() 796 ) { 797 var slideCount = splideMain.length; 798 if (1 < slideCount) { 799 splideMain.go(0); 800 } 801 $(".zoomContainer").remove(); 802 self.$gallery.find(".is-active img").removeData("elevateZoom"); 803 self.$gallery.find(".is-active img").removeData("zoomImage"); 804 self.$gallery.find(".is-active img").elevateZoom({ 805 zoomType: $zoom_type, 806 cursor: "crosshair", 807 zoomWindowFadeIn: 300, 808 zoomWindowFadeOut: 300, 809 }); 810 } 811 splideMain.refresh(); 812 self.reload_product_lightbox(); 813 }; 814 $.fn.kt_wc_set_variation_attr = function (attr, value) { 815 if (undefined === this.attr("data-o_" + attr)) { 816 this.attr( 817 "data-o_" + attr, 818 !this.attr(attr) ? "" : this.attr(attr) 819 ); 820 } 821 this.attr(attr, value); 822 }; 823 $.fn.kt_wc_reset_variation_attr = function (attr) { 824 if (undefined !== this.attr("data-o_" + attr)) { 825 this.attr(attr, this.attr("data-o_" + attr)); 826 } 827 }; 828 $(".variations_form").on("click", ".reset_variations", function () { 829 self.kt_wc_variations_image_reset(); 830 }); 831 }; 832 /** 833 * Function to call kt_wc_product_gallery on jquery selector. 834 */ 835 $.fn.kt_wc_product_gallery = function () { 836 var $gallery = this; 837 if (!$gallery.hasClass("splide-initial")) { 838 if (typeof Splide === "function") { 839 new KadenceProductGallery($gallery); 840 } else { 841 // eslint-disable-next-line vars-on-top 842 var initLoadDelay = setInterval(function () { 843 if (typeof Splide === "function") { 844 new KadenceProductGallery($gallery); 845 clearInterval(initLoadDelay); 846 } 847 }, 200); 848 } 849 } 850 return this; 851 }; 852 // $.extend(true, $.magnificPopup.defaults, { 853 // tClose: '', 854 // tLoading: kadence_pg.loading, // Text that is displayed during loading. Can contain %curr% and %total% keys 855 // gallery: { 856 // tPrev: '', // Alt text on left arrow 857 // tNext: '', // Alt text on right arrow 858 // tCounter: kadence_pg.of // Markup for "1 of 7" counter 859 // }, 860 // image: { 861 // tError: kadence_pg.error, // Error message when image could not be loaded 862 // titleSrc: function(item) { 863 // return item.el.find('img').attr('alt'); 864 // } 865 // } 866 // }); 867 /* 868 * Initialize all galleries on page. 869 */ 870 window.initKaenceProductGalleries = () => { 871 $(".kadence-ga-splide-init").each(function () { 872 $(this).kt_wc_product_gallery(); 873 }); 874 }; 875 876 window.initKaenceProductGalleries(); 877 878 document.addEventListener("kb-query-loaded", function () { 879 window.initKaenceProductGalleries(); 880 }); 881 document.addEventListener("kt-quickview-load", function () { 882 window.initKaenceProductGalleries(); 883 }); 884});
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.