1(function($) { 2 "use strict"; 3 4 $.extend($.apusThemeCore, { 5 /** 6 * Initialize scripts 7 */ 8 woo_init: function() { 9 var self = this; 10 11 self.productDetail(); 12 13 self.initQuickview(); 14 15 $( 'body' ).on( 'found_variation', function( event, variation ) { 16 self.variationsImageUpdate(variation); 17 }); 18 19 $( 'body' ).on( 'reset_image', function( event, variation ) { 20 self.variationsImageUpdate(variation); 21 }); 22 23 $('body').on('hover', '.apus-top-cart .cart_list', function(){ 24 $(this).perfectScrollbar(); 25 }); 26 27 }, 28 productDetail: function(){ 29 30 // review click link 31 $('.woocommerce-review-link').on('click', function(){ 32 $('.woocommerce-tabs a[href="#tabs-list-reviews"]').trigger('click'); 33 $('html, body').animate({ 34 scrollTop: $("#reviews").offset().top 35 }, 1000); 36 return false; 37 }); 38 39 }, 40 initQuickview: function(){ 41 var self = this; 42 $('a.quickview').on('click', function (e) { 43 e.preventDefault(); 44 var $self = $(this); 45 $self.parent().parent().parent().addClass('loading'); 46 var product_id = $(this).data('product_id'); 47 var url = findus_woo_options.ajaxurl + '?action=findus_quickview_product&product_id=' + product_id; 48 49 $.get(url,function(data,status){ 50 $.magnificPopup.open({ 51 mainClass: 'apus-mfp-zoom-in apus-quickview', 52 items : { 53 src : data, 54 type: 'inline' 55 } 56 }); 57 // variation 58 if ( typeof wc_add_to_cart_variation_params !== 'undefined' ) { 59 $( '.variations_form' ).each( function() { 60 $( this ).wc_variation_form().find('.variations select:eq(0)').trigger('change'); 61 }); 62 } 63 64 self.initSlick($(".quickview-slick")); 65 66 $self.parent().parent().parent().removeClass('loading'); 67 }); 68 }); 69 }, 70 71 variationsImageUpdate: function( variation ) { 72 var $form = $('.variations_form'), 73 $product = $form.closest( '.product' ), 74 $product_gallery = $product.find( '.apus-woocommerce-product-gallery-wrapper' ), 75 $gallery_img = $product.find( '.apus-woocommerce-product-gallery-thumbs img:eq(0)' ), 76 $product_img_wrap = $product_gallery.find( '.woocommerce-product-gallery__image, .woocommerce-product-gallery__image--placeholder' ).eq( 0 ), 77 $product_img = $product_img_wrap.find( '.wp-post-image' ), 78 $product_link = $product_img_wrap.find( 'a' ).eq( 0 ); 79 80 81 if ( variation && variation.image && variation.image.src && variation.image.src.length > 1 ) { 82 83 if ( $( '.apus-woocommerce-product-gallery-thumbs img[src="' + variation.image.thumb_src + '"]' ).length > 0 ) { 84 $( '.apus-woocommerce-product-gallery-thumbs img[src="' + variation.image.thumb_src + '"]' ).trigger( 'click' ); 85 $form.attr( 'current-image', variation.image_id ); 86 return; 87 } else { 88 $product_img.wc_set_variation_attr( 'src', variation.image.src ); 89 $product_img.wc_set_variation_attr( 'height', variation.image.src_h ); 90 $product_img.wc_set_variation_attr( 'width', variation.image.src_w ); 91 $product_img.wc_set_variation_attr( 'srcset', variation.image.srcset ); 92 $product_img.wc_set_variation_attr( 'sizes', variation.image.sizes ); 93 $product_img.wc_set_variation_attr( 'title', variation.image.title ); 94 $product_img.wc_set_variation_attr( 'alt', variation.image.alt ); 95 $product_img.wc_set_variation_attr( 'data-src', variation.image.full_src ); 96 $product_img.wc_set_variation_attr( 'data-large_image', variation.image.full_src ); 97 $product_img.wc_set_variation_attr( 'data-large_image_width', variation.image.full_src_w ); 98 $product_img.wc_set_variation_attr( 'data-large_image_height', variation.image.full_src_h ); 99 $product_img_wrap.wc_set_variation_attr( 'data-thumb', variation.image.src ); 100 $gallery_img.wc_set_variation_attr( 'src', variation.image.thumb_src ); 101 $gallery_img.wc_set_variation_attr( 'srcset', variation.image.thumb_srcset ); 102 103 $product_link.wc_set_variation_attr( 'href', variation.image.full_src ); 104 $gallery_img.removeAttr('srcset'); 105 $('.apus-woocommerce-product-gallery').slick('slickGoTo', 0); 106 107 } 108 } else { 109 $product_img.wc_reset_variation_attr( 'src' ); 110 $product_img.wc_reset_variation_attr( 'width' ); 111 $product_img.wc_reset_variation_attr( 'height' ); 112 $product_img.wc_reset_variation_attr( 'srcset' ); 113 $product_img.wc_reset_variation_attr( 'sizes' ); 114 $product_img.wc_reset_variation_attr( 'title' ); 115 $product_img.wc_reset_variation_attr( 'alt' ); 116 $product_img.wc_reset_variation_attr( 'data-src' ); 117 $product_img.wc_reset_variation_attr( 'data-large_image' ); 118 $product_img.wc_reset_variation_attr( 'data-large_image_width' ); 119 $product_img.wc_reset_variation_attr( 'data-large_image_height' ); 120 $product_img_wrap.wc_reset_variation_attr( 'data-thumb' ); 121 $gallery_img.wc_reset_variation_attr( 'src' ); 122 $product_link.wc_reset_variation_attr( 'href' ); 123 } 124 125 window.setTimeout( function() { 126 $( window ).trigger( 'resize' ); 127 $form.wc_maybe_trigger_slide_position_reset( variation ); 128 $product_gallery.trigger( 'woocommerce_gallery_init_zoom' ); 129 }, 20 ); 130 } 131 });
132 133 $.apusThemeExtensions.shop = $.apusThemeCore.woo_init; 134 135 136 // gallery 137 138 var ApusProductGallery = function( $target, args ) { 139 var self = this; 140 this.$target = $target; 141 this.$images = $( '.woocommerce-product-gallery__image', $target ); 142 143 // No images? Abort. 144 if ( 0 === this.$images.length ) { 145 this.$target.css( 'opacity', 1 ); 146 return; 147 } 148 149 // Make this object available. 150 $target.data( 'product_gallery', this ); 151 152 // Pick functionality to initialize... 153 this.zoom_enabled = $.isFunction( $.fn.zoom ) && wc_single_product_params.zoom_enabled; 154 this.photoswipe_enabled = typeof PhotoSwipe !== 'undefined' && wc_single_product_params.photoswipe_enabled; 155 156 // ...also taking args into account. 157 if ( args ) { 158 this.zoom_enabled = false === args.zoom_enabled ? false : this.zoom_enabled; 159 this.photoswipe_enabled = false === args.photoswipe_enabled ? false : this.photoswipe_enabled; 160 } 161 162 163 164 // Bind functions to this. 165 this.initZoom = this.initZoom.bind( this ); 166 this.initZoomForTarget = this.initZoomForTarget.bind( this ); 167 this.initPhotoswipe = this.initPhotoswipe.bind( this ); 168 this.getGalleryItems = this.getGalleryItems.bind( this ); 169 this.openPhotoswipe = this.openPhotoswipe.bind( this ); 170 171 this.$target.css( 'opacity', 1 ); 172 173 if ( this.zoom_enabled ) { 174 this.initZoom(); 175 $target.on( 'woocommerce_gallery_init_zoom', this.initZoom ); 176 } 177 178 if ( this.photoswipe_enabled ) { 179 this.initPhotoswipe(); 180 } 181 182 $('.apus-woocommerce-product-gallery').on('beforeChange', function(event, slick, currentSlide, nextSlide){ 183 self.initZoomForTarget( self.$images.eq(nextSlide) ); 184 }); 185 }; 186 187 188 /** 189 * Init zoom. 190 */ 191 ApusProductGallery.prototype.initZoom = function() { 192 this.initZoomForTarget( this.$images.first() ); 193 }; 194 195 /** 196 * Init zoom. 197 */ 198 ApusProductGallery.prototype.initZoomForTarget = function( zoomTarget ) { 199 if ( ! this.zoom_enabled ) { 200 return false; 201 } 202 203 var galleryWidth = this.$target.width(), 204 zoomEnabled = false; 205 206 $( zoomTarget ).each( function( index, target ) { 207 var image = $( target ).find( 'img' ); 208 209 if ( image.data( 'large_image_width' ) > galleryWidth ) { 210 zoomEnabled = true; 211 return false; 212 } 213 } ); 214 215 // But only zoom if the img is larger than its container. 216 if ( zoomEnabled ) { 217 var zoom_options = { 218 touch: false 219 }; 220 221 if ( 'ontouchstart' in window ) { 222 zoom_options.on = 'click'; 223 } 224 225 zoomTarget.trigger( 'zoom.destroy' ); 226 zoomTarget.zoom( zoom_options ); 227 } 228 }; 229 230 /** 231 * Init PhotoSwipe. 232 */ 233 ApusProductGallery.prototype.initPhotoswipe = function() { 234 if ( this.zoom_enabled && this.$images.length > 0 ) { 235 this.$target.prepend( '<a href="#" class="woocommerce-product-gallery__trigger"><i class="flaticon-magnifying-glass" aria-hidden="true"></i></a>' ); 236 this.$target.on( 'click', '.woocommerce-product-gallery__trigger', this.openPhotoswipe ); 237 } 238 this.$target.on( 'click', '.woocommerce-product-gallery__image a', this.openPhotoswipe ); 239 }; 240 241 /** 242 * Get product gallery image items. 243 */ 244 ApusProductGallery.prototype.getGalleryItems = function() { 245 var $slides = this.$images, 246 items = []; 247 248 if ( $slides.length > 0 ) { 249 $slides.each( function( i, el ) { 250 var img = $( el ).find( 'img' ), 251 large_image_src = img.attr( 'data-large_image' ), 252 large_image_w = img.attr( 'data-large_image_width' ), 253 large_image_h = img.attr( 'data-large_image_height' ), 254 item = { 255 src : large_image_src, 256 w : large_image_w, 257 h : large_image_h, 258 title: img.attr( 'data-caption' ) ? img.attr( 'data-caption' ) : img.attr( 'title' ) 259 }; 260 items.push( item ); 261 } ); 262 } 263 264 return items; 265 }; 266 267 /** 268 * Open photoswipe modal. 269 */ 270 ApusProductGallery.prototype.openPhotoswipe = function( e ) { 271 e.preventDefault(); 272 273 var pswpElement = $( '.pswp' )[0], 274 items = this.getGalleryItems(), 275 eventTarget = $( e.target ), 276 clicked; 277 278 if ( this.$target.find( '.woocommerce-product-gallery__image.slick-current' ).length > 0 ) { 279 clicked = this.$target.find( '.woocommerce-product-gallery__image.slick-current' ); 280 } else { 281 clicked = eventTarget.closest( '.woocommerce-product-gallery__image' ); 282 } 283 var options = $.extend( { 284 index: $( clicked ).index() 285 }, wc_single_product_params.photoswipe_options ); 286 287 // Initializes and opens PhotoSwipe. 288 var photoswipe = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options ); 289 photoswipe.init(); 290 }; 291 292 /** 293 * Function to call wc_product_gallery on jquery selector. 294 */ 295 $.fn.apus_wc_product_gallery = function( args ) { 296 new ApusProductGallery( this, args ); 297 return this; 298 }; 299 300 /* 301 * Initialize all galleries on page. 302 */ 303 $( '.apus-woocommerce-product-gallery-wrapper' ).each( function() { 304 $( this ).apus_wc_product_gallery(); 305 } ); 306 307 308})(jQuery);
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.