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 self.initSidebar(); 16 17 $( 'body' ).on( 'found_variation', function( event, variation ) { 18 self.variationsImageUpdate(variation); 19 }); 20 21 $( 'body' ).on( 'reset_image', function( event, variation ) { 22 self.variationsImageUpdate(variation); 23 }); 24 if ( $.isFunction( $.fn.select2 ) ) { 25 $('.apus-search-form .select-category select').select2(); 26 } 27 28 $('body').on('hover', '.apus-topcart .cart_list', function(){ 29 $(this).perfectScrollbar(); 30 }); 31 32 }, 33 productDetail: function(){ 34 // review click link 35 $('.woocommerce-review-link').on('click', function(){ 36 $('.woocommerce-tabs a[href="#tabs-list-reviews"]').trigger('click'); 37 $('html, body').animate({ 38 scrollTop: $("#reviews").offset().top 39 }, 1000); 40 return false; 41 }); 42 43 $('body').on('click', '.view-more-desc', function() { 44 45 var $this = $(this); 46 var $content = $this.parent().find("div.woocommerce-product-details__short-description"); 47 48 if ( $this.hasClass('view-more') ) { 49 var linkText = homeo_woo_options.view_less_text; 50 $content.removeClass("hideContent").addClass("showContent"); 51 $this.removeClass("view-more").addClass("view-less"); 52 } else { 53 var linkText = homeo_woo_options.view_more_text; 54 $content.removeClass("showContent").addClass("hideContent"); 55 $this.removeClass("view-less").addClass("view-more"); 56 }; 57 58 $this.find('span').text(linkText); 59 }); 60 }, 61 initQuickview: function(){ 62 var self = this; 63 $('body').on('click', 'a.quickview', function (e) { 64 e.preventDefault(); 65 var $self = $(this); 66 $self.addClass('loading'); 67 var product_id = $(this).data('product_id'); 68 var url = homeo_woo_options.ajaxurl + '?action=homeo_quickview_product&product_id=' + product_id; 69 70 $.get(url,function(data,status){ 71 $.magnificPopup.open({ 72 mainClass: 'apus-mfp-zoom-in apus-quickview', 73 items : { 74 src : data, 75 type: 'inline' 76 }, 77 callbacks: { 78 open: function() { 79 // variation 80 if ( typeof wc_add_to_cart_variation_params !== 'undefined' ) { 81 $( '.variations_form' ).each( function() { 82 $( this ).wc_variation_form().find('.variations select:eq(0)').trigger('change'); 83 }); 84 } 85 if ( $.isFunction( $.fn.tawcvs_variation_swatches_form ) ) { 86 $( '.variations_form' ).tawcvs_variation_swatches_form(); 87 } 88 if ( $('.apus-quickview').find('.slick-carousel') ) { 89 self.initSlick($('.apus-quickview').find('.slick-carousel')); 90 } 91 self.layzyLoadImage(); 92 self.refresh_quantity_increments(); 93 } 94 } 95 }); 96 97 $self.removeClass('loading'); 98 }); 99 }); 100 }, 101 initSidebar: function() { 102 // view more categories 103 $('.widget_product_categories ul.product-categories').each(function(e){
104 var height = $(this).outerHeight(); 105 if ( height > 260 ) { 106 var view_more = '<a href="javascript:void(0);" class="view-more-list-cat view-more"><span>'+homeo_woo_options.view_more_text+'</span> <i class="fa fa-angle-double-right"></i></a>'; 107 $(this).parent().append(view_more); 108 $(this).addClass('hideContent'); 109 } 110 }); 111 112 $('body').on('click', '.view-more-list-cat', function() { 113 114 var $this = $(this); 115 var $content = $this.parent().find(".product-categories"); 116 117 if ( $this.hasClass('view-more') ) { 118 var linkText = homeo_woo_options.view_less_text; 119 $content.removeClass("hideContent").addClass("showContent"); 120 $this.removeClass("view-more").addClass("view-less"); 121 } else { 122 var linkText = homeo_woo_options.view_more_text; 123 $content.removeClass("showContent").addClass("hideContent"); 124 $this.removeClass("view-less").addClass("view-more"); 125 }; 126 127 $this.find('span').text(linkText); 128 }); 129 130 // view more for filter 131 $('.woocommerce-widget-layered-nav-list').each(function(e){ 132 var height = $(this).outerHeight(); 133 if ( height > 260 ) { 134 var view_more = '<a href="javascript:void(0);" class="view-more-list view-more"><span>'+homeo_woo_options.view_more_text+'</span> <i class="fa fa-angle-double-right"></i></a>'; 135 $(this).parent().append(view_more); 136 $(this).addClass('hideContent'); 137 } 138 }); 139 140 $('body').on('click', '.view-more-list', function() { 141 142 var $this = $(this); 143 var $content = $this.parent().find(".woocommerce-widget-layered-nav-list"); 144 145 if ( $this.hasClass('view-more') ) { 146 var linkText = homeo_woo_options.view_less_text; 147 $content.removeClass("hideContent").addClass("showContent"); 148 $this.removeClass("view-more").addClass("view-less"); 149 } else { 150 var linkText = homeo_woo_options.view_more_text; 151 $content.removeClass("showContent").addClass("hideContent"); 152 $this.removeClass("view-less").addClass("view-more"); 153 }; 154 155 $this.find('span').text(linkText); 156 }); 157 }, 158 variationsImageUpdate: function( variation ) { 159 var $form = $('.variations_form'), 160 $product = $form.closest( '.product' ), 161 $product_gallery = $product.find( '.apus-woocommerce-product-gallery-wrapper' ), 162 $gallery_img = $product.find( '.apus-woocommerce-product-gallery-thumbs img:eq(0)' ), 163 $product_img_wrap = $product_gallery.find( '.woocommerce-product-gallery__image, .woocommerce-product-gallery__image--placeholder' ).eq( 0 ), 164 $product_img = $product_img_wrap.find( '.wp-post-image' ), 165 $product_link = $product_img_wrap.find( 'a' ).eq( 0 ); 166 167 168 if ( variation && variation.image && variation.image.src && variation.image.src.length > 1 ) { 169 170 if ( $( '.apus-woocommerce-product-gallery-thumbs img[src="' + variation.image.thumb_src + '"]' ).length > 0 ) { 171 $( '.apus-woocommerce-product-gallery-thumbs img[src="' + variation.image.thumb_src + '"]' ).trigger( 'click' ); 172 $form.attr( 'current-image', variation.image_id ); 173 return; 174 } else { 175 $product_img.wc_set_variation_attr( 'src', variation.image.src ); 176 $product_img.wc_set_variation_attr( 'height', variation.image.src_h ); 177 $product_img.wc_set_variation_attr( 'width', variation.image.src_w ); 178 $product_img.wc_set_variation_attr( 'srcset', variation.image.srcset ); 179 $product_img.wc_set_variation_attr( 'sizes', variation.image.sizes ); 180 $product_img.wc_set_variation_attr( 'title', variation.image.title ); 181 $product_img.wc_set_variation_attr( 'alt', variation.image.alt ); 182 $product_img.wc_set_variation_attr( 'data-src', variation.image.full_src ); 183 $product_img.wc_set_variation_attr( 'data-large_image', variation.image.full_src ); 184 $product_img.wc_set_variation_attr( 'data-large_image_width', variation.image.full_src_w ); 185 $product_img.wc_set_variation_attr( 'data-large_image_height', variation.image.full_src_h ); 186 $product_img_wrap.wc_set_variation_attr( 'data-thumb', variation.image.src ); 187 $gallery_img.wc_set_variation_attr( 'src', variation.image.thumb_src ); 188 $gallery_img.wc_set_variation_attr( 'srcset', variation.image.thumb_srcset ); 189 190 $product_link.wc_set_variation_attr( 'href', variation.image.full_src ); 191 $gallery_img.removeAttr('srcset'); 192 $('.apus-woocommerce-product-gallery').slick('slickGoTo', 0); 193 194 } 195 } else { 196 $product_img.wc_reset_variation_attr( 'src' ); 197 $product_img.wc_reset_variation_attr( 'width' ); 198 $product_img.wc_reset_variation_attr( 'height' ); 199 $product_img.wc_reset_variation_attr( 'srcset' ); 200 $product_img.wc_reset_variation_attr( 'sizes' ); 201 $product_img.wc_reset_variation_attr( 'title' ); 202 $product_img.wc_reset_variation_attr( 'alt' ); 203 $product_img.wc_reset_variation_attr( 'data-src' ); 204 $product_img.wc_reset_variation_attr( 'data-large_image' ); 205 $product_img.wc_reset_variation_attr( 'data-large_image_width' ); 206 $product_img.wc_reset_variation_attr( 'data-large_image_height' ); 207 $product_img_wrap.wc_reset_variation_attr( 'data-thumb' ); 208 $gallery_img.wc_reset_variation_attr( 'src' ); 209 $product_link.wc_reset_variation_attr( 'href' ); 210 } 211 212 window.setTimeout( function() { 213 $( window ).trigger( 'resize' ); 214 $form.wc_maybe_trigger_slide_position_reset( variation ); 215 $product_gallery.trigger( 'woocommerce_gallery_init_zoom' ); 216 }, 20 ); 217 } 218 });
219 220 $.apusThemeExtensions.shop = $.apusThemeCore.woo_init; 221 222 223 // gallery 224 225 var ApusProductGallery = function( $target, args ) { 226 var self = this; 227 this.$target = $target; 228 this.$images = $( '.woocommerce-product-gallery__image', $target ); 229 230 // No images? Abort. 231 if ( 0 === this.$images.length ) { 232 this.$target.css( 'opacity', 1 ); 233 return; 234 } 235 236 // Make this object available. 237 $target.data( 'product_gallery', this ); 238 239 // Pick functionality to initialize... 240 this.zoom_enabled = $.isFunction( $.fn.zoom ) && wc_single_product_params.zoom_enabled; 241 this.photoswipe_enabled = typeof PhotoSwipe !== 'undefined' && wc_single_product_params.photoswipe_enabled; 242 243 // ...also taking args into account. 244 if ( args ) { 245 this.zoom_enabled = false === args.zoom_enabled ? false : this.zoom_enabled; 246 this.photoswipe_enabled = false === args.photoswipe_enabled ? false : this.photoswipe_enabled; 247 } 248 249 250 251 // Bind functions to this. 252 this.initZoom = this.initZoom.bind( this ); 253 this.initZoomForTarget = this.initZoomForTarget.bind( this ); 254 this.initPhotoswipe = this.initPhotoswipe.bind( this ); 255 this.getGalleryItems = this.getGalleryItems.bind( this ); 256 this.openPhotoswipe = this.openPhotoswipe.bind( this ); 257 258 this.$target.css( 'opacity', 1 ); 259 260 if ( this.zoom_enabled ) { 261 this.initZoom(); 262 $target.on( 'woocommerce_gallery_init_zoom', this.initZoom ); 263 } 264 265 if ( this.photoswipe_enabled ) { 266 this.initPhotoswipe(); 267 } 268 269 $('.apus-woocommerce-product-gallery').on('beforeChange', function(event, slick, currentSlide, nextSlide){ 270 self.initZoomForTarget( self.$images.eq(nextSlide) ); 271 }); 272 }; 273 274 275 /** 276 * Init zoom. 277 */ 278 ApusProductGallery.prototype.initZoom = function() { 279 this.initZoomForTarget( this.$images.first() ); 280 }; 281 282 /** 283 * Init zoom. 284 */ 285 ApusProductGallery.prototype.initZoomForTarget = function( zoomTarget ) { 286 if ( ! this.zoom_enabled ) { 287 return false; 288 } 289 290 var galleryWidth = this.$target.width(), 291 zoomEnabled = false; 292 293 $( zoomTarget ).each( function( index, target ) { 294 var image = $( target ).find( 'img' ); 295 296 if ( image.data( 'large_image_width' ) > galleryWidth ) { 297 zoomEnabled = true; 298 return false; 299 } 300 } ); 301 302 // But only zoom if the img is larger than its container. 303 if ( zoomEnabled ) { 304 var zoom_options = { 305 touch: false 306 }; 307 308 if ( 'ontouchstart' in window ) { 309 zoom_options.on = 'click'; 310 } 311 312 zoomTarget.trigger( 'zoom.destroy' ); 313 zoomTarget.zoom( zoom_options ); 314 } 315 }; 316 317 /** 318 * Init PhotoSwipe. 319 */ 320 ApusProductGallery.prototype.initPhotoswipe = function() { 321 if ( this.zoom_enabled && this.$images.length > 0 ) { 322 this.$target.prepend( '<a href="#" class="woocommerce-product-gallery__trigger"><i class="flaticon-zoom-in"></i></a>' ); 323 this.$target.on( 'click', '.woocommerce-product-gallery__trigger', this.openPhotoswipe ); 324 } 325 this.$target.on( 'click', '.woocommerce-product-gallery__image a', this.openPhotoswipe ); 326 }; 327 328 /** 329 * Get product gallery image items. 330 */ 331 ApusProductGallery.prototype.getGalleryItems = function() { 332 var $slides = this.$images, 333 items = []; 334 335 if ( $slides.length > 0 ) { 336 $slides.each( function( i, el ) { 337 var img = $( el ).find( 'img' ), 338 large_image_src = img.attr( 'data-large_image' ), 339 large_image_w = img.attr( 'data-large_image_width' ), 340 large_image_h = img.attr( 'data-large_image_height' ), 341 item = { 342 src : large_image_src, 343 w : large_image_w, 344 h : large_image_h, 345 title: img.attr( 'data-caption' ) ? img.attr( 'data-caption' ) : img.attr( 'title' ) 346 }; 347 items.push( item ); 348 } ); 349 } 350 351 return items; 352 }; 353 354 /** 355 * Open photoswipe modal. 356 */ 357 ApusProductGallery.prototype.openPhotoswipe = function( e ) { 358 e.preventDefault(); 359 360 var pswpElement = $( '.pswp' )[0], 361 items = this.getGalleryItems(), 362 eventTarget = $( e.target ), 363 clicked; 364 365 if ( this.$target.find( '.woocommerce-product-gallery__image.slick-current' ).length > 0 ) { 366 clicked = this.$target.find( '.woocommerce-product-gallery__image.slick-current' ); 367 } else { 368 clicked = eventTarget.closest( '.woocommerce-product-gallery__image' ); 369 } 370 var options = $.extend( { 371 index: $( clicked ).index() 372 }, wc_single_product_params.photoswipe_options ); 373 374 // Initializes and opens PhotoSwipe. 375 var photoswipe = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options ); 376 photoswipe.init(); 377 }; 378 379 /** 380 * Function to call wc_product_gallery on jquery selector. 381 */ 382 $.fn.apus_wc_product_gallery = function( args ) { 383 new ApusProductGallery( this, args ); 384 return this; 385 }; 386 387 /* 388 * Initialize all galleries on page. 389 */ 390 $( '.apus-woocommerce-product-gallery-wrapper' ).each( function() { 391 $( this ).apus_wc_product_gallery(); 392 } ); 393 394 395})(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.