1/* global sooFilter */ 2jQuery( document ).ready( function ( $ ) { 3 'use strict'; 4 5 // sooFilter is required for price slider 6 if ( typeof sooFilter !== 'undefined' ) { 7 8 $( document.body ).on( 'soo_price_filter_create soo_price_filter_slide', function ( event, min, max, item ) { 9 var $amount = $( item ).next( '.slider-amount' ), 10 $label = $amount.find( '.slider-label' ), 11 $min_input = $amount.find( 'input[data-min]' ), 12 $max_input = $amount.find( 'input[data-max]' ); 13 14 // Show preview price 15 if ( sooFilter.currency.position === 'left' ) { 16 17 $label.find( 'span.from' ).html( sooFilter.currency.symbol + min ); 18 $label.find( 'span.to' ).html( sooFilter.currency.symbol + max ); 19 20 } else if ( sooFilter.currency.position === 'left_space' ) { 21 22 $label.find( 'span.from' ).html( sooFilter.currency.symbol + ' ' + min ); 23 $label.find( 'span.to' ).html( sooFilter.currency.symbol + ' ' + max ); 24 25 } else if ( sooFilter.currency.position === 'right' ) { 26 27 $label.find( 'span.from' ).html( min + sooFilter.currency.symbol ); 28 $label.find( 'span.to' ).html( max + sooFilter.currency.symbol ); 29 30 } else if ( sooFilter.currency.position === 'right_space' ) { 31 32 $label.find( 'span.from' ).html( min + ' ' + sooFilter.currency.symbol ); 33 $label.find( 'span.to' ).html( max + ' ' + sooFilter.currency.symbol ); 34 35 } 36 37 // Disable inputs when it has no meaning 38 if ( min <= $min_input.data( 'min' ) ) { 39 $min_input.attr( 'disabled', 'disabled' ); 40 } else { 41 $min_input.removeAttr( 'disabled' ); 42 } 43 44 if ( max >= $max_input.data( 'max' ) ) { 45 $max_input.attr( 'disabled', 'disabled' ); 46 } else { 47 $max_input.removeAttr( 'disabled' ); 48 } 49 } ); 50 51 _.each( document.getElementsByClassName( 'filter-slider' ), function ( item ) { 52 var $this = $( item ), 53 $amount = $this.next( '.slider-amount' ), 54 $min_input = $amount.find( 'input[data-min]' ), 55 $max_input = $amount.find( 'input[data-max]' ), 56 min = parseInt( $min_input.data( 'min' ), 10 ), 57 max = parseInt( $max_input.data( 'max' ), 10 ), 58 current_min = parseInt( $min_input.val(), 10 ), 59 current_max = parseInt( $max_input.val(), 10 ); 60 61 current_min = current_min || min; 62 current_max = current_max || max; 63 64 $this.removeClass( 'hidden' ); 65 $amount.find( '.slider-label' ).removeClass( 'hidden' ); 66 $min_input.hide(); 67 $max_input.hide(); 68 69 $this.slider( { 70 animate: true, 71 range : true, 72 values : [current_min, current_max], 73 min : min, 74 max : max, 75 create : function () { 76 $min_input.val( current_min ); 77 $max_input.val( current_max ); 78 79 $( document.body ).trigger( 'soo_price_filter_create', [current_min, current_max, item] ); 80 $( document.body ).trigger( 'price_slider_create', [current_min, current_max] ); 81 }, 82 slide : function ( event, ui ) { 83 $min_input.val( ui.values[0] ); 84 $max_input.val( ui.values[1] ); 85 86 $( document.body ).trigger( 'soo_price_filter_slide', [ui.values[0], ui.values[1], item] ); 87 $( document.body ).trigger( 'price_slider_slide', [ui.values[0], ui.values[1]] ); 88 }, 89 change : function ( event, ui ) { 90 if ( ! event.originalEvent ) { 91 return; 92 } 93 94 var form = $( ui.handle ).closest( 'form' ).get( 0 ); 95 $( document.body ).trigger( 'soo_price_filter_change', [ui.values[0], ui.values[1], item] ).trigger( 'soo_filter_change', [form] ); 96 $( document.body ).trigger( 'price_slider_change', [ui.values[0], ui.values[1]] ); 97 } 98 } ); 99 } ); 100 } 101 102 // Swatch or list selection 103 $( document.body ).on( 'click', '.filter-swatches .swatch, .filter-list .filter-list-item', function ( event ) { 104 event.preventDefault(); 105 var $this = $( this ), 106 $filter = $this.closest( '.product-filter' ), 107 $input = $this.parent().next( 'input[type=hidden]' ), 108 current = $input.val(), 109 value = $this.data( 'value' ), 110 form = $( this ).closest( 'form' ).get( 0 ), 111 index = -1; 112 113 if ( $filter.hasClass( 'multiple' ) ) { 114 115 current = current ? current.split( ',' ) : []; 116 index = current.indexOf( value ); 117 118 if ( index === -1 ) { 119 index = current.indexOf( value.toString() ); 120 } 121 122 if ( index !== -1 ) { 123 current = _.without( current, value ); 124 } else { 125 current.push( value ); 126 } 127 128 $input.val( current.join( ',' ) ); 129 $this.toggleClass( 'selected' ); 130 131 if ( current.length === 0 ) { 132 $input.attr( 'disabled', 'disabled' ); 133 } else { 134 $input.removeAttr( 'disabled' ); 135 } 136 } else { 137 138 if ( $this.hasClass( 'selected' ) ) { 139 $this.removeClass( 'selected' ); 140 $input.val( '' ).attr( 'disabled', 'disabled' ); 141 } else { 142 $this.addClass( 'selected' ).siblings( '.selected' ).removeClass( 'selected' ); 143 $input.val( value ).removeAttr( 'disabled' ); 144 } 145 146 } 147 148 $( document.body ).trigger( 'soo_filter_change', [form] ); 149 } ); 150 151 // Trigger change form event 152 $( document.body ).on( 'change', '.soo-product-filter-widget input, .soo-product-filter-widget select', function () { 153 var form = $( this ).closest( 'form' ).get( 0 ); 154 $( document.body ).trigger( 'soo_filter_change', [form] ); 155 } ); 156 157 // Ajax filter 158 var ajax = null; 159 160 $( document.body ).on( 'soo_filter_change', function ( event, form ) { 161 var $form = $( form ), 162 $container = $( sooFilter.selector.products ), 163 $navContainer = $( sooFilter.selector.nav ), 164 $counterContainer = $( sooFilter.selector.counter ), 165 action = $form.attr( 'action' ), 166 separator = action.indexOf( '?' ) !== -1 ? '&' : '?', 167 url = action + separator + $form.serialize(); 168 169 if ( !$container.length ) { 170 $container = $( sooFilter.selector.notfound ); 171 } 172 173 if ( !$form.hasClass( 'ajax-filter' ) ) { 174 return; 175 } 176 177 if ( ajax ) { 178 ajax.abort(); 179 } 180 181 $( document.body ).trigger( 'soo_filter_before_send_request', $container ); 182 183 ajax = $.get( url, function ( res ) { 184 var $res = $( res ), 185 $content = $res.find( sooFilter.selector.products ), 186 $nav = $res.find( sooFilter.selector.nav ), 187 $counter = $res.find( sooFilter.selector.counter ); 188 189 if ( !$content.length ) { 190 $content = $res.find( sooFilter.selector.notfound ); 191 $counterContainer.fadeOut(); 192 193 $container.replaceWith( $content ); 194 } else { 195 $container.replaceWith( $content ); 196 $counterContainer.replaceWith( $counter ).fadeIn(); 197 198 if ( $nav.length ) { 199 if ( $navContainer.length ) { 200 $navContainer.replaceWith( $nav ); 201 } else { 202 $nav.insertAfter( sooFilter.selector.products ); 203 $navContainer = $nav; 204 } 205 } else { 206 $navContainer.hide(); 207 } 208 } 209 210 $( document.body ).trigger( 'soo_filter_request_success', [res, url] ); 211 } ); 212 } ); 213 214 $( document.body ).on( 'soo_filter_before_send_request', function ( event, container ) { 215 $( container ).css( 'opacity', 0.5 ); 216 $( this ).addClass( 'soo_filtering_products' ); 217 } ); 218 219 $( document.body ).on( 'soo_filter_request_success', function ( e, response, url ) { 220 $( this ).removeClass( 'soo_filtering_products' ); 221 222 // Update result count 223 $( '.woocommerce-result-count' ).replaceWith( $( response ).find( '.woocommerce-result-count' ) ); 224 $( 'form.woocommerce-ordering' ).replaceWith( $( response ).find( 'form.
224woocommerce-ordering' ) ); 225 226 $( '.woocommerce-ordering' ).on( 'change', 'select.orderby', function() { 227 $( this ).closest( 'form' ).submit(); 228 }); 229 230 if ( '?' === url.slice( -1 ) ) { 231 url = url.slice( 0, -1 ); 232 } 233 234 url = url.replace( /%2C/g, ',' ); 235 236 history.pushState( null, '', url ); 237 } ); 238} );
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.