1var Toolset_WCV = Toolset_WCV || {}; 2 3Toolset_WCV.Frontend = function( $ ) { 4 5 var self = this; 6 7 self.manageVariations = function( $container ) { 8 if ( 9 typeof wc_add_to_cart_variation_params !== 'undefined' 10 && typeof $.fn.wc_variation_form === "function" 11 ) { 12 $container.find( '.variations_form' ).each( function() { 13 $( this ).wc_variation_form(); 14 }); 15 } 16 return self; 17 }; 18 19 self.manageOnSale = function( $container ) { 20 $container.find( '.woocommerce span.onsale' ).each( function() { 21 if ( $( this ).closest( '.wcviews_onsale_wrap' ).length == 0 ) { 22 $( this ).wrap( '<span class="wcviews_onsale_wrap" />' ); 23 const onSaleWrapper = $( this ).parent(); 24 const onSaleBadge = this; 25 // Wait until initialization calls are done 26 setTimeout( function() { 27 const flexWrapper = onSaleWrapper.siblings( '.woocommerce-product-gallery' ).children( '.flex-viewport' ); 28 $( onSaleWrapper ).appendTo( flexWrapper ); 29 }, 0 ); 30 } 31 } ); 32 return self; 33 }; 34 35 self.manageStarRating = function( $container ) { 36 $container.find( '.woocommerce .star-rating' ).addClass( 'wc_views_star_rating' ); 37 return self; 38 }; 39 40 self.manageAjaxResults = function( $container ) { 41 self.manageOnSale( $container ) 42 .manageStarRating( $container ) 43 .manageVariations( $container ); 44 }; 45 46 /** 47 * Auxiliar method copied from the native WooCommerce variations script. 48 * 49 * @param string string 50 * @return string 51 */ 52 self.addSlashes = function( string ) { 53 string = string.replace( /'/g, '\\\'' ); 54 string = string.replace( /"/g, '\\\"' ); 55 return string; 56 }; 57 58 $( document ).on( 'js_event_wpv_pagination_completed', function( event, data ) { 59 self.manageAjaxResults( data.layout ); 60 }); 61 62 $( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) { 63 self.manageAjaxResults( data.layout ); 64 }); 65 66 $( document ).on( 'woocommerce_update_variation_values', '.variations_form', function( event ) { 67 // AFter initializing the variations, WooCommerce removes the "selected" attribute for the maybe selected default onw 68 // so infinite scrolling fails to re-initialize variations properly on products already in previous pages. 69 // This event lets us re-add the "selected" attribute. 70 var $form = $( this ), 71 $attributeFields = $form.find( '.variations select' ); 72 73 $attributeFields.each( function( index, el ) { 74 var $currentAttrSelector = $( el ), 75 currentAttrSelectorVal = $currentAttrSelector.val() || ''; 76 77 $currentAttrSelector.find( 'option.attached.enabled[value="' + self.addSlashes( currentAttrSelectorVal ) + '"]' ).attr( 'selected', 'selected' ); 78 }); 79 }); 80 81 /** 82 * Updates quantity to buttons 83 * 84 * When adding quantity to archives, the button data must be updated 85 */ 86 self.manageQuantity = () => { 87 const quantitySelector = 'input[name="quantity"]'; 88 const buttonSelector = 'button.add_to_cart_button'; 89 document.querySelectorAll( quantitySelector ).forEach( ( quantity ) => { 90 quantity.addEventListener( 'input', ( event ) => { 91 event.target.closest( 'form' ).querySelector( buttonSelector ).dataset.quantity = event.target.value; 92 } ); 93 } ); 94 95 return self; 96 }; 97 98 self.init = function() { 99 self.manageOnSale( $( document ) ) 100 .manageStarRating( $( document ) ) 101 .manageQuantity(); 102 }; 103 104 self.init(); 105 106}; 107 108jQuery( function( $ ) { 109 Toolset_WCV.FrontendInstance = new Toolset_WCV.Frontend( $ ); 110}); 111 112/** 113 * Callback that was forced after a View AJAX pagination event is completed! 114 * We removed it from PHP, keep it for backwards compatibility. 115 */ 116function wcviews_onsale_pagination_callback() {}
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.