Guest User

Untitled

a guest
Dec 23rd, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*!
  2.  * Additional Variation Images Gallery for WooCommerce v1.2.9
  3.  *
  4.  * Author: Emran Ahmed ( [email protected] )
  5.  * Date: 12/9/2021, 5:02:20 PM
  6.  * Released under the GPLv3 license.
  7.  */
  8. /******/ (function(modules) { // webpackBootstrap
  9. /******/    // The module cache
  10. /******/    var installedModules = {};
  11. /******/
  12. /******/    // The require function
  13. /******/    function __webpack_require__(moduleId) {
  14. /******/
  15. /******/        // Check if module is in cache
  16. /******/        if(installedModules[moduleId]) {
  17. /******/            return installedModules[moduleId].exports;
  18. /******/        }
  19. /******/        // Create a new module (and put it into the cache)
  20. /******/        var module = installedModules[moduleId] = {
  21. /******/            i: moduleId,
  22. /******/            l: false,
  23. /******/            exports: {}
  24. /******/        };
  25. /******/
  26. /******/        // Execute the module function
  27. /******/        modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  28. /******/
  29. /******/        // Flag the module as loaded
  30. /******/        module.l = true;
  31. /******/
  32. /******/        // Return the exports of the module
  33. /******/        return module.exports;
  34. /******/    }
  35. /******/
  36. /******/
  37. /******/    // expose the modules object (__webpack_modules__)
  38. /******/    __webpack_require__.m = modules;
  39. /******/
  40. /******/    // expose the module cache
  41. /******/    __webpack_require__.c = installedModules;
  42. /******/
  43. /******/    // define getter function for harmony exports
  44. /******/    __webpack_require__.d = function(exports, name, getter) {
  45. /******/        if(!__webpack_require__.o(exports, name)) {
  46. /******/            Object.defineProperty(exports, name, {
  47. /******/                configurable: false,
  48. /******/                enumerable: true,
  49. /******/                get: getter
  50. /******/            });
  51. /******/        }
  52. /******/    };
  53. /******/
  54. /******/    // getDefaultExport function for compatibility with non-harmony modules
  55. /******/    __webpack_require__.n = function(module) {
  56. /******/        var getter = module && module.__esModule ?
  57. /******/            function getDefault() { return module['default']; } :
  58. /******/            function getModuleExports() { return module; };
  59. /******/        __webpack_require__.d(getter, 'a', getter);
  60. /******/        return getter;
  61. /******/    };
  62. /******/
  63. /******/    // Object.prototype.hasOwnProperty.call
  64. /******/    __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  65. /******/
  66. /******/    // __webpack_public_path__
  67. /******/    __webpack_require__.p = "";
  68. /******/
  69. /******/    // Load entry module and return exports
  70. /******/    return __webpack_require__(__webpack_require__.s = 0);
  71. /******/ })
  72. /************************************************************************/
  73. /******/ ([
  74. /* 0 */
  75. /***/ (function(module, exports, __webpack_require__) {
  76.  
  77. __webpack_require__(1);
  78. __webpack_require__(3);
  79. __webpack_require__(4);
  80. __webpack_require__(5);
  81. __webpack_require__(6);
  82. module.exports = __webpack_require__(7);
  83.  
  84.  
  85. /***/ }),
  86. /* 1 */
  87. /***/ (function(module, exports, __webpack_require__) {
  88.  
  89. jQuery(function ($) {
  90.     Promise.resolve().then(function () {
  91.         return __webpack_require__(2);
  92.     }).then(function () {
  93.  
  94.         // For Single Product
  95.         $('.woo-variation-gallery-wrapper:not(.wvg-loaded)').WooVariationGallery();
  96.  
  97.         // Ajax and Variation Product
  98.         $(document).on('wc_variation_form', '.variations_form', function () {
  99.             $('.woo-variation-gallery-wrapper:not(.wvg-loaded)').WooVariationGallery();
  100.         });
  101.  
  102.         // Support for Jetpack's Infinite Scroll,
  103.         $(document.body).on('post-load', function () {
  104.             $('.woo-variation-gallery-wrapper:not(.woo-variation-gallery-product-type-variable):not(.wvg-loaded)').WooVariationGallery();
  105.         });
  106.  
  107.         // YITH Quickview
  108.         $(document).on('qv_loader_stop', function () {
  109.             $('.woo-variation-gallery-wrapper:not(.woo-variation-gallery-product-type-variable):not(.wvg-loaded)').WooVariationGallery();
  110.         });
  111.  
  112.         // Elementor
  113.         if (window.elementorFrontend && window.elementorFrontend.hooks) {
  114.             elementorFrontend.hooks.addAction('frontend/element_ready/woocommerce-product-images.default', function ($scope) {
  115.                 $('.woo-variation-gallery-wrapper:not(.wvg-loaded)').WooVariationGallery();
  116.             });
  117.         }
  118.     });
  119. }); // end of jquery main wrapper
  120.  
  121. /***/ }),
  122. /* 2 */
  123. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  124.  
  125. "use strict";
  126. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  127. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  128.  
  129. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  130.  
  131. // ================================================================
  132. // WooCommerce Variation Gallery
  133. /*global wc_add_to_cart_variation_params, woo_variation_gallery_options */
  134. // ================================================================
  135.  
  136. var WooVariationGallery = function ($) {
  137.  
  138.     var Default = {};
  139.  
  140.     var WooVariationGallery = function () {
  141.         function WooVariationGallery(element, config) {
  142.             _classCallCheck(this, WooVariationGallery);
  143.  
  144.             // Assign
  145.             this._el = element;
  146.             this._element = $(element);
  147.             this._config = $.extend({}, Default, config);
  148.  
  149.             //this.$product             = this._element.closest('.product');
  150.             // let wrapper               = woo_variation_gallery_options.wrapper || '.product';
  151.             this.$wrapper = this._element.closest('.product');
  152.             this.$variations_form = this.$wrapper.find('.variations_form');
  153.             this.$attributeFields = this.$variations_form.find('.variations select');
  154.             this.$target = this._element.parent();
  155.             this.$slider = $('.woo-variation-gallery-slider', this._element);
  156.             this.$thumbnail = $('.woo-variation-gallery-thumbnail-slider', this._element);
  157.             this.thumbnail_columns = this._element.data('thumbnail_columns');
  158.             this.product_id = this.$variations_form.data('product_id');
  159.             this.is_variation_product = this.$variations_form.length > 0;
  160.             this.initial_load = true;
  161.  
  162.             // Temp variable
  163.             this.is_vertical = !!woo_variation_gallery_options.is_vertical;
  164.  
  165.             // Call
  166.             this._element.addClass('wvg-loaded');
  167.             this.defaultDimension();
  168.             this.defaultGallery();
  169.  
  170.             if (!!woo_variation_gallery_options.enable_gallery_preload) {
  171.                 this.initVariationImagePreload();
  172.             }
  173.  
  174.             this.initEvents();
  175.             this.initVariationGallery();
  176.  
  177.             if (!this.is_variation_product) {
  178.                 this.imagesLoaded();
  179.             }
  180.  
  181.             if (this.is_variation_product) {
  182.                 this.initSlick();
  183.                 this.initZoom();
  184.                 this.initPhotoswipe();
  185.             }
  186.  
  187.             this._element.data('woo_variation_gallery', this);
  188.             $(document).trigger('woo_variation_gallery_init', [this]);
  189.         }
  190.  
  191.         _createClass(WooVariationGallery, [{
  192.             key: 'init',
  193.             value: function init() {
  194.                 var _this = this;
  195.  
  196.                 return _.debounce(function () {
  197.                     _this.initSlick();
  198.                     _this.initZoom();
  199.                     _this.initPhotoswipe();
  200.                 }, 500);
  201.             }
  202.         }, {
  203.             key: 'getChosenAttributes',
  204.             value: function getChosenAttributes() {
  205.                 var data = {};
  206.                 var count = 0;
  207.                 var chosen = 0;
  208.  
  209.                 this.$attributeFields.each(function () {
  210.                     var attribute_name = $(this).data('attribute_name') || $(this).attr('name');
  211.                     var value = $(this).val() || '';
  212.  
  213.                     if (value.length > 0) {
  214.                         chosen++;
  215.                     }
  216.  
  217.                     count++;
  218.                     data[attribute_name] = value;
  219.                 });
  220.  
  221.                 return {
  222.                     'count': count,
  223.                     'chosenCount': chosen,
  224.                     'data': data
  225.                 };
  226.             }
  227.         }, {
  228.             key: 'defaultDimension',
  229.             value: function defaultDimension() {
  230.                 var _this2 = this;
  231.  
  232.                 // console.log(this._element.height(), this._element.width());
  233.                 this._element.css('min-height', this._element.height()).css('min-width', this._element.width());
  234.  
  235.                 $(window).on('resize.wvg', _.debounce(function (event) {
  236.                     if (event.originalEvent) {
  237.                         _this2._element.css('min-height', _this2._element.height()).css('min-width', _this2._element.width());
  238.                     }
  239.                 }, 300));
  240.  
  241.                 $(window).on('resize.wvg', _.debounce(function (event) {
  242.                     if (event.originalEvent) {
  243.                         _this2._element.css('min-height', '').css('min-width', '');
  244.                     }
  245.                 }, 100, { 'leading': true, 'trailing': false }));
  246.             }
  247.         }, {
  248.             key: 'dimension',
  249.             value: function dimension() {
  250.  
  251.                 //this._element.css('min-height', '0px');
  252.                 //this._element.css('min-width', '0px');
  253.  
  254.                 //return _.debounce(() => {
  255.                 //this._element.css('min-height', this.$slider.height() + 'px');
  256.                 //this._element.css('min-width', this.$slider.width() + 'px');
  257.                 //}, 400);
  258.             }
  259.         }, {
  260.             key: 'initEvents',
  261.             value: function initEvents() {
  262.                 var _this3 = this;
  263.  
  264.                 this._element.on('woo_variation_gallery_slider_slick_init', function (event, gallery) {
  265.  
  266.                     if (woo_variation_gallery_options.is_vertical) {
  267.  
  268.                         //$(window).off('resize.wvg');
  269.  
  270.                         $(window).on('resize', _this3.enableThumbnailPositionDebounce());
  271.                         //$(window).on('resize', this.thumbnailHeightDebounce());
  272.  
  273.                         //this.$slider.on('setPosition', this.enableThumbnailPositionDebounce());
  274.                         _this3.$slider.on('setPosition', _this3.thumbnailHeightDebounce());
  275.  
  276.                         _this3.$slider.on('afterChange', function () {
  277.                             _this3.thumbnailHeight();
  278.                         });
  279.                     }
  280.  
  281.                     if (woo_variation_gallery_options.enable_thumbnail_slide) {
  282.  
  283.                         var thumbnails = _this3.$thumbnail.find('.wvg-gallery-thumbnail-image').length;
  284.  
  285.                         if (parseInt(woo_variation_gallery_options.gallery_thumbnails_columns) < thumbnails) {
  286.                             _this3.$thumbnail.find('.wvg-gallery-thumbnail-image').removeClass('current-thumbnail');
  287.                             _this3.initThumbnailSlick();
  288.                         } else {
  289.                             _this3.$slider.slick('slickSetOption', 'asNavFor', null, false);
  290.                         }
  291.                     }
  292.                 });
  293.  
  294.                 this._element.on('woo_variation_gallery_slick_destroy', function (event, gallery) {
  295.                     if (_this3.$thumbnail.hasClass('slick-initialized')) {
  296.                         _this3.$thumbnail.slick('unslick');
  297.                     }
  298.                 });
  299.  
  300.                 this._element.on('woo_variation_gallery_image_loaded', this.init());
  301.             }
  302.         }, {
  303.             key: 'initSlick',
  304.             value: function initSlick() {
  305.                 var _this4 = this;
  306.  
  307.                 if (this.$slider.is('.slick-initialized')) {
  308.                     this.$slider.slick('unslick');
  309.                 }
  310.  
  311.                 this.$slider.off('init');
  312.                 this.$slider.off('beforeChange');
  313.                 this.$slider.off('afterChange');
  314.  
  315.                 this._element.trigger('woo_variation_gallery_before_init', [this]);
  316.  
  317.                 // Slider
  318.  
  319.                 this.$slider.on('init', function (event) {
  320.                     if (_this4.initial_load) {
  321.                         _this4.initial_load = false;
  322.                         // this._element.css('min-height', this.$slider.height() + 'px');
  323.                         //_.delay(() => {
  324.                         //    this.$slider.slick('setPosition');
  325.                         //}, 2000)
  326.                     }
  327.                 }).on('beforeChange', function (event, slick, currentSlide, nextSlide) {
  328.  
  329.                     _this4.$thumbnail.find('.wvg-gallery-thumbnail-image').not('.slick-slide').removeClass('current-thumbnail');
  330.                     _this4.$thumbnail.find('.wvg-gallery-thumbnail-image').not('.slick-slide').eq(nextSlide).addClass('current-thumbnail');
  331.                 }).on('afterChange', function (event, slick, currentSlide) {
  332.                     _this4.stopVideo(_this4.$slider);
  333.                     _this4.initZoomForTarget(currentSlide);
  334.                 }).slick();
  335.  
  336.                 // Thumbnails
  337.  
  338.                 this.$thumbnail.find('.wvg-gallery-thumbnail-image').not('.slick-slide').first().addClass('current-thumbnail');
  339.  
  340.                 this.$thumbnail.find('.wvg-gallery-thumbnail-image').not('.slick-slide').each(function (index, el) {
  341.                     $(el).find('div, img').on('click', function (event) {
  342.                         event.preventDefault();
  343.                         event.stopPropagation();
  344.                         _this4.$slider.slick('slickGoTo', index);
  345.                     });
  346.                 });
  347.  
  348.                 _.delay(function () {
  349.                     _this4._element.trigger('woo_variation_gallery_slider_slick_init', [_this4]);
  350.                 }, 1);
  351.  
  352.                 _.delay(function () {
  353.                     // console.log(this._element.height(), this._element.width());
  354.  
  355.                     //    this._element.css('min-height', this._element.height())
  356.                     //    this._element.css('min-width', this._element.width())
  357.  
  358.                     _this4.removeLoadingClass();
  359.                 }, 100);
  360.             }
  361.         }, {
  362.             key: 'initZoomForTarget',
  363.             value: function initZoomForTarget(currentSlide) {
  364.  
  365.                 if (!woo_variation_gallery_options.enable_gallery_zoom) {
  366.                     return;
  367.                 }
  368.  
  369.                 var galleryWidth = parseInt(this.$target.width()),
  370.                     zoomEnabled = false,
  371.                     zoomTarget = this.$slider.slick('getSlick').$slides.eq(currentSlide);
  372.  
  373.                 $(zoomTarget).each(function (index, target) {
  374.                     var image = $(target).find('img');
  375.  
  376.                     if (parseInt(image.data('large_image_width')) > galleryWidth) {
  377.                         zoomEnabled = true;
  378.  
  379.                         return false;
  380.                     }
  381.                 });
  382.  
  383.                 // If zoom not included.
  384.                 if (!$().zoom) {
  385.                     return;
  386.                 }
  387.  
  388.                 // But only zoom if the img is larger than its container.
  389.                 if (zoomEnabled) {
  390.                     var zoom_options = $.extend({
  391.                         touch: false
  392.                     }, wc_single_product_params.zoom_options);
  393.  
  394.                     if ('ontouchstart' in document.documentElement) {
  395.                         zoom_options.on = 'click';
  396.                     }
  397.  
  398.                     zoomTarget.trigger('zoom.destroy');
  399.                     zoomTarget.zoom(zoom_options);
  400.                 }
  401.             }
  402.         }, {
  403.             key: 'initZoom',
  404.             value: function initZoom() {
  405.                 var currentSlide = this.$slider.slick('slickCurrentSlide');
  406.                 this.initZoomForTarget(currentSlide);
  407.             }
  408.         }, {
  409.             key: 'initPhotoswipe',
  410.             value: function initPhotoswipe() {
  411.                 var _this5 = this;
  412.  
  413.                 if (!woo_variation_gallery_options.enable_gallery_lightbox) {
  414.                     return;
  415.                 }
  416.  
  417.                 this._element.off('click', '.woo-variation-gallery-trigger');
  418.                 this._element.off('click', '.wvg-gallery-image a');
  419.  
  420.                 this._element.on('click', '.woo-variation-gallery-trigger', function (event) {
  421.                     _this5.openPhotoswipe(event);
  422.                 });
  423.  
  424.                 this._element.on('click', '.wvg-gallery-image a', function (event) {
  425.                     _this5.openPhotoswipe(event);
  426.                 });
  427.             }
  428.         }, {
  429.             key: 'openPhotoswipe',
  430.             value: function openPhotoswipe(event) {
  431.                 var _this6 = this;
  432.  
  433.                 event.preventDefault();
  434.  
  435.                 if (typeof PhotoSwipe === 'undefined') {
  436.                     return false;
  437.                 }
  438.  
  439.                 var pswpElement = $('.pswp')[0],
  440.                     items = this.getGalleryItems();
  441.  
  442.                 var options = $.extend({
  443.                     index: this.$slider.slick('slickCurrentSlide')
  444.                 }, wc_single_product_params.photoswipe_options);
  445.  
  446.                 // Initializes and opens PhotoSwipe.
  447.  
  448.                 var photoswipe = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
  449.  
  450.                 // Gallery starts closing
  451.                 photoswipe.listen('close', function () {
  452.                     _this6.stopVideo(pswpElement);
  453.                 });
  454.  
  455.                 photoswipe.listen('afterChange', function () {
  456.                     _this6.stopVideo(pswpElement);
  457.                 });
  458.  
  459.                 photoswipe.init();
  460.             }
  461.         }, {
  462.             key: 'stopVideo',
  463.             value: function stopVideo(element) {
  464.                 $(element).find('iframe, video').each(function () {
  465.                     var tag = $(this).prop("tagName").toLowerCase();
  466.                     if (tag === 'iframe') {
  467.                         var src = $(this).attr('src');
  468.                         //   $(this).attr('src', src);
  469.                     }
  470.  
  471.                     if (tag === 'video') {
  472.                         $(this)[0].pause();
  473.                     }
  474.                 });
  475.             }
  476.         }, {
  477.             key: 'addLoadingClass',
  478.             value: function addLoadingClass() {
  479.                 if (woo_variation_gallery_options.preloader_disable) {
  480.                     return true;
  481.                 }
  482.                 this._element.addClass('loading-gallery');
  483.             }
  484.         }, {
  485.             key: 'removeLoadingClass',
  486.             value: function removeLoadingClass() {
  487.                 this._element.removeClass('loading-gallery');
  488.             }
  489.         }, {
  490.             key: 'getGalleryItems',
  491.             value: function getGalleryItems() {
  492.                 var $slides = this.$slider.slick('getSlick').$slides,
  493.                     items = [];
  494.  
  495.                 if ($slides.length > 0) {
  496.                     $slides.each(function (i, el) {
  497.                         var img = $(el).find('img, iframe, video');
  498.                         var tag = $(img).prop("tagName").toLowerCase();
  499.  
  500.                         var src = void 0,
  501.                             item = void 0;
  502.                         switch (tag) {
  503.                             case 'img':
  504.                                 var large_image_src = img.attr('data-large_image'),
  505.                                     large_image_w = img.attr('data-large_image_width'),
  506.                                     large_image_h = img.attr('data-large_image_height');
  507.                                 item = {
  508.                                     src: large_image_src,
  509.                                     w: large_image_w,
  510.                                     h: large_image_h,
  511.                                     title: img.attr('data-caption') ? img.attr('data-caption') : img.attr('title')
  512.                                 };
  513.                                 break;
  514.                             case 'iframe':
  515.                                 src = img.attr('src');
  516.                                 item = {
  517.                                     html: '<iframe class="wvg-lightbox-iframe" src="' + src + '" style="width: 100%; height: 100%; margin: 0;padding: 0; background-color: #000000" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'
  518.                                 };
  519.                                 break;
  520.                             case 'video':
  521.                                 src = img.attr('src');
  522.                                 item = {
  523.                                     html: '<video preload="auto" class="wvg-lightbox-video" disablePictureInPicture controls controlsList="nodownload" src="' + src + '" style="width: 100%; height: 100%; margin: 0;padding: 0; background-color: #000000"></video>'
  524.                                 };
  525.                                 break;
  526.                         }
  527.  
  528.                         items.push(item);
  529.                     });
  530.                 }
  531.                 return items;
  532.             }
  533.         }, {
  534.             key: 'destroySlick',
  535.             value: function destroySlick() {
  536.  
  537.                 this.$slider.html('');
  538.                 this.$thumbnail.html('');
  539.  
  540.                 if (this.$slider.is('.slick-initialized')) {
  541.                     this.$slider.slick('unslick');
  542.                 }
  543.  
  544.                 this._element.trigger('woo_variation_gallery_slick_destroy', [this]);
  545.             }
  546.         }, {
  547.             key: 'defaultGallery',
  548.             value: function defaultGallery() {
  549.                 var _this7 = this;
  550.  
  551.                 if (this.is_variation_product) {
  552.  
  553.                     if (this._element.defaultXHR) {
  554.                         this._element.defaultXHR.abort();
  555.                     }
  556.  
  557.                     this._element.defaultXHR = $.ajax({
  558.                         headers: {
  559.                             'Cache-Control': 'max-age=86400',
  560.                             'Pragma': 'cache' //  backwards compatibility with HTTP/1.0 caches
  561.                         },
  562.                         cache: true,
  563.                         url: wc_add_to_cart_variation_params.wc_ajax_url.toString().replace('%%endpoint%%', 'get_default_gallery'),
  564.                         type: 'GET',
  565.                         data: {
  566.                             product_id: this.product_id
  567.                         },
  568.                         success: function success(data) {
  569.                             if (data) {
  570.                                 _this7._element.data('woo_variation_gallery_default', data);
  571.                                 _this7._element.trigger('woo_variation_default_gallery_loaded', [_this7, data]);
  572.                             } else {
  573.                                 _this7._element.data('woo_variation_gallery_default', []);
  574.                                 _this7._element.trigger('woo_variation_default_gallery_loaded', [_this7, []]);
  575.                                 console.error('Variation Gallery not available on variation id ' + _this7.product_id + '.');
  576.                             }
  577.                         }
  578.                     });
  579.  
  580.                     /*wp.ajax.send('wvg_get_default_gallery', {
  581.                         data    : {
  582.                             product_id : this.product_id
  583.                         },
  584.                         success : (data) => {
  585.                             this._element.data('woo_variation_gallery_default', data);
  586.                             this._element.trigger('woo_variation_default_gallery_loaded', [this, data]);
  587.                         },
  588.                         error   : (e) => {
  589.                             this._element.data('woo_variation_gallery_default', []);
  590.                             this._element.trigger('woo_variation_default_gallery_loaded', [this, e]);
  591.                             console.error(`Variation Gallery not available on variation id ${this.product_id}.`);
  592.                         }
  593.                     });*/
  594.                 }
  595.             }
  596.         }, {
  597.             key: 'initVariationImagePreload',
  598.             value: function initVariationImagePreload() {
  599.                 var _this8 = this;
  600.  
  601.                 //return;
  602.                 if (this.is_variation_product) {
  603.  
  604.                     if (this._element.imagesXHR) {
  605.                         this._element.imagesXHR.abort();
  606.                     }
  607.  
  608.                     this._element.defaultXHR = $.ajax({
  609.                         headers: {
  610.                             'Cache-Control': 'max-age=86400',
  611.                             'Pragma': 'cache' //  backwards compatibility with HTTP/1.0 caches
  612.                         },
  613.                         cache: true,
  614.                         url: wc_add_to_cart_variation_params.wc_ajax_url.toString().replace('%%endpoint%%', 'get_available_variation_images'),
  615.                         type: 'GET',
  616.                         data: {
  617.                             product_id: this.product_id
  618.                         },
  619.                         success: function success(images) {
  620.                             if (images) {
  621.                                 if (images.length > 1) {
  622.                                     _this8.imagePreload(images);
  623.                                 }
  624.                                 _this8._element.data('woo_variation_gallery_variation_images', images);
  625.                                 _this8._element.trigger('woo_variation_gallery_variation_images', [_this8, images]);
  626.                             } else {
  627.                                 _this8._element.data('woo_variation_gallery_variation_images', []);
  628.                                 console.error('Variation Gallery variations images not available on variation id ' + _this8.product_id + '.');
  629.                             }
  630.                         }
  631.                     });
  632.  
  633.                     /*
  634.                                     wp.ajax.send('wvg_get_available_variation_images', {
  635.                                         data    : {
  636.                                             product_id : this.product_id
  637.                                         },
  638.                                         success : (images) => {
  639.                                             // console.log(data)
  640.                                             if (images.length > 1) {
  641.                                                 this.imagePreload(images);
  642.                                             }
  643.                                             this._element.data('woo_variation_gallery_variation_images', images);
  644.                                             this._element.trigger('woo_variation_gallery_variation_images', [this, images]);
  645.                                         },
  646.                                         error   : (e) => {
  647.                                             this._element.data('woo_variation_gallery_variation_images', []);
  648.                                             console.error(`Variation Gallery variations images not available on variation id ${this.product_id}.`);
  649.                                         }
  650.                                     });
  651.                     */
  652.                 }
  653.             }
  654.         }, {
  655.             key: 'imagePreload',
  656.             value: function imagePreload(images) {
  657.                 for (var i = 0; i < images.length; i++) {
  658.                     try {
  659.  
  660.                         // Note: this won't work when chrome devtool is open and 'disable cache' is enabled within the network panel
  661.                         var _img = new Image();
  662.                         var _gallery = new Image();
  663.                         var _full = new Image();
  664.                         var _thumbnail = new Image();
  665.  
  666.                         _img.src = images[i].src;
  667.  
  668.                         if (images[i].srcset) {
  669.                             _img.srcset = images[i].srcset;
  670.                         }
  671.  
  672.                         _gallery.src = images[i].gallery_thumbnail_src;
  673.  
  674.                         _full.src = images[i].full_src;
  675.  
  676.                         _thumbnail.src = images[i].archive_src;
  677.  
  678.                         var video_link = $.trim(images[i].video_link);
  679.  
  680.                         if (video_link && images[i].video_embed_type === 'video') {
  681.  
  682.                             var req = new XMLHttpRequest();
  683.                             req.open('GET', video_link, true);
  684.                             req.responseType = 'blob';
  685.  
  686.                             req.onload = function () {
  687.                                 // Onload is triggered even on 404
  688.                                 // so we need to check the status code
  689.                                 if (this.status === 200) {
  690.                                     var videoBlob = this.response;
  691.                                     var vid = URL.createObjectURL(videoBlob); // IE10+
  692.                                     // Video is now downloaded
  693.                                     // and we can set it as source on the video element
  694.                                     // video.src = vid;
  695.                                 }
  696.                             };
  697.                             req.onerror = function () {
  698.                                 // Error
  699.                             };
  700.  
  701.                             req.send();
  702.                         }
  703.  
  704.                         // Append Content
  705.                         /*let _img_src    = images[i].src;
  706.                         let _img_srcset = images[i].srcset;
  707.                          let _gallery_src   = images[i].gallery_thumbnail_src;
  708.                         let _full_src      = images[i].full_src;
  709.                         let _thumbnail_src = images[i].archive_src;
  710.                          let template = `<div style="display: none"><img aria-hidden="true" style="display: none" src="${_img_src}" /><img style="display: none" src="${_gallery_src}" /><img style="display: none" src="${_thumbnail_src}" /><img style="display: none" src="${_full_src}" /></div>`;
  711.                          if (_img_srcset) {
  712.                             template = `<div style="display: none"><img aria-hidden="true" style="display: none" src="${_img_src}" srcset="${_img_srcset}" /><img style="display: none" src="${_gallery_src}" /><img style="display: none" src="${_thumbnail_src}" /><img style="display: none" src="${_full_src}" /></div>`;
  713.                         }
  714.                          // let template = `<div style="display: none"><img aria-hidden="true" style="display: none" src="${_img_src}" srcset="${_img_srcset}" /><img style="display: none" src="${_gallery_src}" /><img style="display: none" src="${_thumbnail_src}" /><img style="display: none" src="${_full_src}" /></div>`;
  715.                         $('body').append(template)*/
  716.                     } catch (e) {
  717.                         console.error(e);
  718.                     }
  719.                 }
  720.             }
  721.         }, {
  722.             key: 'showVariationImage',
  723.             value: function showVariationImage(variation) {
  724.                 if (variation) {
  725.                     this.addLoadingClass();
  726.                     this.galleryInit(variation.variation_gallery_images);
  727.                 }
  728.             }
  729.         }, {
  730.             key: 'resetVariationImage',
  731.             value: function resetVariationImage() {
  732.                 if (!this._element.is('.loading-gallery')) {
  733.                     this.addLoadingClass();
  734.                     this.galleryReset();
  735.                 }
  736.             }
  737.         }, {
  738.             key: 'initVariationGallery',
  739.             value: function initVariationGallery() {
  740.                 var _this9 = this;
  741.  
  742.                 // show_variation, found_variation
  743.  
  744.                 this.$variations_form.off('reset_image.wvg');
  745.                 this.$variations_form.off('click.wvg', '.reset_variations');
  746.                 this.$variations_form.off('show_variation.wvg');
  747.                 this.$variations_form.off('hide_variation.wvg');
  748.                 // this.$variations_form.off('found_variation.wvg');
  749.  
  750.                 // Show Gallery
  751.                 // console.log(this.$variations_form)
  752.                 this.$variations_form.on('show_variation.wvg', function (event, variation) {
  753.                     _this9.showVariationImage(variation);
  754.                 });
  755.  
  756.                 if (woo_variation_gallery_options.gallery_reset_on_variation_change) {
  757.                     this.$variations_form.on('hide_variation.wvg', function () {
  758.                         _this9.resetVariationImage();
  759.                     });
  760.                 } else {
  761.                     this.$variations_form.on('click.wvg', '.reset_variations', function () {
  762.                         _this9.resetVariationImage();
  763.                     });
  764.                 }
  765.             }
  766.         }, {
  767.             key: 'galleryReset',
  768.             value: function galleryReset() {
  769.                 var _this10 = this;
  770.  
  771.                 var $default_gallery = this._element.data('woo_variation_gallery_default');
  772.  
  773.                 if ($default_gallery && $default_gallery.length > 0) {
  774.                     this.galleryInit($default_gallery);
  775.                 } else {
  776.                     _.delay(function () {
  777.                         _this10.removeLoadingClass();
  778.                     }, 100);
  779.                 }
  780.             }
  781.         }, {
  782.             key: 'galleryInit',
  783.             value: function galleryInit(images) {
  784.                 var _this11 = this;
  785.  
  786.                 var hasGallery = images.length > 1;
  787.  
  788.                 this._element.trigger('before_woo_variation_gallery_init', [this, images]);
  789.  
  790.                 this.destroySlick();
  791.  
  792.                 var slider_inner_html = images.map(function (image) {
  793.                     var template = wp.template('woo-variation-gallery-slider-template');
  794.                     return template(image);
  795.                 }).join('');
  796.  
  797.                 var thumbnail_inner_html = images.map(function (image) {
  798.                     var template = wp.template('woo-variation-gallery-thumbnail-template');
  799.                     return template(image);
  800.                 }).join('');
  801.  
  802.                 if (hasGallery) {
  803.                     this.$target.addClass('woo-variation-gallery-has-product-thumbnail');
  804.                 } else {
  805.                     this.$target.removeClass('woo-variation-gallery-has-product-thumbnail');
  806.                 }
  807.  
  808.                 this.$slider.html(slider_inner_html);
  809.  
  810.                 if (hasGallery) {
  811.                     this.$thumbnail.html(thumbnail_inner_html);
  812.                 } else {
  813.                     this.$thumbnail.html('');
  814.                 }
  815.  
  816.                 //this._element.trigger('woo_variation_gallery_init', [this, images]);
  817.  
  818.                 _.delay(function () {
  819.                     _this11.imagesLoaded();
  820.                 }, 1);
  821.  
  822.                 //this._element.trigger('after_woo_variation_gallery_init', [this, images]);
  823.             }
  824.         }, {
  825.             key: 'imagesLoaded',
  826.             value: function imagesLoaded() {
  827.                 var _this12 = this;
  828.  
  829.                 // Some Script Add Custom imagesLoaded Function
  830.                 if (!$().imagesLoaded.done) {
  831.                     this._element.trigger('woo_variation_gallery_image_loading', [this]);
  832.                     this._element.trigger('woo_variation_gallery_image_loaded', [this]);
  833.                     return;
  834.                 }
  835.  
  836.                 this._element.imagesLoaded().progress(function (instance, image) {
  837.                     _this12._element.trigger('woo_variation_gallery_image_loading', [_this12]);
  838.                 }).done(function (instance) {
  839.                     _this12._element.trigger('woo_variation_gallery_image_loaded', [_this12]);
  840.                 });
  841.             }
  842.         }, {
  843.             key: 'initThumbnailSlick',
  844.             value: function initThumbnailSlick() {
  845.                 var _this13 = this;
  846.  
  847.                 if (this.$thumbnail.hasClass('slick-initialized')) {
  848.                     this.$thumbnail.slick('unslick');
  849.                 }
  850.  
  851.                 this.$thumbnail.off('init');
  852.  
  853.                 this.$thumbnail.on('init', function () {}).slick();
  854.  
  855.                 _.delay(function () {
  856.                     _this13._element.trigger('woo_variation_gallery_thumbnail_slick_init', [_this13]);
  857.                 }, 1);
  858.             }
  859.         }, {
  860.             key: 'thumbnailHeight',
  861.             value: function thumbnailHeight() {
  862.  
  863.                 //console.log('thumbnailHeight...')
  864.                 if (this.is_vertical) {
  865.                     if (this.$slider.slick('getSlick').$slides.length > 1) {
  866.                         this.$thumbnail.height(this.$slider.height());
  867.                     } else {
  868.                         this.$thumbnail.height(0);
  869.                     }
  870.                 } else {
  871.                     this.$thumbnail.height('auto');
  872.                 }
  873.  
  874.                 if (this.$thumbnail.hasClass('slick-initialized')) {
  875.                     this.$thumbnail.slick('setPosition');
  876.                 }
  877.             }
  878.         }, {
  879.             key: 'thumbnailHeightDebounce',
  880.             value: function thumbnailHeightDebounce(event) {
  881.                 var _this14 = this;
  882.  
  883.                 return _.debounce(function () {
  884.                     _this14.thumbnailHeight();
  885.                 }, 401);
  886.             }
  887.         }, {
  888.             key: 'enableThumbnailPosition',
  889.             value: function enableThumbnailPosition() {
  890.  
  891.                 if (!woo_variation_gallery_options.is_mobile) {
  892.                     //    return;
  893.                 }
  894.  
  895.                 if (woo_variation_gallery_options.is_vertical) {
  896.                     //console.log('enableThumbnailPosition...')
  897.                     if (window.matchMedia("(max-width: 768px)").matches || window.matchMedia("(max-width: 480px)").matches) {
  898.  
  899.                         this.is_vertical = false;
  900.  
  901.                         this._element.removeClass(woo_variation_gallery_options.thumbnail_position_class_prefix + 'left ' + woo_variation_gallery_options.thumbnail_position_class_prefix + 'right ' + woo_variation_gallery_options.thumbnail_position_class_prefix + 'bottom');
  902.                         this._element.addClass(woo_variation_gallery_options.thumbnail_position_class_prefix + 'bottom');
  903.  
  904.                         this.$slider.slick('setPosition');
  905.                     } else {
  906.  
  907.                         this.is_vertical = true;
  908.  
  909.                         this._element.removeClass(woo_variation_gallery_options.thumbnail_position_class_prefix + 'left ' + woo_variation_gallery_options.thumbnail_position_class_prefix + 'right ' + woo_variation_gallery_options.thumbnail_position_class_prefix + 'bottom');
  910.                         this._element.addClass('' + woo_variation_gallery_options.thumbnail_position_class_prefix + woo_variation_gallery_options.thumbnail_position);
  911.  
  912.                         this.$slider.slick('setPosition');
  913.                     }
  914.                 }
  915.             }
  916.         }, {
  917.             key: 'enableThumbnailPositionDebounce',
  918.             value: function enableThumbnailPositionDebounce(event) {
  919.                 var _this15 = this;
  920.  
  921.                 return _.debounce(function () {
  922.                     _this15.enableThumbnailPosition();
  923.                 }, 400);
  924.             }
  925.         }], [{
  926.             key: '_jQueryInterface',
  927.             value: function _jQueryInterface(config) {
  928.                 return this.each(function () {
  929.                     new WooVariationGallery(this, config);
  930.                 });
  931.             }
  932.         }]);
  933.  
  934.         return WooVariationGallery;
  935.     }();
  936.  
  937.     /**
  938.      * ------------------------------------------------------------------------
  939.      * jQuery
  940.      * ------------------------------------------------------------------------
  941.      */
  942.  
  943.     $.fn['WooVariationGallery'] = WooVariationGallery._jQueryInterface;
  944.     $.fn['WooVariationGallery'].Constructor = WooVariationGallery;
  945.     $.fn['WooVariationGallery'].noConflict = function () {
  946.         $.fn['WooVariationGallery'] = $.fn['WooVariationGallery'];
  947.         return WooVariationGallery._jQueryInterface;
  948.     };
  949.  
  950.     return WooVariationGallery;
  951. }(jQuery);
  952.  
  953. /* harmony default export */ __webpack_exports__["default"] = (WooVariationGallery);
  954.  
  955. /***/ }),
  956. /* 3 */
  957. /***/ (function(module, exports) {
  958.  
  959. // removed by extract-text-webpack-plugin
  960.  
  961. /***/ }),
  962. /* 4 */
  963. /***/ (function(module, exports) {
  964.  
  965. // removed by extract-text-webpack-plugin
  966.  
  967. /***/ }),
  968. /* 5 */
  969. /***/ (function(module, exports) {
  970.  
  971. // removed by extract-text-webpack-plugin
  972.  
  973. /***/ }),
  974. /* 6 */
  975. /***/ (function(module, exports) {
  976.  
  977. // removed by extract-text-webpack-plugin
  978.  
  979. /***/ }),
  980. /* 7 */
  981. /***/ (function(module, exports) {
  982.  
  983. // removed by extract-text-webpack-plugin
  984.  
  985. /***/ })
  986. /******/ ]);
Advertisement
Add Comment
Please, Sign In to add comment