PageSourceSearch

https://practicalmind.net/wp-content/themes/pma-theme/js/woocommerce.js?ver=20150330

js practicalmind.net collected 2026-10-05 03:43:01 UTC 14,251 bytes, 332 lines download raw bytes

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