1var cgkit_load_swiper = false; 2var cgkit_gal_width = 0; 3var swiper = undefined; 4var swiper2 = undefined; 5var cgkit_first_slide = null; 6var cgkit_first_slide_x = 0; 7var cgkit_first_slide_y = 0; 8function loadGallery() { 9 10 var cg_layout = 'horizontal'; 11 var is_grid_layout = false; 12 var win_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; 13 if( commercekit_pdp.pdp_gallery_layout == 'vertical-left' || commercekit_pdp.pdp_gallery_layout == 'vertical-right' ){ 14 cg_layout = 'vertical'; 15 cgkitResizeThumbsHeight(0); 16 } 17 if( commercekit_pdp.pdp_gallery_layout == 'horizontal' || commercekit_pdp.pdp_gallery_layout == 'vertical-left' || commercekit_pdp.pdp_gallery_layout == 'vertical-right' ){ 18 cgkit_load_swiper = true; 19 } 20 if( ( commercekit_pdp.pdp_gallery_layout == 'grid-2-4' || commercekit_pdp.pdp_gallery_layout == 'grid-3-1-2' || commercekit_pdp.pdp_gallery_layout == 'grid-1-2-2' || commercekit_pdp.pdp_gallery_layout == 'vertical-scroll' || commercekit_pdp.pdp_gallery_layout == 'simple-scroll' ) && win_width <= 770 ){ 21 cgkit_load_swiper = true; 22 is_grid_layout = false; 23 } 24 if( ( commercekit_pdp.pdp_gallery_layout == 'grid-2-4' || commercekit_pdp.pdp_gallery_layout == 'grid-3-1-2' || commercekit_pdp.pdp_gallery_layout == 'grid-1-2-2' || commercekit_pdp.pdp_gallery_layout == 'vertical-scroll' || commercekit_pdp.pdp_gallery_layout == 'simple-scroll' ) && win_width > 770 ){ 25 cgkit_load_swiper = false;
26 is_grid_layout = true; 27 } 28 var mb10 = document.querySelector('#commercegurus-pdp-gallery'); 29 if( mb10 ){ 30 mb10.classList.remove('cgkit-mb10'); 31 mb10.classList.remove('cgkit-layout-'+commercekit_pdp.pdp_thumbnails); 32 mb10.style.visibility = 'visible'; 33 var layout_class = mb10.getAttribute('data-layout-class'); 34 if( layout_class ){ 35 if( is_grid_layout ){ 36 if( cgkit_load_swiper ){ 37 mb10.classList.remove(layout_class); 38 mb10.classList.add('cg-layout-horizontal'); 39 } else { 40 mb10.classList.remove('cg-layout-horizontal'); 41 mb10.classList.add(layout_class); 42 cgkitClearSwiperSlides(); 43 } 44 } else { 45 if( win_width <= 770 ){ 46 mb10.classList.remove(layout_class); 47 mb10.classList.add('cg-layout-horizontal'); 48 cg_layout = 'horizontal'; 49 } else { 50 mb10.classList.add(layout_class); 51 mb10.classList.remove('cg-layout-horizontal'); 52 } 53 cgkitClearSwiperSlides(); 54 } 55 } 56 } else { 57 return; 58 } 59 var pictures = document.querySelectorAll('#commercegurus-pdp-gallery .cg-main-swiper .swiper-slide picture source'); 60 pictures.forEach(function(picture){ 61 var srcset = picture.getAttribute('srcset'); 62 var dsrcset = picture.getAttribute('data-srcset'); 63 if( srcset && dsrcset && srcset.indexOf('spacer.png') >= 0 ){ 64 picture.setAttribute('srcset', dsrcset); 65 } 66 }); 67 var imgs = document.querySelectorAll('#commercegurus-pdp-gallery .cg-main-swiper .swiper-slide img'); 68 var gal_main = document.querySelector('#commercegurus-pdp-gallery .cg-main-swiper'); 69 if( gal_main ){ 70 cgkit_gal_width = gal_main.clientWidth; 71 } 72 imgs.forEach(function(img){ 73 cgkitUpdateSwiperImageHeight(img); 74 }); 75 if( commercekit_pdp.pdp_gallery_layout == 'vertical-scroll' || commercekit_pdp.pdp_gallery_layout == 'simple-scroll' ) { 76 var main_lis = document.querySelectorAll('#commercegurus-pdp-gallery .cg-main-swiper li'); 77 var main_index = 0; 78 main_lis.forEach(function(main_li){ 79 main_li.setAttribute('data-index', main_index++); 80 }); 81 if( commercekit_pdp.pdp_gallery_layout == 'vertical-scroll' ) { 82 var thumb_lis = document.querySelectorAll('#commercegurus-pdp-gallery .cg-thumb-swiper li'); 83 var thumb_index = 0; 84 thumb_lis.forEach(function(thumb_li){ 85 if( win_width > 770 ){ 86 thumb_li.classList.add('cgkit-vertical-scroll-thumb'); 87 } else { 88 thumb_li.classList.remove('cgkit-vertical-scroll-thumb'); 89 } 90 if( thumb_index == 0 ){ 91 thumb_li.classList.add('active'); 92 } 93 thumb_li.setAttribute('data-index', thumb_index++); 94 }); 95 } 96 } 97 if( commercekit_pdp.pdp_gallery_layout == 'vertical-scroll' || commercekit_pdp.pdp_gallery_layout == 'simple-scroll' ) { 98 var main_imgs = document.querySelectorAll('#commercegurus-pdp-gallery .cg-main-swiper .swiper-slide img'); 99 main_imgs.forEach(function(main_img){ 100 var src = main_img.getAttribute('src'); 101 var dsrc = main_img.getAttribute('data-src'); 102 var dsset = main_img.getAttribute('data-srcset'); 103 if( src && src.indexOf('spacer.png') >= 0 && dsrc ){ 104 main_img.setAttribute('src', dsrc); 105 main_img.setAttribute('srcset', dsset); 106 } 107 }); 108 var vs_thumbs = document.querySelector('#commercegurus-pdp-gallery .cg-thumb-swiper'); 109 var cgkit_sticky_nav = document.querySelector('body.sticky-d .col-full-nav'); 110 if( vs_thumbs && cgkit_sticky_nav && commercekit_pdp.pdp_sticky_atc != 1 ){ 111 if( window.innerWidth > 992 ){ 112 var old_top = vs_thumbs.getAttribute('data-top'); 113 if( !old_top ){ 114 old_top = parseInt(getComputedStyle(vs_thumbs).getPropertyValue('top')); 115 vs_thumbs.setAttribute('data-top', old_top); 116 } 117 var new_top = parseInt(old_top) + cgkit_sticky_nav.clientHeight; 118 vs_thumbs.setAttribute('style', 'top: ' + new_top + 'px;' ); 119 } else { 120 vs_thumbs.setAttribute('style', 'top: unset;' ); 121 } 122 } 123 } 124 var pdp_thumbnails = commercekit_pdp.pdp_thumbnails; 125 if( win_width <= 770 ){ 126 pdp_thumbnails = commercekit_pdp.pdp_m_thumbs; 127 } 128 if( commercekit_pdp.pdp_gallery_layout == 'vertical-left' || commercekit_pdp.pdp_gallery_layout == 'vertical-right' ){ 129 if( mb10 ){ 130 mb10.classList.remove('cgkit-vlayout-'+commercekit_pdp.pdp_v_thumbs); 131 } 132 if( win_width > 770 ){ 133 pdp_thumbnails = commercekit_pdp.pdp_v_thumbs; 134 } 135 var thumb_lis = document.querySelectorAll('#commercegurus-pdp-gallery .cg-thumb-swiper .swiper-slide'); 136 var thumb_wrap = document.querySelector('#commercegurus-pdp-gallery .cg-thumb-swiper'); 137 if( thumb_wrap && thumb_lis.length > 0 ){ 138 var thumb_width = thumb_lis[0].clientWidth; 139 if( win_width > 770 ){ 140 var thumbs_height = thumb_width * thumb_lis.length; 141 var vert_first_slide = document.querySelector('#commercegurus-pdp-gallery .cg-main-swiper li.swiper-slide:first-child img'); 142 if( vert_first_slide ){ 143 var vertical_height = vert_first_slide.clientHeight; 144 if( vertical_height ){
145 thumbs_height = Math.min(vertical_height, thumbs_height); 146 } 147 } 148 thumb_wrap.style.height = thumbs_height + 'px'; 149 pdp_thumbnails = 'auto'; 150 } else { 151 thumb_wrap.style.height = ''; 152 } 153 } 154 } 155 if( cgkit_load_swiper ) { 156 var items = document.querySelectorAll('.cg-main-swiper .swiper-slide'); 157 items.forEach(function(item){ 158 item.classList.remove('less-images'); 159 item.classList.remove('more-images'); 160 }); 161 var load_more = document.querySelector('.cg-main-swiper .load-more-images'); 162 if( load_more ){ 163 load_more.style.display = 'none'; 164 load_more.classList.add('more'); 165 load_more.classList.remove('less'); 166 load_more.innerHTML = load_more.getAttribute('data-more'); 167 } 168 // Swiper init. 169 if( cg_layout == 'vertical1' ){ 170 // Vertical 171 swiper = new Swiper662(".cg-thumb-swiper", { 172 lazy: true, 173 preloadImages: false, 174 slidesPerView: pdp_thumbnails, 175 grabCursor: true, 176 cssmode: true, 177 watchSlidesVisibility: true, 178 watchSlidesProgress: true, 179 spaceBetween: 10, 180 direction: cg_layout, 181 keyboard: { 182 enabled: true, 183 }, 184 }); 185 } else { 186 // Horizontal 187 swiper = new Swiper662(".cg-thumb-swiper", { 188 lazy: true, 189 preloadImages: false, 190 threshold: 2, 191 slidesPerView: pdp_thumbnails, 192 centerInsufficientSlides: true, 193 grabCursor: true, 194 cssmode: true, 195 watchSlidesVisibility: true, 196 watchSlidesProgress: true, 197 direction: cg_layout, 198 keyboard: { 199 enabled: true, 200 }, 201 }); 202 } 203 204 var space_between = 0; 205 var slides_per_view = 1; 206 var gall_lis = document.querySelectorAll('#commercegurus-pdp-gallery .cg-main-swiper li'); 207 if( commercekit_pdp.pdp_mobile_layout == 'show-edge' && win_width <= 770 && gall_lis.length > 1 ){ 208 space_between = 10; 209 slides_per_view = commercekit_pdp.pdp_showedge_percent; 210 } 211 swiper2 = new Swiper662(".cg-main-swiper", { 212 autoHeight: true, 213 lazy: { 214 loadPrevNext: true, 215 preloaderClass: 'cg-swiper-preloader', 216 loadPrevNextAmount: 1, 217 }, 218 preloadImages: false, 219 threshold: 2, 220 cssmode: true, 221 spaceBetween: space_between, 222 slidesPerView: slides_per_view, 223 navigation: { 224 nextEl: ".swiper-button-next", 225 prevEl: ".swiper-button-prev", 226 }, 227 thumbs: { 228 swiper: swiper, 229 }, 230 watchOverflow: true, 231 observer: true, 232 observeParents: true, 233 keyboard: { 234 enabled: true, 235 }, 236 }); 237 238 swiper2.on('slideChangeTransitionEnd', function (){ 239 setTimeout(function(){cgkitPausePlayedVideos();}, 200); 240 setTimeout(function(){cgkitLoadMissingSwiperImages();}, 2000); 241 }); 242 243 if( cg_layout == 'vertical1' ){ 244 swiper2.on('slideChangeTransitionStart', function() { 245 swiper.slideTo(swiper2.activeIndex); 246 }); 247 swiper.on('transitionStart', function(){ 248 swiper2.slideTo(swiper.activeIndex); 249 }); 250 swiper2.on('slideChangeTransitionEnd', function() { 251 cgkitResizeThumbsHeight(1); 252 }); 253 } 254 } else { 255 var grid_count = 8; 256 if( commercekit_pdp.pdp_gallery_layout == 'grid-3-1-2' ) { 257 grid_count = 6 258 } 259 if( commercekit_pdp.pdp_gallery_layout == 'grid-1-2-2' ) { 260 grid_count = 5 261 } 262 var item_count = 0; 263 var items = document.querySelectorAll('.cg-main-swiper .swiper-slide'); 264 items.forEach(function(item){ 265 item_count++; 266 item.classList.remove('less-images'); 267 item.classList.remove('more-images'); 268 if( item_count <= grid_count ){ 269 item.classList.add('less-images'); 270 } else { 271 item.classList.add('more-images'); 272 } 273 }); 274 var load_more = document.querySelector('.cg-main-swiper .load-more-images'); 275 if( load_more ){ 276 if( items.length > grid_count ){ 277 load_more.style.display = 'block'; 278 } else { 279 load_more.style.display = 'none'; 280 } 281 } 282 283 var items = document.querySelectorAll('.cg-main-swiper .swiper-slide.less-images .swiper-lazy'); 284 items.forEach(function(item){ 285 if( !item.classList.contains('loaded') ){ 286 var dsrc = item.getAttribute('data-src'); 287 if( dsrc ){ 288 item.setAttribute('src', dsrc); 289 item.classList.add('loaded'); 290 } 291 } 292 }); 293 } 294 // Photoswipe init. 295 var initPhotoSwipeFromDOM = function(gallerySelector) { 296 // parse slide data (url, title, size ...) from DOM elements 297 // (children of gallerySelector) 298 var parseThumbnailElements = function(el) { 299 var thumbElements = el.childNodes, 300 numNodes = thumbElements.length, 301 items = [], 302 figureEl, 303 linkEl, 304 size, 305 item; 306 307 for (var i = 0; i < numNodes; i++) { 308 figureEl = thumbElements[i]; // <figure> element 309 310 // include only element nodes 311 if (figureEl.nodeType !== 1) { 312 continue; 313 } 314 315 linkEl = figureEl.children[0]; // <a> element 316 317 size = linkEl.getAttribute("data-size").split("x"); 318 319 if( linkEl.classList.contains('cgkit-video') ){ 320 // create video slide object 321 var video_html = linkEl.getAttribute('data-html'); 322 video_html = video_html.replace(/</g, '<'); 323 video_html = video_html.replace(/>/g, '>'); 324 video_html = video_html.replace(/"/g, '"'); 325 item = { 326 html: video_html 327 } 328 } else { 329 // create slide object 330 var img_alt = ''; 331 var img_title = ''; 332 var imgEl = linkEl.querySelector('img'); 333 if( imgEl ){ 334 img_alt = imgEl.getAttribute('alt'); 335 if( commercekit_pdp.pdp_lightbox_cap ){ 336 img_title = imgEl.getAttribute('data-caption') ? imgEl.getAttribute('data-caption') : imgEl.getAttribute('title'); 337 } 338 } 339 item = { 340 src: linkEl.getAttribute("href"), 341 w: parseInt(size[0], 10), 342 h: parseInt(size[1], 10), 343 alt: img_alt, 344 title: img_title 345 }; 346 347 if (figureEl.children.length > 1) { 348 // <figcaption> content 349 item.title = figureEl.children[1].innerHTML; 350 } 351 352 if (linkEl.children.length > 0) { 353 // <img> thumbnail element, retrieving thumbnail url 354 item.msrc = linkEl.children[0].getAttribute("src"); 355 } 356 } 357 358 item.el = figureEl; // save link to element for getThumbBoundsFn 359 items.push(item); 360 } 361 362 return items; 363 }; 364 365 // find nearest parent element 366 var closest = function closest(el, fn) { 367 return el && (fn(el) ? el : closest(el.parentNode, fn)); 368 }; 369 370 // triggers when user clicks on thumbnail 371 var onThumbnailsClick = function(e) { 372 e = e || window.event; 373 e.preventDefault ? e.preventDefault() : (e.returnValue = false); 374 375 var eTarget = e.target || e.srcElement; 376 377 var input = e.target; 378 var inputp = input.closest('.cgkit-video-play'); 379 if( input.classList.contains('cgkit-video-play') || inputp ){ 380 return; 381 } 382 383 // find root element of slide 384 var clickedListItem = closest(eTarget, function(el) { 385 return el.tagName && el.tagName.toUpperCase() === "LI"; 386 }); 387 388 if (!clickedListItem) { 389 return; 390 } 391 392 // find index of clicked item by looping through all child nodes 393 // alternatively, you may define index via data- attribute 394 var clickedGallery = clickedListItem.parentNode, 395 childNodes = clickedListItem.parentNode.childNodes, 396 numChildNodes = childNodes.length, 397 nodeIndex = 0, 398 index; 399 400 for (var i = 0; i < numChildNodes; i++) { 401 if (childNodes[i].nodeType !== 1) { 402 continue; 403 } 404 405 if (childNodes[i] === clickedListItem) { 406 index = nodeIndex; 407 break; 408 } 409 nodeIndex++; 410 } 411 412 if (index >= 0 && commercekit_pdp.pdp_lightbox) {
413 // open PhotoSwipe if valid index found 414 openPhotoSwipe(index, clickedGallery); 415 } 416 return false; 417 }; 418 419 // parse picture index and gallery index from URL (#&pid=1&gid=2) 420 var photoswipeParseHash = function() { 421 var hash = window.location.hash.substring(1), 422 params = {}; 423 424 if (hash.length < 5) { 425 return params; 426 } 427 428 var vars = hash.split("&"); 429 for (var i = 0; i < vars.length; i++) { 430 if (!vars[i]) { 431 continue; 432 } 433 var pair = vars[i].split("="); 434 if (pair.length < 2) { 435 continue; 436 } 437 params[pair[0]] = pair[1]; 438 } 439 440 if (params.gid) { 441 params.gid = parseInt(params.gid, 10); 442 } 443 444 return params; 445 }; 446 447 var openPhotoSwipe = function( 448 index, 449 galleryElement, 450 disableAnimation, 451 fromURL 452 ) { 453 var pswpElement = document.querySelectorAll(".pswp")[0], 454 gallery, 455 options, 456 items; 457 458 items = parseThumbnailElements(galleryElement); 459 460 // Photoswipe options. 461 options = { 462 /* "showHideOpacity" uncomment this If dimensions of your small thumbnail don't match dimensions of large image */ 463 //showHideOpacity:true, 464 465 // Buttons/elements 466 closeEl: true, 467 captionEl: true, 468 fullscreenEl: true, 469 zoomEl: true, 470 shareEl: false, 471 counterEl: false, 472 arrowEl: true, 473 preloaderEl: true, 474 // define gallery index (for URL) 475 galleryUID: galleryElement.getAttribute("data-pswp-uid"), 476 getThumbBoundsFn: function(index) { 477 // See Options -> getThumbBoundsFn section of documentation for more info 478 var thumbnail = items[index].el.getElementsByTagName("img")[0]; // find thumbnail 479 if( !thumbnail ){ 480 thumbnail = items[index].el.getElementsByTagName("video")[0]; // find thumbnail 481 if( !thumbnail ){ 482 thumbnail = items[index].el.getElementsByTagName("iframe")[0]; // find thumbnail 483 } 484 } 485 pageYScroll = window.pageYOffset || document.documentElement.scrollTop; 486 rect = thumbnail.getBoundingClientRect(); 487 488 return { x: rect.left, y: rect.top + pageYScroll, w: rect.width }; 489 } 490 }; 491 492 // PhotoSwipe opened from URL 493 if (fromURL) { 494 if (options.galleryPIDs) { 495 // parse real index when custom PIDs are used 496 // http://photoswipe.com/documentation/faq.html#custom-pid-in-url 497 for (var j = 0; j < items.length; j++) { 498 if (items[j].pid == index) { 499 options.index = j; 500 break; 501 } 502 } 503 } else { 504 // in URL indexes start from 1 505 options.index = parseInt(index, 10) - 1; 506 } 507 } else { 508 options.index = parseInt(index, 10); 509 } 510 511 // exit if index not found 512 if (isNaN(options.index)) { 513 return; 514 } 515 516 if (disableAnimation) { 517 options.showAnimationDuration = 0; 518 } 519 520 // Pass data to PhotoSwipe and initialize it 521 gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options); 522 gallery.init(); 523 524 /* Additional swiperjs/photoswipe integration - 525 1/2. UPDATE SWIPER POSITION TO THE CURRENT ZOOM_IN IMAGE (BETTER UI) */ 526 // photoswipe event: Gallery unbinds events 527 // (triggers before closing animation) 528 gallery.listen("unbindEvents", function() { 529 // The index of the current photoswipe slide 530 var getCurrentIndex = gallery.getCurrentIndex(); 531 // Update position of the slider 532 if( cgkit_load_swiper ){ 533 swiper2.slideTo(getCurrentIndex, 0, false); 534 } 535 // 2/2. Start swiper autoplay (on close - if swiper autoplay is true) 536 //swiper2.autoplay.start(); 537 }); 538 // 2/2. swiper autoplay stop when image in zoom mode (When lightbox is open) */ 539 gallery.listen('initialZoomIn', function() { 540 if( cgkit_load_swiper ) { 541 if(swiper2.autoplay.running){ 542 swiper2.autoplay.stop(); 543 } 544 } 545 }); 546 gallery.listen('beforeChange', function () { 547 cgkitAddPhotoSwiperEvents(); 548 }); 549 gallery.listen('afterChange', function () { 550 cgkitAddPhotoSwiperEvents(); 551 }); 552 gallery.listen('close', function () { 553 setTimeout(function(){ 554 var pswp = document.querySelector('#pswp'); 555 if( pswp ){ 556 pswp.className = 'pswp'; 557 } 558 }, 400); 559 }); 560 cgkitAddPhotoSwiperEvents(); 561 }; 562 563 var videos2 = document.querySelectorAll('.cgkit-video-wrap video'); 564 videos2.forEach(function(video){ 565 video.addEventListener('loadeddata', function(e){ 566 var input = e.target; 567 var parent = input.closest('.cgkit-video-wrap'); 568 cgkitVideoResizeHeight(parent, input, this.videoWidth, this.videoHeight); 569 }); 570 video.addEventListener('play', function(e){ 571 var input = e.target; 572 var parent = input.closest('.cgkit-video-wrap'); 573 cgkitVideoResizeHeight(parent, input, this.videoWidth, this.videoHeight); 574 }); 575 video.addEventListener('pause', function(e){ 576 var input = e.target; 577 var parent = input.closest('.cgkit-video-wrap'); 578 cgkitVideoResizeHeight(parent, input, this.videoWidth, this.videoHeight); 579 }); 580 }); 581 582 // loop through all gallery elements and bind events 583 var galleryElements = document.querySelectorAll(gallerySelector); 584 585 for (var i = 0, l = galleryElements.length; i < l; i++) { 586 galleryElements[i].setAttribute("data-pswp-uid", i + 1); 587 galleryElements[i].onclick = onThumbnailsClick; 588 } 589 590 // Parse URL and open gallery if it contains #&pid=3&gid=1 591 var hashData = photoswipeParseHash(); 592 if (hashData.pid && hashData.gid && commercekit_pdp.pdp_lightbox) { 593 openPhotoSwipe(hashData.pid, galleryElements[hashData.gid - 1], true, true); 594 } 595 }; 596 597 // execute above function. 598 initPhotoSwipeFromDOM(".cg-psp-gallery"); 599 var thbImage = document.querySelector("ul.swiper-wrapper.flex-control-nav li:first-child img"); 600 if( thbImage ) { 601 observer = new MutationObserver((changes) => {
602 changes.forEach(change => { 603 if(change.attributeName.includes('src')){ 604 var img = document.querySelector('#commercegurus-pdp-gallery .cg-main-swiper .swiper-slide:first-child img'); 605 if( img ) { 606 cgkitUpdateSwiperImageHeight(img); 607 } 608 if( cgkit_load_swiper ) { 609 swiper2.slideTo(0, 500, false); 610 } 611 } 612 }); 613 }); 614 observer.observe(thbImage, {attributes : true}); 615 } 616 617 var thbForm = document.querySelector("form.variations_form"); 618 if( thbForm ) { 619 observer2 = new MutationObserver((changes) => { 620 changes.forEach(change => { 621 if(change.attributeName.includes('current-image')){ 622 var vid = thbForm.getAttribute('current-image'); 623 if( vid == '' || vid == undefined ) { 624 if( cgkit_load_swiper ) { 625 swiper2.slideTo(0, 500, false); 626 } 627 } else { 628 var thumb = document.querySelector('li.swiper-slide[data-variation-id="'+vid+'"]'); 629 if( thumb ){ 630 var index = thumb.getAttribute('data-index'); 631 if( cgkit_load_swiper ) { 632 swiper2.slideTo(index, 500, false); 633 } 634 } 635 } 636 var thbImage2 = document.querySelector("ul.swiper-wrapper.flex-control-nav li:first-child img"); 637 if( thbImage2 ) { 638 thbImage2.setAttribute('srcset', ''); 639 thbImage2.setAttribute('sizes', ''); 640 } 641 } 642 }); 643 }); 644 observer2.observe(thbForm, {attributes : true}); 645 } 646 if( cg_layout == 'vertical' ){ 647 var mainWrap = document.querySelector('ul.swiper-wrapper.cg-psp-gallery'); 648 if( mainWrap ) { 649 observer = new MutationObserver((changes) => {
650 changes.forEach(change => { 651 if(change.attributeName.includes('style')){ 652 if( cgkit_load_swiper ) { 653 var curobj = document.querySelector('ul.swiper-wrapper.cg-psp-gallery'); 654 if( curobj ){ 655 var parent = curobj.closest('.cg-main-swiper'); 656 if( parent ){ 657 parent.style.height = curobj.offsetHeight+'px'; 658 } 659 } 660 } 661 } 662 }); 663 }); 664 observer.observe(mainWrap, {attributes : true}); 665 } 666 } 667 cgkit_prepare_clone_arrows(); 668 cgkitLazyVideosObserver(); 669} 670 671const galleryUserInteractionEvents = ["mouseover", "keydown", "touchstart", "touchmove", "wheel"]; 672galleryUserInteractionEvents.forEach(function(event) { 673 window.addEventListener(event, triggerGalleryScriptLoader, { 674 passive: !0 675 }) 676}); 677 678function triggerGalleryScriptLoader() { 679 loadGalleryScripts(); 680 galleryUserInteractionEvents.forEach(function(event) { 681 window.removeEventListener(event, triggerGalleryScriptLoader, { 682 passive: !0 683 }) 684 }) 685} 686 687function loadGalleryScripts() { 688 loadGallery(); 689 if( cgkit_first_slide ){ 690 cgkit_first_slide.removeEventListener('touchstart', cgkit_trigger_first_slide_start, !0); 691 cgkit_first_slide.removeEventListener('touchmove', cgkit_trigger_first_slide_move, !0); 692 } 693} 694function cgkitPausePlayedVideos(){ 695 var cgkit_videos = document.querySelectorAll('.swiper-slide-prev video, .swiper-slide-next video'); 696 cgkit_videos.forEach(function(cgkit_video){ 697 var parent = cgkit_video.closest('.cgkit-video-wrap'); 698 if( parent ){ 699 var iconPlay = parent.querySelector('svg.play'); 700 var iconPause = parent.querySelector('svg.pause'); 701 if( iconPlay && iconPause ){ 702 iconPlay.style.display = 'block'; 703 iconPause.style.display = 'none'; 704 cgkit_video.pause(); 705 } 706 } 707 }); 708 cgkit_video2 = document.querySelector('.swiper-slide-active video'); 709 if( cgkit_video2 ){ 710 if( cgkit_video2.classList.contains('cgkit-autoplay') ){ 711 var parent = cgkit_video2.closest('.cgkit-video-wrap'); 712 if( parent ){ 713 var iconPlay = parent.querySelector('svg.play'); 714 var iconPause = parent.querySelector('svg.pause'); 715 if( iconPlay && iconPause ){ 716 iconPlay.style.display = 'none'; 717 iconPause.style.display = 'block'; 718 cgkit_video2.play(); 719 } 720 } 721 } 722 } 723} 724function cgkitVideoTogglePlay(parent){ 725 var video = parent.querySelector('video'); 726 var iconPlay = parent.querySelector('svg.play'); 727 var iconPause = parent.querySelector('svg.pause'); 728 if( video && iconPlay && iconPause ){ 729 if( video.paused ) { 730 iconPlay.style.display = 'none'; 731 iconPause.style.display = 'block'; 732 video.play(); 733 } else { 734 iconPlay.style.display = 'block'; 735 iconPause.style.display = 'none'; 736 video.pause(); 737 } 738 } 739 var videoIcon = parent.querySelector('.cgkit-play'); 740 if( videoIcon ){ 741 videoIcon.classList.remove('not-autoplay'); 742 } 743} 744function cgkitVideoResizeHeight(parent, input, videoWidth, videoHeight){ 745 if( input.style.display != 'none' ){ 746 var pswp = input.closest('div.pswp__scroll-wrap'); 747 if( pswp ){ 748 var parentHeight = parent.offsetHeight; 749 var parentWidth = ( parentHeight / videoHeight ) * videoWidth; 750 parent.style.width = parentWidth+'px'; 751 input.style.width = parentWidth+'px'; 752 } else { 753 var parentWidth = parent.offsetWidth; 754 var parentHeight = ( parentWidth / videoWidth ) * videoHeight; 755 parent.style.height = parentHeight+'px'; 756 input.style.height = parentHeight+'px'; 757 var activeSlide = parent.closest('li.swiper-slide.swiper-slide-active'); 758 if( activeSlide ){ 759 document.querySelector('#cgkit-pdp-gallery-outside').click(); 760 } 761 } 762 } 763} 764function cgkitResizeThumbsHeight(active){ 765 return true; 766 var win_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; 767 if( win_width <= 770 ){ 768 return; 769 } 770 var thumbs = document.querySelector('.cg-thumb-swiper'); 771 var thumb_limit = commercekit_pdp.pdp_thumbnails; 772 var thumb_count = 0; 773 var total_height = 0; 774 if( active ){ 775 var item = document.querySelector('.cg-thumb-swiper .swiper-slide.swiper-slide-active'); 776 if( item ){ 777 var oitem = item; 778 var previus = false;
779 do { 780 thumb_count++; 781 total_height += item.offsetHeight; 782 var nitem = item.nextElementSibling; 783 if( nitem && !previus ){ 784 item = nitem; 785 } else { 786 if( !previus ){ 787 item = oitem; 788 } 789 var pitem = item.previousElementSibling; 790 if( pitem ){ 791 item = pitem; 792 previus = true; 793 } 794 } 795 } while ( thumb_count < thumb_limit ); 796 } 797 } else { 798 var items = document.querySelectorAll('.cg-thumb-swiper .swiper-slide'); 799 items.forEach(function(item){ 800 thumb_count++; 801 if( thumb_count <= thumb_limit ){ 802 total_height += item.offsetHeight; 803 } 804 }); 805 } 806 if( thumbs && total_height ){ 807 var margin_height = ( thumb_limit - 1 ) * 10; 808 thumbs.style.height = (total_height+margin_height)+'px'; 809 } 810} 811function cgkitUpdateSwiperImageHeight(img){ 812 var dsrc = img.getAttribute('data-src'); 813 var dosrc = img.getAttribute('data-opt-src'); 814 if( dosrc && dosrc.indexOf('spacer.png') >= 0 && dsrc ){ 815 img.setAttribute('data-opt-src', dsrc); 816 } 817 if( cgkit_gal_width && cgkit_load_swiper ){ 818 var img_width = parseInt(img.getAttribute('width')); 819 var img_height = parseInt(img.getAttribute('height')); 820 if( ! isNaN(img_width) && ! isNaN(img_width) ){ 821 var max_height = ( cgkit_gal_width / img_width ) * img_height; 822 img.style.height = max_height + 'px'; 823 } 824 } else { 825 img.style.height = ''; 826 } 827} 828function cgkitAddPhotoSwiperEvents(){ 829 var video2 = document.querySelector('.pswp__scroll-wrap .cgkit-video-wrap video'); 830 if( video2 ){ 831 var parent2 = video2.closest('.cgkit-video-wrap'); 832 cgkitVideoResizeHeight(parent2, video2, video2.videoWidth, video2.videoHeight); 833 } 834 var videos2 = document.querySelectorAll('.pswp__scroll-wrap .cgkit-video-wrap video'); 835 videos2.forEach(function(video){ 836 video.addEventListener('loadeddata', function(e){ 837 var input = e.target; 838 var parent = input.closest('.cgkit-video-wrap'); 839 cgkitVideoResizeHeight(parent, input, this.videoWidth, this.videoHeight); 840 }); 841 video.addEventListener('play', function(e){ 842 var input = e.target; 843 var parent = input.closest('.cgkit-video-wrap'); 844 cgkitVideoResizeHeight(parent, input, this.videoWidth, this.videoHeight); 845 }); 846 video.addEventListener('pause', function(e){ 847 var input = e.target; 848 var parent = input.closest('.cgkit-video-wrap'); 849 cgkitVideoResizeHeight(parent, input, this.videoWidth, this.videoHeight); 850 }); 851 }); 852} 853function cgkitClearSwiperSlides(){ 854 if( swiper != undefined && swiper2 != undefined ){ 855 swiper.destroy(); 856 swiper2.destroy(); 857 swiper = undefined; 858 swiper2 = undefined; 859 var swpwraps = document.querySelectorAll('#commercegurus-pdp-gallery ul.swiper-wrapper'); 860 swpwraps.forEach(function(swpwrap){ 861 swpwrap.removeAttribute('style'); 862 }); 863 var swpslds = document.querySelectorAll('#commercegurus-pdp-gallery li.swiper-slide'); 864 swpslds.forEach(function(swpsld){ 865 swpsld.removeAttribute('style'); 866 }); 867 } 868} 869function cgkitLoadMissingSwiperImages(){ 870 var cg_li = document.querySelector('.cg-main-swiper .swiper-slide.swiper-slide-active'); 871 if( cg_li ){ 872 var cg_imgs = cg_li.querySelectorAll('img'); 873 var rm_spin = false; 874 cg_imgs.forEach(function(cg_img){ 875 var src = cg_img.getAttribute('src'); 876 var dsrc = cg_img.getAttribute('data-src'); 877 var dsset = cg_img.getAttribute('data-srcset'); 878 if( cg_img.classList.contains('swiper-lazy-loading') && src && src.indexOf('spacer.png') >= 0 && dsrc ){ 879 cg_img.setAttribute('src', dsrc); 880 cg_img.setAttribute('srcset', dsset); 881 cg_img.classList.remove('swiper-lazy-loading'); 882 cg_img.classList.add('swiper-lazy-loaded'); 883 cg_img.addEventListener('load', function(e){ 884 document.querySelector('#cgkit-pdp-gallery-outside').click(); 885 }); 886 rm_spin = true; 887 } 888 }); 889 var cg_spin = cg_li.querySelector('.cg-swiper-preloader'); 890 if( cg_spin && rm_spin ){ 891 cg_spin.remove(); 892 } 893 } 894} 895if( document.querySelector('#commercegurus-pdp-gallery') ){ 896 var cgkit_win_width = window.innerWidth; 897 window.addEventListener('resize', function(e){ 898 if( cgkit_win_width == window.innerWidth ){ 899 return; 900 } 901 cgkit_win_width = window.innerWidth; 902 loadGallery(); 903 var videos2 = document.querySelectorAll('.cgkit-video-wrap video'); 904 videos2.forEach(function(video){ 905 var parent = video.closest('.cgkit-video-wrap'); 906 cgkitVideoResizeHeight(parent, video, video.videoWidth, video.videoHeight); 907 }); 908 if( commercekit_pdp.pdp_gallery_layout == 'vertical-left' || commercekit_pdp.pdp_gallery_layout == 'vertical-right' ){ 909 cgkitResizeThumbsHeight(1); 910 } 911 }); 912 document.addEventListener('click', function(e){ 913 var input = e.target; 914 if( input.classList.contains('load-more-images') ){ 915 if( input.classList.contains('more') ){ 916 input.classList.remove('more'); 917 input.classList.add('less'); 918 input.innerHTML = input.getAttribute('data-less'); 919 var items = document.querySelectorAll('.cg-main-swiper .swiper-slide.more-images .swiper-lazy');
920 items.forEach(function(item){ 921 if( !item.classList.contains('loaded') ){ 922 var dsrc = item.getAttribute('data-src'); 923 if( dsrc ){ 924 item.setAttribute('src', dsrc); 925 item.classList.add('loaded'); 926 } 927 } 928 }); 929 var items = document.querySelectorAll('.cg-main-swiper .swiper-slide.more-images'); 930 items.forEach(function(item){ 931 item.style.display = 'block'; 932 }); 933 } else { 934 input.classList.add('more'); 935 input.classList.remove('less'); 936 input.innerHTML = input.getAttribute('data-more'); 937 var items = document.querySelectorAll('.cg-main-swiper .swiper-slide.more-images'); 938 items.forEach(function(item){ 939 item.style.display = 'none'; 940 }); 941 document.querySelector('#commercegurus-pdp-gallery').scrollIntoView({block:'end'}); 942 } 943 } 944 }); 945 document.addEventListener('click', function(e){ 946 var input = e.target; 947 var inputp = input.closest('.cgkit-video-play'); 948 if( input.classList.contains('cgkit-video-play') || inputp ){ 949 if( inputp ){ 950 input = inputp; 951 } 952 e.preventDefault(); 953 e.stopPropagation(); 954 var parent = input.closest('.cgkit-video-wrap'); 955 var image = parent.querySelector('img'); 956 var video = parent.querySelector('video'); 957 if( image && video ){ 958 image.style.display = 'none'; 959 video.style.display = 'block'; 960 } 961 cgkitVideoTogglePlay(parent); 962 return false; 963 } 964 }); 965 var cgkit_var_image = false; 966 var thbImage2 = document.querySelector("ul.swiper-wrapper.flex-control-nav li:first-child img"); 967 if( thbImage2 ) { 968 observer2 = new MutationObserver((changes) => {
969 changes.forEach(change => { 970 if(change.attributeName.includes('src')){ 971 if( !cgkit_var_image ){ 972 loadGallery(); 973 cgkit_var_image = true; 974 } 975 } 976 }); 977 }); 978 observer2.observe(thbImage2, {attributes : true}); 979 } 980 var thbImage3 = document.querySelector("ul.swiper-wrapper.cg-psp-gallery li:first-child img"); 981 if( thbImage3 ) { 982 observer3 = new MutationObserver((changes) => { 983 changes.forEach(change => { 984 if(change.attributeName.includes('src')){ 985 if( !cgkit_var_image ){ 986 loadGallery(); 987 cgkit_var_image = true; 988 } 989 } 990 }); 991 }); 992 observer3.observe(thbImage3, {attributes : true}); 993 } 994 var thbImage4 = document.querySelector("form.variations_form"); 995 if( thbImage4 ) { 996 observer4 = new MutationObserver((changes) => { 997 changes.forEach(change => { 998 if(change.attributeName.includes('current-image')){ 999 if( !cgkit_var_image ){ 1000 loadGallery(); 1001 cgkit_var_image = true; 1002 } 1003 } 1004 }); 1005 }); 1006 observer4.observe(thbImage4, {attributes : true}); 1007 } 1008 var mb11 = document.querySelector('#commercegurus-pdp-gallery'); 1009 if( mb11 ){ 1010 var win_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; 1011 var layout_class = mb11.getAttribute('data-layout-class'); 1012 if( layout_class ){ 1013 if( win_width <= 770 ){ 1014 mb11.classList.remove(layout_class); 1015 mb11.classList.add('cg-layout-horizontal'); 1016 } else { 1017 mb11.classList.add(layout_class); 1018 mb11.classList.remove('cg-layout-horizontal'); 1019 } 1020 } 1021 } 1022 function cgkit_gal_image_activate( li_thumb ) { 1023 if ( li_thumb ) { 1024 if ( li_thumb.classList.contains('active') ) { 1025 return; 1026 } 1027 } 1028 li_thumb.classList.add('active'); 1029 cgkit_vertical_scroll_thumb_galery(li_thumb); 1030 var thumb_lis = document.querySelectorAll('#commercegurus-pdp-gallery .cg-thumb-swiper li'); 1031 thumb_lis.forEach(function(thumb_li){ 1032 if( thumb_li !== li_thumb ){ 1033 thumb_li.classList.remove('active'); 1034 } 1035 }); 1036 } 1037 function cgkit_vertical_scroll_thumb_galery(li_thumb) { 1038 if( commercekit_pdp.pdp_gallery_layout == 'vertical-left' || commercekit_pdp.pdp_gallery_layout == 'vertical-right' ){ 1039 var win_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; 1040 if( win_width > 770 ){ 1041 var topPos = li_thumb.offsetTop; 1042 var divContainer = document.querySelectorAll('.cg-thumb-swiper')[0]; 1043 divContainer.scrollTo({top: topPos, behavior: 'smooth'}); 1044 } 1045 } 1046 } 1047 function cgkit_gal_image_offset_top( elem ) { 1048 var offsetTop = 0; 1049 while ( elem ) { 1050 offsetTop += elem.offsetTop; 1051 elem = elem.offsetParent; 1052 } 1053 if ( window.innerWidth <= 992 ) { 1054 var cgkit_sticky_hdr = document.querySelector( commercekit_pdp.cgkit_sticky_hdr_class ); 1055 if ( cgkit_sticky_hdr ) { 1056 offsetTop = offsetTop - cgkit_sticky_hdr.clientHeight; 1057 } 1058 } else { 1059 var cgkit_sticky_nav = document.querySelector( 'body.sticky-d .col-full-nav' ); 1060 var cgkit_body = document.querySelector( 'body' ); 1061 if ( cgkit_sticky_nav && ! cgkit_body.classList.contains('ckit_stickyatc_active') ) { 1062 offsetTop = offsetTop - cgkit_sticky_nav.clientHeight; 1063 } 1064 } 1065 var difTop = 90; 1066 var summary = document.querySelector('#page div.product .summary'); 1067 if( summary ) { 1068 var sum_style = getComputedStyle(summary) 1069 difTop = sum_style.top; 1070 difTop = parseInt(difTop.replace('px',''))-30; 1071 } 1072 return offsetTop - difTop; 1073 } 1074 function cgkit_scroll_to_top_image() { 1075 if( commercekit_pdp.pdp_gallery_layout == 'vertical-scroll' || commercekit_pdp.pdp_gallery_layout == 'simple-scroll' ) { 1076 var main_li = document.querySelector('#commercegurus-pdp-gallery .cg-main-swiper li[data-index="0"]'); 1077 if( main_li ){ 1078 window.scroll( { 1079 behavior: 'smooth', 1080 left: 0, 1081 top: cgkit_gal_image_offset_top(main_li), 1082 } ); 1083 } 1084 } 1085 } 1086 if( commercekit_pdp.pdp_gallery_layout == 'vertical-scroll' ) { 1087 var cgkit_vsgal_click = false; 1088 var cgkit_vsgal_click_id = 0; 1089 document.addEventListener('click', function(e){ 1090 var input = e.target; 1091 var inputp = input.closest('.cgkit-vertical-scroll-thumb'); 1092 if( input.classList.contains('cgkit-vertical-scroll-thumb') || inputp ){ 1093 if( inputp ){ 1094 input = inputp; 1095 } 1096 e.preventDefault(); 1097 e.stopPropagation(); 1098 if( input.classList.contains('active') ){ 1099 return false;
1100 } 1101 cgkit_gal_image_activate(input); 1102 cgkit_vsgal_click = true; 1103 if ( ! cgkit_vsgal_click_id ) { 1104 cgkit_vsgal_click_id = setTimeout( function(){ cgkit_vsgal_click = false; cgkit_vsgal_click_id = 0; }, 1000 ); 1105 } else { 1106 clearTimeout( cgkit_vsgal_click_id ); 1107 cgkit_vsgal_click_id = setTimeout( function(){ cgkit_vsgal_click = false; cgkit_vsgal_click_id = 0; }, 1000 ); 1108 } 1109 var index = input.getAttribute('data-index'); 1110 var main_li = document.querySelector('#commercegurus-pdp-gallery .cg-main-swiper li[data-index="'+index+'"]'); 1111 if( main_li ){ 1112 window.scroll( { 1113 behavior: 'smooth', 1114 left: 0, 1115 top: cgkit_gal_image_offset_top(main_li), 1116 } ); 1117 } 1118 return false; 1119 } 1120 }); 1121 document.addEventListener('scroll', function(e) { 1122 if ( cgkit_vsgal_click ) { 1123 return 1124 } 1125 var cgkit_lis = document.querySelectorAll( '#commercegurus-pdp-gallery .cg-main-swiper li' ); 1126 cgkit_lis.forEach( function( cgkit_li ) { 1127 var li_start = cgkit_gal_image_offset_top( cgkit_li ); 1128 var li_end = cgkit_li.clientHeight + li_start; 1129 var index = cgkit_li.getAttribute('data-index'); 1130 var li_thumb = document.querySelector('#commercegurus-pdp-gallery .cg-thumb-swiper li[data-index="'+index+'"]'); 1131 if ( ! li_thumb ) { 1132 return; 1133 } 1134 if ( window.pageYOffset >= li_start && window.pageYOffset < li_end ) { 1135 cgkit_gal_image_activate( li_thumb ); 1136 return; 1137 } 1138 } ); 1139 } ); 1140 } 1141 document.addEventListener('DOMContentLoaded', function(){ 1142 var win_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; 1143 var items = document.querySelectorAll('#commercegurus-pdp-gallery .cg-main-swiper .swiper-slide.less-images .swiper-lazy'); 1144 items.forEach(function(item){ 1145 if( !item.classList.contains('loaded') ){ 1146 if( item.classList.contains('pdp-video') ){ 1147 if( win_width > 770 ){ 1148 var dsrc = item.getAttribute('data-src'); 1149 if( dsrc ){ 1150 item.setAttribute('src', dsrc); 1151 item.classList.add('loaded'); 1152 } 1153 } 1154 } 1155 } 1156 }); 1157 cgkit_first_slide = document.querySelector('#commercegurus-pdp-gallery .cg-main-swiper li.swiper-slide:first-child'); 1158 if( cgkit_first_slide ){ 1159 cgkit_first_slide.addEventListener('touchstart', cgkit_trigger_first_slide_start, !0); 1160 cgkit_first_slide.addEventListener('touchmove', cgkit_trigger_first_slide_move, !0); 1161 } 1162 if( commercekit_pdp.pdp_mobile_layout == 'show-edge' && win_width <= 770 ){ 1163 var second_img = document.querySelector('#commercegurus-pdp-gallery .cg-main-swiper .swiper-slide:nth-child(2) img'); 1164 if( second_img ){ 1165 var src = second_img.getAttribute('src'); 1166 var dsrc = second_img.getAttribute('data-src'); 1167 var dsset = second_img.getAttribute('data-srcset'); 1168 if( src && src.indexOf('spacer.png') >= 0 && dsrc ){ 1169 second_img.setAttribute('src', dsrc); 1170 second_img.setAttribute('srcset', dsset); 1171 } 1172 } 1173 } 1174 }); 1175 function cgkit_trigger_first_slide_start(e){ 1176 triggerGalleryScriptLoader(); 1177 cgkit_first_slide_x = e.touches[0].clientX; 1178 cgkit_first_slide_y = e.touches[0].clientY; 1179 } 1180 function cgkit_trigger_first_slide_move(e){ 1181 const moveX = e.touches[0].clientX; 1182 const moveY = e.touches[0].clientY; 1183 const diffX = moveX - cgkit_first_slide_x; 1184 const diffY = moveY - cgkit_first_slide_y; 1185 if( Math.abs(diffX) > Math.abs(diffY) ){ 1186 setTimeout(function(){ 1187 if( swiper != undefined && swiper2 != undefined ){ 1188 swiper.slideTo(1); 1189 swiper2.slideTo(1); 1190 } 1191 }, 200); 1192 e.preventDefault(); 1193 e.stopImmediatePropagation(); 1194 } 1195 if( cgkit_first_slide ){ 1196 cgkit_first_slide.removeEventListener('touchstart', cgkit_trigger_first_slide_start, !0); 1197 cgkit_first_slide.removeEventListener('touchmove', cgkit_trigger_first_slide_move, !0); 1198 } 1199 } 1200 function cgkit_prepare_clone_arrows(){ 1201 var main_next = document.querySelector('.cg-main-swiper .swiper-button-next'); 1202 var next_button = document.querySelector('.cg-thumb-swiper .swiper-button-next'); 1203 if( main_next && next_button ) { 1204 cgkit_update_clone_arrows( main_next, next_button ); 1205 next_observer = new MutationObserver((changes) => {
1206 changes.forEach(change => { 1207 if(change.attributeName.includes('class')){ 1208 cgkit_update_clone_arrows( main_next, next_button ); 1209 } 1210 }); 1211 }); 1212 next_observer.observe(main_next, {attributes : true}); 1213 } 1214 var main_prev = document.querySelector('.cg-main-swiper .swiper-button-prev'); 1215 var prev_button = document.querySelector('.cg-thumb-swiper .swiper-button-prev'); 1216 if( main_prev && prev_button ) { 1217 cgkit_update_clone_arrows( main_prev, prev_button ); 1218 prev_observer = new MutationObserver((changes) => { 1219 changes.forEach(change => { 1220 if(change.attributeName.includes('class')){ 1221 cgkit_update_clone_arrows( main_prev, prev_button ); 1222 } 1223 }); 1224 }); 1225 prev_observer.observe(main_prev, {attributes : true}); 1226 } 1227 } 1228 function cgkit_update_clone_arrows( $main, $button ){ 1229 if( $main.classList.contains('swiper-button-disabled') ){ 1230 $button.classList.add('swiper-button-disabled'); 1231 } else { 1232 $button.classList.remove('swiper-button-disabled'); 1233 } 1234 } 1235 document.addEventListener('click', function(e){ 1236 var input = e.target; 1237 var inputp = input.closest('.cg-thumb-swiper'); 1238 if( input.classList.contains('swiper-button-next') && inputp ){ 1239 e.preventDefault(); 1240 e.stopPropagation(); 1241 var main_next = document.querySelector('.cg-main-swiper .swiper-button-next'); 1242 if( main_next ){ 1243 main_next.click(); 1244 } 1245 } 1246 if( input.classList.contains('swiper-button-prev') && inputp ){ 1247 e.preventDefault(); 1248 e.stopPropagation(); 1249 var main_prev = document.querySelector('.cg-main-swiper .swiper-button-prev'); 1250 if( main_prev ){ 1251 main_prev.click(); 1252 } 1253 } 1254 }); 1255 function cgkitLazyVideosObserver(){ 1256 var lazyVideos = [].slice.call(document.querySelectorAll('video.cgkit-lazy, img.cgkit-lazy')); 1257 if( "IntersectionObserver" in window ){ 1258 var lazyVideoObserver = new IntersectionObserver(function(entries, observer) { 1259 entries.forEach(function(entry){ 1260 if( entry.isIntersecting ){ 1261 var video = null; 1262 if( typeof entry.target.tagName === 'string' && entry.target.tagName === 'IMG' ){ 1263 var videoWrap = entry.target.closest('.cgkit-video-wrap'); 1264 if( videoWrap ){ 1265 video = videoWrap.querySelector('video'); 1266 } 1267 } else { 1268 video = entry.target; 1269 } 1270 if( video ){ 1271 for( var source in video.children ){ 1272 var videoSource = video.children[source]; 1273 if( typeof videoSource.tagName === 'string' && videoSource.tagName === 'SOURCE') { 1274 videoSource.src = videoSource.dataset.src; 1275 } 1276 } 1277 video.load(); 1278 } 1279 entry.target.classList.remove('cgkit-lazy'); 1280 lazyVideoObserver.unobserve(entry.target); 1281 } 1282 }); 1283 }); 1284 lazyVideos.forEach(function(lazyVideo) { 1285 lazyVideoObserver.observe(lazyVideo); 1286 }); 1287 } 1288 } 1289}
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.