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