PageSourceSearch

https://orionbjj.com/wp-content/plugins/trx_addons/components/api/woocommerce/woocommerce.js

js orionbjj.com collected 2026-10-06 20:56:37 UTC 61,884 bytes, 1,411 lines download raw bytes

1/* global jQuery */
2
3(function() {
4	"use strict";
5
6	var $window   = jQuery( window ),
7		$document = jQuery( document ),
8		$body     = jQuery( 'body' );
9
10	$document.on('action.before_init_trx_addons', function() {
11		// Remove theme-animations inside sliders with WooCommerce products
12		jQuery( '.slides.products .slider-slide' ).each( function() {
13			var $self = jQuery( this );
14			$self.find( '>[data-animation]' ).removeAttr( 'data-animation' );
15			$self.find( '>[data-post-animation]' ).removeAttr( 'data-post-animation' );
16		} );
17	} );
18
19	$document.on('action.ready_trx_addons', function() {
20
21		// WooCommerce categories on homepages
22		//----------------------------------------------------------
23
24		// Add arrows to the WooCommerce categories on homepages
25		if ( ! $body.hasClass( 'woocommerce' ) ) {
26			$body.find( '.widget_area:not(.footer_wrap) .widget_product_categories:not(.inited)' ).each( function() {
27				var widget = jQuery(this).addClass('inited');
28				widget.find('ul.product-categories .has_children > a').append('<span class="open_child_menu"></span>');
29				widget.on('click', 'ul.product-categories.plain li a .open_child_menu', function(e) {
30					var $a = jQuery(this).parent();
31					if ($a.siblings('ul:visible').length > 0)
32						$a.siblings('ul').slideUp().parent().removeClass('opened');
33					else {
34						jQuery(this).parents('li').siblings('li').find('ul:visible').slideUp().parent().removeClass('opened');
35						$a.siblings('ul').slideDown().parent().addClass('opened');
36					}
37					e.preventDefault();
38					return false;
39				} );
40
41				// Resize handlers
42				jQuery(document).on('action.resize_trx_addons', function() {
43					trx_addons_woocommerce_resize_actions();
44				});
45				trx_addons_woocommerce_resize_actions();
46			
47				// Switch popup menu / hierarchical list on product categories list placed in sidebar
48				function trx_addons_woocommerce_resize_actions() {
49					var cat_menu = widget.find('ul.product-categories');
50					var sb = cat_menu.parents('.widget_area');
51					if ( sb.length > 0 && cat_menu.length > 0 ) {
52						if ( sb.width() == sb.parents('.content_wrap').width() ) {
53							if ( cat_menu.hasClass('inited') ) {
54								cat_menu.removeClass('inited').addClass('plain').superfish('destroy');
55								cat_menu.find('ul.animated').removeClass('animated').addClass('no_animated');
56							}
57						} else {
58							if ( ! cat_menu.hasClass('inited') ) {
59								cat_menu.removeClass('plain').addClass('inited');
60								cat_menu.find('ul.no_animated').removeClass('no_animated').addClass('animated');
61								trx_addons_init_sfmenu('body:not(.woocommerce) .widget_area:not(.footer_wrap) .widget_product_categories ul.product-categories');
62							}
63						}
64					}
65				}
66			});
67		}
68
69		
70		// Extended attributes in single product
71		//----------------------------------------------------------
72
73		// Change a behaviour to AJAX for the button 'Add to Cart' placed inside the popup 'Quick View'
74		function trx_addons_woocommerce_add_to_cart_ajax( type ) {
75			var $popup = $body.find( ( type == 'popup_yith' ? '>#yith-quick-view-modal' : '>.mfp-wrap' ) );
76			if ( $popup.length ) {
77				var $bt = $popup.find( '.single_add_to_cart_button' );
78				if ( $bt.length ) {
79					$bt.addClass( 'add_to_cart_button ajax_add_to_cart' )
80						.attr( 'data-product_id', $bt.attr( 'value' ) );
81					$popup.find( '.input-text.qty' )
82						.on( 'change', function() {
83							$bt.attr( 'data-quantity', jQuery( this ).val() );
84						} );
85				}
86			}
87		}
88		if ( trx_addons_apply_filters( 'trx_addons_filter_ajax_add_to_cart_in_quick_view', true ) ) {
89			jQuery( document.body ).on( 'woosq_loaded', function() {
90				trx_addons_woocommerce_add_to_cart_ajax( 'popup_wpc' );
91			} );
92			$document.on( 'qv_loader_stop', function() {
93				trx_addons_woocommerce_add_to_cart_ajax( 'popup_yith' );
94			} );
95		}
96
97		// Init product attributes with variations
98		jQuery( document.body ).on( 'woosq_loaded', function( e ) {
99			trx_addons_woocommerce_init_variations( 'popup_wpc', $body );
100		} );
101		$body.on( 'wcpt_product_modal_ready', function( e ) {
102			$document.trigger( 'action.init_hidden_elements', [$body] );
103		} );
104
105		$document.on( 'action.init_hidden_elements qv_loader_stop', function( e, cont ) {
106			if ( ! cont ) cont = $body;
107			trx_addons_woocommerce_init_variations( e.type == 'qv_loader_stop' ? 'popup_yith' : 'init_hidden', cont );
108		} );
109
110		// Check available product variations
111		function trx_addons_woocommerce_init_variations( type, cont ) {
112			cont.find( '.variations_form.cart:not(.inited)' ).each( function() {
113				var form = jQuery(this).addClass('inited');
114				var trx_addons_attribs = form.find('.trx_addons_attrib_item');
115				if ( trx_addons_attribs.length === 0 ) return;
116				
117				// First check after variation form inited
118				form.on( 'wc_variation_form', function( variation_form ) {
119					form.on( 'check_variations', function() {
120						trx_addons_woocommerce_check_variations( form );
121					} );
122					trx_addons_woocommerce_check_variations( form );
123				} );
124
125				// Click on our variations attribs
126				trx_addons_attribs.on( 'click', function(e) {
127					var $attrib = jQuery(this);
128					e.preventDefault();
129					if ( ! $attrib.hasClass('trx_addons_attrib_disabled') ) {
130						$attrib.toggleClass('trx_addons_attrib_selected').siblings().removeClass('trx_addons_attrib_selected');
131						var term = $attrib.hasClass('trx_addons_attrib_selected') ? $attrib.data('value') : '';
132						if ( term === '' ) {
133							$attrib.siblings('.trx_addons_attrib_item[data-value=""]').addClass('trx_addons_attrib_selected');
134						}
135						var attrib_name = $attrib.parents('.trx_addons_attrib_extended').data('attrib');
136						$attrib.parents('.trx_addons_attrib_extended').parent().find('#'+attrib_name).val(term).trigger('change');
137					}
138					return false;
139				} );
140			} );
141		}
142		
143		function trx_addons_woocommerce_check_variations( form ) {
144			// Refresh attributes on selects are changed
145			form.find( '.variations select' ).each( function() {
146				var select_box = jQuery(this),
147					select_val = select_box.val(),
148					attrib_box = select_box.siblings('.trx_addons_attrib_extended').length == 1 
149									? select_box.siblings('.trx_addons_attrib_extended')
150									: select_box.parent().siblings('.trx_addons_attrib_extended');
151				attrib_box.find('.trx_addons_attrib_item').removeClass('trx_addons_attrib_selected').addClass('trx_addons_attrib_disabled');
152				select_box.find('option').each( function() {
153					var opt = jQuery( this );
154					attrib_box.find( '.trx_addons_attrib_item[data-value="' + opt.val() + '"]' )
155								.removeClass( 'trx_addons_attrib_disabled' )
156								.toggleClass( 'trx_addons_attrib_selected', opt.val() == select_val );//opt.get(0).selected
157				} );
158			} );
159		}
160
161		
162		// Extended attributes in the products list (shop page or category/tag list)
163		//----------------------------------------------------------
164		if ( true || $body.hasClass( 'woocommerce' ) && $body.hasClass( 'archive' ) ) {
165			$document.on( 'action.init_hidden_elements', function( e, cont ) {
166				// If products with attributes are not present on this page - exit
167				if ( ! jQuery( '.trx_addons_product_attributes' ).length ) return;
168				// Click on the attribute - add filter
169				cont
170					.find( '.trx_addons_product_attribute_item_action_filter:not(.attribute_action_filter_inited)' )
171					.addClass( 'attribute_action_filter_inited' )
172					.on( 'click', function( e ) {
173						var flt    = jQuery( this ),
174							item   = flt.parent(),
175							type   = item.data( 'type' ),
176							attr   = item.data( 'attribute' ),
177							value  = item.data( 'value' ),
178							widget = jQuery( '.trx_addons_woocommerce_search_type_filter' ).eq(0);
179						if ( widget.length ) {
180							var widget_fld = widget.find( '.sc_form_field_' + attr );
181							if ( widget_fld.length ) {
182								var widget_item = widget_fld.find( '.sc_form_field_item[data-value="' + value + '"]' ).eq( 0 );
183								if ( widget_item.length && ! widget_item.hasClass( 'sc_form_field_item_checked' ) ) {
184									widget_item.trigger( 'click' );
185									var apply = widget_fld.find( '.trx_addons_search_apply' );
186									if ( apply.length ) {
187										apply.trigger( 'click' );
188									}
189								}
190							}
191						}
192						e.preventDefault();
193						return false;
194					} );
195				// Click on the attribute - swap image
196				var $swap_atts = cont
197									.find( '.trx_addons_product_attribute_item_action_swap:not(.attribute_action_swap_inited)' )
198									.addClass( 'attribute_action_swap_inited' );
199				if ( $swap_atts.length ) {
200					$swap_atts.on( 'click', function( e ) {
201						var $link = jQuery( this ),
202							$item = $link.parent(),
203							active = $item.hasClass( 'trx_addons_product_attribute_item_active' ),
204							disabled = $item.hasClass( 'trx_addons_product_attribute_item_disabled' );
205						if ( ! disabled ) {
206							$item.parents( '.trx_addons_product_attribute' )
207								.find( '.trx_addons_product_attribute_item_active' )
208								.removeClass( 'trx_addons_product_attribute_item_active' );
209							swap_product_image( $item.toggleClass( 'trx_addons_product_attribute_item_active', ! active ) );
210							check_available_variations( $item.parents( '.trx_addons_product_attributes' ) );
211						}
212						e.preventDefault();
213						return false;
214					} );
215					// Swap image and display corresponding price on first run or after new products are loaded
216					swap_product_image( $swap_atts.eq(0) );
217					// Check variations on first run or after new products are loaded
218					$swap_atts.parents( '.trx_addons_product_attributes' ).each( function() {
219						check_available_variations( jQuery( this ) );
220					} );
221				}
222				// Hover on the attribute - change the product image
223				cont
224					.find( '.trx_addons_product_attributes[data-product-variations] .trx_addons_product_attribute_item:not(.attribute_action_swap_inited)' )
225					.addClass( 'attribute_action_swap_inited' )
226					.on( 'focus mouseover', function( e ) {
227						var $self = jQuery( this );
228						if ( ! $self.find( '>.trx_addons_product_attribute_item_action_swap' ).length ) {
229							swap_product_image( $self );
230						}
231					} );
232
233				// Check available variations for product in the archive
234				function check_available_variations( $wrap ) {
235					var variations = $wrap.data( 'product-variations' ),
236						variation_sel = {},
237						$active_items = $wrap.find( '.trx_addons_product_attribute_item_active' );
238					// Collect active items to the current variation
239					$active_items.each( function( idx ) {
240						variation_sel[ $active_items.eq( idx ).data( 'attribute' ) ] = $active_items.eq( idx ).data( 'value' );
241					} );
242					$wrap.find( '.trx_addons_product_attribute_item' ).each( function() {
243						var $attr = jQuery( this ),
244							attr_name = $attr.data( 'attribute' ),
245							attr_value = $attr.data( 'value' ),
246							attr_variation = trx_addons_object_clone( variation_sel );
247						attr_variation[ attr_name ] = attr_value;
248						$attr.toggleClass( 'trx_addons_product_attribute_item_disabled', get_closest_variation( variations, attr_variation ) === false );
249					} );
250				}
251
252				// Get a closest variation
253				function get_closest_variation( variations, variation_sel ) {
254					var variation = false,
255						variation_max = 0,
256						variation_cur = 0;
257					for ( var i = 0; i < variations.length; i++ ) {
258						if ( ! variations[i].variation_is_active || ! variations[i].variation_is_visible ) {
259							continue;
260						}
261						variation_cur = 0;
262						for ( var attr in variation_sel ) {
263							if ( ! variations[i].attributes['attribute_'+attr] ) {
264								variation_cur += 1;
265							} else if ( variations[i].attributes['attribute_' + attr] == variation_sel[attr] ) {
266								variation_cur += 10;
267							} else {
268								variation_cur = 0;
269								break;
270							}
271						}
272						if ( variation_max < variation_cur ) {
273							variation_max = variation_cur;
274							variation = variations[i];
275						}
276					}
277					return variation;
278				}
279
280				// Return true if all attributes from variation are selected
281				function is_full_variation_present( variations, variation_sel_count ) {
282					var variation_total = 0;
283					for ( var i = 0; i < variations.length; i++ ) {
284						if ( ! variations[i].variation_is_active || ! variations[i].variation_is_visible ) {
285							continue;
286						}
287						for ( var p in variations[i].attributes ) {
288							if ( variations[i].attributes.hasOwnProperty( p ) ) {
289								variation_total++;
290							}
291						}
292						break;
293					}
294					return variation_total == variation_sel_count;
295				}
296
297				// Swap a product image on an attribute hover or click
298				function swap_product_image( $flt ) {
299					var $wrap = $flt.parents( '.trx_addons_product_attributes' ),
300						$product = $flt.parents( '.product' ),
301						variations = $wrap.data( 'product-variations' ),
302						variation = false,
303						variation_sel = {},
304						variation_sel_count = 0;
305					if ( variations ) {
306						// Collect active items to the current variation
307						var $active_items = $wrap.find( '.trx_addons_product_attribute_item_action_swap' ).length
308												? $wrap.find( '.trx_addons_product_attribute_item_active' )
309												: $flt;
310						$active_items.each( function( idx ) {
311							variation_sel[ $active_items.eq( idx ).data( 'attribute' ) ] = $active_items.eq( idx ).data( 'value' );
312							variation_sel_count++;
313						} );
314						// Get a closest variation
315						if ( variation_sel_count ) {
316							variation = get_closest_variation( variations, variation_sel );
317						}
318						// Swap image if a variation found
319						// or change back the original image if a variation with selected atributes is not found
320						var $img = $product.find( 'img[class*="attachment-woocommerce"],img[class*="woocommerce-placeholder"]' );
321						if ( $img.length ) {
322							if ( ! $img.data( 'src-old' ) ) {
323								$img.data( {
324									'src-old': $img.attr( 'src' ),
325									'srcset-old': $img.attr( 'srcset' ),
326									'sizes-old': $img.attr( 'sizes' )
327								} );
328							}
329							if ( variation ) {
330								$img.attr( {
331									'src': variation.image.src,
332									'srcset': variation.image.srcset ? variation.image.srcset : '',
333									'sizes': variation.image.sizes ? variation.image.sizes : ''
334								} );
335							} else {
336								$img.attr( {
337									'src': $img.data( 'src-old' ),
338									'srcset': $img.data( 'srcset-old' ),
339									'sizes': $img.data( 'sizes-old' )
340								} );
341							}
342						}
343						// Swap price if a full variation found (all attributes present in the item and selected)
344						// or change back the original price if a variation with selected atributes is not found
345						if ( trx_addons_apply_filters( 'trx_addons_filter_swap_price_for_variable_products', is_full_variation_present( variations, variation_sel_count ) ) ) {
346							var $price = $product.find( '.price_wrap' );
347							if ( ! $price.length ) {
348								$price = $product.find( '.price' );
349							}
350							if ( $price.length ) {
351								if ( ! $price.data( 'price-old' ) ) {
352									$price.data( {
353										'price-old': $price.html()
354									} );
355								}
356								if ( variation ) {
357									// A 'price_html' can be empty if all variations have an equal price.
358									// In this case leave a price unchanged.
359									if ( variation.price_html != '' ) {
360										$price.html( $price.hasClass( 'price_wrap' ) ? variation.price_html : jQuery( variation.price_html ).html() );
361									}
362								} else {
363									$price.html( $price.data( 'price-old' ) );
364								}
365							}
366						}
367					}
368				}
369			} );
370		}
371
372
373		// WooCommerce Search Widget
374		//----------------------------------------------------------
375		
376		var reopen_after_reload = trx_addons_apply_filters( 'trx_addons_filter_reopen_filter_after_reload_products', false ),
377			reopened = false,
378			reload_is_busy = false,
379			reload_is_allowed = true,
380			last_clicked_item = '',
381			last_opened_filter = '',
382			inline_css_selector = trx_addons_apply_filters( 'trx_addons_filter_reload_inline_css_selector', '#trx_addons-inline-styles-inline-css' ),
383			inline_css_wrap = jQuery( inline_css_selector ),
384			inline_css_start = trx_addons_apply_filters( 'trx_addons_filter_reload_inline_css_start', '#woocommerce_output_start{}' ),
385			inline_css_end = trx_addons_apply_filters( 'trx_addons_filter_reload_inline_css_end', '#woocommerce_output_end{}' ),
386			list_products_selector = trx_addons_apply_filters( 'trx_addons_filter_reload_products_selector', '.list_products' ),
387			list_products_wrap = jQuery( list_products_selector ),
388			list_products_loading = 0,
389			list_products_loading_class = '.trx_addons_loading',
390			list_products_loading_selector  = trx_addons_apply_filters( 'trx_addons_filter_reload_products_loading_wrap_selector',
391																		'.list_products .products,.list_products .woocommerce-info,.woocommerce-no-products-found'
392																		),
393			list_products_loading_html  = trx_addons_apply_filters( 'trx_addons_filter_reload_products_loading_html',
394																	'<div class="trx_addons_loading"></div>'
395																	),
396			single_product_selector = trx_addons_apply_filters( 'trx_addons_filter_single_product_selector', '.post_item_single.post_type_product' ),
397			mask_fields_wrap_on_loading = true;
398
399		$document.on( 'action.init_hidden_elements', function() {
400
401			// Reinit search form after page reloaded
402			var search_forms = jQuery('.trx_addons_woocommerce_search_form:not(.inited)');
403			if ( search_forms.length ) {
404				search_forms.each( function() {
405					var form   = jQuery(this).addClass('inited'),
406						widget = form.parents('.trx_addons_woocommerce_search'),
407						type   = widget.hasClass( 'trx_addons_woocommerce_search_type_filter')
408									? 'filter'
409									: ( widget.hasClass( 'trx_addons_woocommerce_search_type_form')
410										? 'form'
411										: 'inline'
412										),
413						apply  = widget.hasClass( 'trx_addons_woocommerce_search_apply' ),
414						ajax   = widget.hasClass( 'trx_addons_woocommerce_search_ajax' ),
415						number = widget.data('number') || 1,
416						expanded = widget.data('expanded') || 0;
417
418					form
419						// Submit form ('inline' or 'form' styles)
420						.on('submit', function(e) {
421							var shop_url = form.attr('action');
422							var params = trx_addons_woocommerce_search_form_get_params(form);
423							if (params !== false) {
424								window.location.href = trx_addons_add_to_url(shop_url, params);
425							} else {
426								e.preventDefault();
427							}
428							return false;
429						})
430						// Enable/Disable submit button ('inline' or 'form' styles)
431						.on('change', 'select,input', function(e) {
432							var button = form.find('.trx_addons_woocommerce_search_button');
433							if ( button.length ) {
434								var params = trx_addons_woocommerce_search_form_get_params(form);
435								if (params === false) {
436									button.attr('disable', 'disable');
437								} else {
438									button.removeAttr('disable');
439								}
440							}
441						})
442						// Open/Close dropdown with items ('inline' style)
443						.on('click', '.trx_addons_woocommerce_search_form_field_label', function(e) {
444							jQuery(this)
445								.parent('.trx_addons_woocommerce_search_form_field')
446								.siblings('.trx_addons_woocommerce_search_form_field')
447								.find('.trx_addons_woocommerce_search_form_field_list').slideUp();
448							jQuery(this).siblings('.trx_addons_woocommerce_search_form_field_list').slideToggle();
449							e.preventDefault();
450							return false;
451						})
452						// Select item in the 'inline' form
453						.on('click', '.trx_addons_woocommerce_search_form_field_list li', function(e) {
454							var list = jQuery(this).parent();
455							list.siblings('.trx_addons_woocommerce_search_form_field_label').html(jQuery(this).html());
456							list.siblings('input[type="hidden"]').val(jQuery(this).data('value'));
457							list.slideUp();
458							e.preventDefault();
459							return false;
460						})
461						// Keypress on the field's title
462						.on('keyup', '.sc_form_field_title', function(e) {
463							if ( type == 'filter' ) {
464								if ( e.keyCode == 13 ) {
465									jQuery(this).trigger('click');
466								}
467							}
468						})
469						// Open/Close dropdown with items ('filter' style)
470						.on('click', '.sc_form_field_title', function(e) {
471							if ( type == 'filter' ) {
472								var $self  = jQuery(this),
473									field  = $self.parent(),
474									opened = field.hasClass('sc_form_field_opened');
475								// Close all opened fields
476								if ( $self.parents('.trx_addons_woocommerce_tools').length !== 0
477									&& $self.parents('.trx_addons_woocommerce_search_form_fields_wrap_opened').length === 0
478								) {
479									$self
480										.parents('.trx_addons_woocommerce_search_form_fields_wrap')
481										.find('.sc_form_field_opened').each( function() {
482											var cur_field = jQuery( this ),
483												cur_param = cur_field.find( '.sc_form_field_param' ),
484												cur_apply = cur_field.find( '.trx_addons_search_apply' ),
485												need_apply = apply && cur_apply.length && ! cur_apply.attr('disabled') && cur_param.data('changed');
486											if ( need_apply ) {
487												cur_apply.trigger( 'click' );
488											} else {
489												trx_addons_woocommerce_search_form_close_field( cur_field );	// , apply
490											}
491										} );
492								} else if ( opened ) {
493									var cur_apply = field.find( '.trx_addons_search_apply' ),
494										cur_param = field.find( '.sc_form_field_param' ),
495										need_apply = apply && cur_apply.length && ! cur_apply.attr('disabled') && cur_param.data('changed');
496									if ( false && need_apply ) {	// Don't apply on click a title in sidebar or mobile
497										cur_apply.trigger( 'click' );
498									} else {
499										trx_addons_woocommerce_search_form_close_field( field );	// , apply
500									}
501								}
502								// Open clicked field
503								if ( ! opened ) {
504									trx_addons_woocommerce_search_form_open_field( field );
505								}
506								e.preventDefault();
507								return false;
508							}
509						})
510						// Keypress on the field's title
511						.on('keyup', '.sc_form_field_item', function(e) {
512							if ( type == 'filter' ) {
513								if ( e.keyCode == 13 ) {
514									jQuery(this).trigger('click');
515								} else if ( e.keyCode == 27 ) {
516									jQuery(this).parents('.sc_form_field').find('.sc_form_field_title').focus().trigger('click');
517								}
518							}
519						})
520						// Check item in the select ('filter' style)
521						.on('click', '.sc_form_field .sc_form_field_item', function(e) {
522							if ( type == 'filter' ) {
523								var $self = jQuery(this),
524									wrap  = $self.parents('.sc_form_field_wrap'),
525									multi = $self.parents('.sc_form_field').data('multiple') == '1';
526								last_clicked_item = $self.data('value');
527								if ( ! multi ) {
528									wrap.find('.sc_form_field_item_checked').removeClass('sc_form_field_item_checked');
529								}
530								$self.toggleClass('sc_form_field_item_checked');
531								var value = trx_addons_woocommerce_search_form_get_multiple_field_value( wrap );
532								wrap.find( '.sc_form_field_param' ).val( value ).trigger( 'change' );
533								e.preventDefault();
534								return false;
535							}
536						})
537						// All fields: Keypress on the 'Clear all' button
538						.on('keyup', '.trx_addons_woocommerce_search_clear_all', function(e) {
539							if ( type == 'filter' ) {
540								if ( e.keyCode == 27 ) {
541									jQuery(this).siblings('.trx_addons_woocommerce_search_close').trigger('click');
542								}
543							}
544						})
545						// All fields: Clear all selected items in the multiselect fields
546						.on('click', '.trx_addons_woocommerce_search_clear_all', function(e) {
547							e.preventDefault();
548							if ( type == 'filter' ) {
549								var need_reload = false;
550								reload_is_allowed = false;
551								form.find('.sc_form_field').each( function() {
552									var $self = jQuery(this),
553										param = $self.find( '.sc_form_field_param' );
554									if ( param.attr('name') != 'product_cat' && param.val() !== '' ) {
555										var field = param.parents('.sc_form_field'),
556											value = '';
557										if ( field.hasClass( 'sc_form_field_slider' ) ) {
558											value = param.next().data('min');
559										} else if ( field.hasClass( 'sc_form_field_range' ) ) {
560											value = param.next().data('min') + ',' + param.next().data('max');
561										}
562										need_reload = true;
563										param.val( value ).trigger( 'change' );
564										trx_addons_woocommerce_search_form_restore_field_view( $self );
565									}
566								} );
567								reload_is_allowed = true;
568								if ( need_reload ) {
569									trx_addons_woocommerce_search_form_reload_products( form );
570								}
571							}
572							return false;
573						})
574						// Keypress on the 'Clear all' button
575						.on('keyup', '.sc_form_field_items_selected_clear', function(e) {
576							if ( type == 'filter' ) {
577								if ( e.keyCode == 27 ) {
578									jQuery(this).parents('.sc_form_field').find('.sc_form_field_title').focus().trigger('click');
579								}
580							}
581						})
582						// Clear all selected items in the multiselect fields
583						.on('click', '.sc_form_field_items_selected_clear', function(e) {
584							e.preventDefault();
585							if ( type == 'filter' ) {
586								var $self = jQuery(this),
587									wrap  = $self.parents('.sc_form_field_wrap');
588								wrap.find( '.sc_form_field_param' ).val( '' ).trigger( 'change' );
589								trx_addons_woocommerce_search_form_restore_field_view( wrap.parents( '.sc_form_field' ) );
590							}
591							return false;
592						})
593						// Keypress on the 'Select all' button
594						.on('keyup', '.sc_form_field_items_selected_select_all', function(e) {
595							if ( type == 'filter' ) {
596								if ( e.keyCode == 27 ) {
597									jQuery(this).parents('.sc_form_field').find('.sc_form_field_title').focus().trigger('click');
598								}
599							}
600						})
601						// Select all items in the multiselect fields
602						.on('click', '.sc_form_field_items_selected_select_all', function(e) {
603							e.preventDefault();
604							if ( type == 'filter' ) {
605								var $self = jQuery(this),
606									wrap  = $self.parents('.sc_form_field_wrap');
607								wrap.find('.sc_form_field_item').toggleClass('sc_form_field_item_checked', true);
608								var value = trx_addons_woocommerce_search_form_get_multiple_field_value( wrap );
609								wrap.find( '.sc_form_field_param' ).val( value ).trigger( 'change' );
610							}
611							return false;
612						})
613						// Update 'param' field on change text ('filter' style)
614						.on('change', '.sc_form_field_text .sc_form_field_input', function(e) {
615							if ( type == 'filter' ) {
616								var $self = jQuery(this),
617									wrap  = $self.parents('.sc_form_field_wrap');
618								wrap.find( '.sc_form_field_param' ).val( $self.val() ).trigger( 'change' );
619							}
620						})
621						// Prevent submit form on Enter in the text field
622						.on('keydown', '.sc_form_field_text .sc_form_field_input', function(e) {
623							if ( type == 'filter' ) {
624								var $buttons = jQuery(this).parents('.sc_form_field_wrap').find('.sc_form_field_buttons');
625								if ( $buttons.length ) {
626									if ( e.keyCode == 13 ) {
627										var $apply = $buttons.find('.trx_addons_search_apply');
628										if ( $apply.length ) {
629											e.preventDefault();
630											jQuery(this).trigger('change');
631											$apply.trigger('click');
632										}
633									} else if ( e.keyCode == 27 ) {
634										var $cancel = $buttons.find('.trx_addons_search_cancel');
635										if ( $cancel.length ) {
636											e.preventDefault();
637											$cancel.trigger('click');
638										}
639									}
640								}
641							}
642						})
643						// Update result in the price range ('filter' style)
644						.on('change', '.sc_form_field_price .sc_form_field_param', function(e) {
645							if ( type == 'filter' ) {
646								var $self  = jQuery(this),
647									value  = $self.val().split(','),
648									slider = $self.next('.trx_addons_range_slider '),
649									result = slider.next('.trx_addons_range_result');
650								if ( result.length ) {
651									result.find('.trx_addons_range_result_value').html( value[0] + ( value.length > 1 ? ' - ' + value[1] : '' ) );
652								}
653							}
654						})
655						// Mark title as filled and update selected total value on param changed ('filter' style)
656						.on('change', '.sc_form_field_param', function(e) {
657							if ( type == 'filter' ) {
658								var $self = jQuery(this).data('changed', 1);
659								$self.parents('.trx_addons_woocommerce_search_form_fields_wrap').toggleClass('trx_addons_woocommerce_search_form_fields_changed', true);
660								trx_addons_woocommerce_search_form_param_changed( $self );
661							}
662						} )
663						// Remove attr 'disabled' from buttons 'Apply' and 'Cancel' on param changed ('filter' style)
664						.on('change', '.sc_form_field_param', function(e) {
665							if ( type == 'filter' ) {
666								var field_wrap = jQuery(this).parents('.sc_form_field_wrap');
667								field_wrap.find('.trx_addons_search_apply').removeAttr('disabled');
668								field_wrap.find('.trx_addons_search_cancel').removeAttr('disabled');
669							}
670						} )
671						// Update available (filtered) products counter on param changed ('filter' style)
672						.on('change', '.sc_form_field_param', function(e) {
673							var $self = jQuery(this),
674								fields_wrap = $self.parents('.trx_addons_woocommerce_search_form_fields_wrap').data('param-changed', 1);
675							if ( type == 'filter'
676									&& $self.attr('name') != 'product_cat'
677									&& ( fields_wrap.hasClass('trx_addons_woocommerce_search_form_fields_wrap_opened')
678										||
679										( fields_wrap.parents('.sidebar').length && ( apply || ajax ) )
680										)
681							) {
682								trx_addons_woocommerce_search_form_update_available_products_counter( form );
683							}
684						} )
685						// Reload page on any param are changed, except 's' and 'price' ('filter' style)
686						.on('change', '.sc_form_field_param', function(e) {
687							var $self = jQuery(this);
688							if ( type == 'filter' && reload_is_allowed ) {
689								if ( $self.attr('name') == 'product_cat' ) {
690									var $fld = $self.parents('.sc_form_field_opened'),
691										fld_idx = $fld.index();
692									if ( fld_idx > expanded ) {
693										trx_addons_woocommerce_search_form_close_field( $fld );
694									}
695									trx_addons_woocommerce_search_form_reload_products( form, $self, '.sc_form_field_param[name="product_cat"]', true );
696								} else if ( ! apply
697											&& ! $self.parents('.trx_addons_woocommerce_search_form_fields_wrap').hasClass('trx_addons_woocommerce_search_form_fields_wrap_opened')
698											&& ( ['price', 's'].indexOf($self.attr('name')) == -1 || $self.parents('.sidebar').length )
699								) {
700									trx_addons_woocommerce_search_form_reload_products_after_timeout( form, $self );
701								}
702							}
703						})
704						// Reload page on click button 'Apply' ('filter' style)
705						.on('click', '.trx_addons_search_apply', function(e) {
706							if ( type == 'filter' ) {
707								var $self = jQuery(this);
708								if ( ! $self.attr('disabled') ) {
709									if ( ! $self.parents('.trx_addons_woocommerce_search_form_fields_wrap').hasClass('trx_addons_woocommerce_search_form_fields_wrap_opened')
710										&& $self.parents('.sidebar').length === 0
711									) {
712										trx_addons_woocommerce_search_form_close_field( $self.parents('.sc_form_field_opened') );
713									}
714									trx_addons_woocommerce_search_form_reload_products( form, $self.parents('.sc_form_field').find('.sc_form_field_param') );
715								}
716								e.preventDefault();
717								return false;
718							}
719						})
720						// Restore values on click button 'Cancel' ('filter' style)
721						.on('click', '.trx_addons_search_cancel', function(e) {
722							if ( type == 'filter' ) {
723								var $self = jQuery(this);
724								if ( ! $self.attr('disabled') ) {
725									trx_addons_woocommerce_search_form_close_field( $self.parents('.sc_form_field_opened'), true );
726								}
727								e.preventDefault();
728								return false;
729							}
730						})
731						// Open/Close panel with filters
732						.on('click', '.trx_addons_woocommerce_search_button_filters,'
733									+'.trx_addons_woocommerce_search_button_show,'
734									+'.trx_addons_woocommerce_search_close',
735							function(e) {
736								var $self = jQuery(this),
737									applied = false,
738									wrap = form.find('.trx_addons_woocommerce_search_form_fields_wrap');
739								if ( $self.hasClass('trx_addons_woocommerce_search_button_filters') && ! wrap.hasClass('trx_addons_woocommerce_search_form_fields_wrap_opened') ) {
740									wrap.addClass('trx_addons_woocommerce_search_form_fields_wrap_opened');
741								} else {
742									if ( wrap.hasClass('trx_addons_woocommerce_search_form_fields_wrap_opened')
743										||
744										( $self.parents('.sidebar').length
745											&&
746											$self.parents('.trx_addons_woocommerce_search').hasClass('trx_addons_woocommerce_search_apply')
747											)
748									) {
749										if ( wrap.data('param-changed') > 0 ) {
750											var last_apply = last_opened_filter
751																? form.find('input[name="'+last_opened_filter+'"]')
752																	.parents('.sc_form_field')
753																	.find('.trx_addons_search_apply:not([disabled])')
754																: false;
755											if ( ! last_apply || ! last_apply.length || last_apply.attr('disabled') == 'disabled' ) {
756												last_apply = form.find('.trx_addons_search_apply:not([disabled])').eq(0);
757											}
758											applied = true;
759											if ( last_apply && last_apply.length && last_apply.attr('disabled') != 'disabled' ) {
760												last_apply.trigger( 'click' );
761											} else {
762												trx_addons_woocommerce_search_form_reload_products( form );
763											}
764										}
765									}
766									if ( true || ! applied ) {	// Always hide fields wrap on mobile
767										wrap.removeClass('trx_addons_woocommerce_search_form_fields_wrap_opened');
768									}
769								}
770								e.preventDefault();
771								return false;
772							}
773						);
774				
775					// Open initially toggled fields
776					if ( form.parents('.sidebar').length > 0 ) {
777						form.find('.sc_form_field_expanded').each( function() {
778							trx_addons_woocommerce_search_form_open_field( jQuery(this).removeClass('sc_form_field_expanded'), 'show', false );
779						} );
780					}
781
782					// Show/hide 'Clear all' on fields changed (exclude the field "Product category")
783					form.find('.trx_addons_woocommerce_search_form_fields_wrap')
784						.toggleClass( 'trx_addons_woocommerce_search_form_fields_filled', 
785										form.find('.sc_form_field:not(.sc_form_field_product_cat) .sc_form_field_title_filled').length > 0
786									);
787
788					// Reopen filter after reload products page ('filter' style)
789					if ( type == 'filter' && ! reopened ) {
790						reopened = true;
791						last_opened_filter = trx_addons_get_value_gp( 'last_filter' );
792						if ( last_opened_filter ) {
793							var last_stop = trx_addons_get_value_gp( 'last_stop' );
794							if ( last_stop > 0 ) {
795								trx_addons_document_animate_to( last_stop );
796							}
797							if ( reopen_after_reload && ! apply ) {
798								// Reopen fields wrap on mobile
799								/*
800								var fields_wrap = form.find('.trx_addons_woocommerce_search_form_fields_wrap');
801								if ( fields_wrap.length && ! fields_wrap.hasClass('trx_addons_woocommerce_search_form_fields_wrap_opened') && fields_wrap.css('position') == 'fixed' ) {
802									fields_wrap.addClass('trx_addons_woocommerce_search_form_fields_wrap_opened trx_addons_woocommerce_search_form_fields_wrap_show');
803									setTimeout( function() {
804										fields_wrap.removeClass('trx_addons_woocommerce_search_form_fields_wrap_show');
805									}, 500 );
806								}
807								*/
808								// Reopen last active field
809								var field = form.find('input[name="'+last_opened_filter+'"]').parents('.sc_form_field');
810								trx_addons_woocommerce_search_form_open_field( field );
811								last_clicked_item = trx_addons_get_value_gp( 'last_item' );
812								if ( last_clicked_item ) {
813									field.find('.sc_form_field_item[data-value="'+last_clicked_item+'"]').focus();
814								}
815							}
816						}
817					}
818
819					// Reload products ('filter' style)
820					function trx_addons_woocommerce_search_form_reload_products( form, filter, selector, force_reload_page ) {
821						// Get all filters to the params array
822						if ( selector === undefined ) {
823							selector = '.sc_form_field_param';
824						}
825						var params = trx_addons_woocommerce_search_form_get_params( form, selector );
826						// If any filter selected
827						if ( params !== false ) {
828							// Close last filter field
829							if ( filter
830								&& ( ! ajax || apply || force_reload_page )
831								&& filter.parents('.trx_addons_woocommerce_tools').length !== 0
832								&& filter.parents('.trx_addons_woocommerce_search_form_fields_wrap_opened').length === 0
833							) {
834								trx_addons_woocommerce_search_form_close_field( filter.parents('.sc_form_field_opened') );
835							}
836							// Add filter's name and window scroll position to the parameters
837							if ( last_opened_filter ) {
838								params['last_filter'] = last_opened_filter;
839							}
840							if ( last_clicked_item ) {
841								params['last_item'] = last_clicked_item;
842							}
843							// Add scroll top position to the query
844							params['last_stop'] = jQuery(window).scrollTop();
845							// Make query url
846							var shop_url = trx_addons_add_to_url(form.attr('action'), params),
847								fields_wrap = form.find('.trx_addons_woocommerce_search_form_fields_wrap').data('param-changed', 0);
848							// Reload products by AJAX
849							if ( ajax && ! force_reload_page ) {
850								trx_addons_woocommerce_search_form_get_products_from_url( shop_url, fields_wrap );
851							// Redirect page
852							} else {
853								jQuery( list_products_loading_selector )
854									.addClass( 'trx_addons_woocommerce_search_loading' )
855									.append( list_products_loading_html );
856								window.location.href = shop_url;
857							}
858						}
859					}
860
861					// Reload products after timeout ('filter' style)
862					var trx_addons_woocommerce_search_form_reload_products_after_timeout = trx_addons_throttle(
863							trx_addons_woocommerce_search_form_reload_products,
864							trx_addons_apply_filters( 'trx_addons_filter_reload_products_timeout', ajax ? 500 : 0 ),
865							true
866						);
867
868					// Update available products counter ('filter' style)
869					var trx_addons_woocommerce_search_form_update_available_products_counter = trx_addons_throttle(
870						function( form ) {
871							// Get all filters to the params array
872							var params = trx_addons_woocommerce_search_form_get_params( form, '.sc_form_field_param' );
873							// If any filter selected
874							if ( params !== false ) {
875								var shop_url = trx_addons_add_to_url(form.attr('action'), params),
876									counter  = form.find('.trx_addons_woocommerce_search_button_show_total');
877								if ( counter.length ) {
878									jQuery.get( shop_url ).done( function( response ) {
879										var value = jQuery( response ).find('.trx_addons_woocommerce_search_button_show_total').html();
880										if ( value !== '') {
881											counter.html( value );
882										}
883									} );
884								}
885							}
886						},
887						trx_addons_apply_filters( 'trx_addons_filter_update_products_counter_timeout', 500 ),
888						true
889					);
890
891				});
892			}
893
894			// WooCommerce NavFilters: AJAX reload products on filter removed (if woocommerce_search_filter is present near this widget)
895			jQuery( '.widget_layered_nav_filters:not(.trx_addons_woocommerce_search_compatibility_inited)' ).each( function() {
896				var $self = jQuery(this).addClass('trx_addons_woocommerce_search_compatibility_inited'),
897					widget_search = $self.siblings('.widget_woocommerce_search');
898				// Allow AJAX reload on filter removed only if widget 'Product Filter' is present on same sidebar
899				// and ajax search is turned on for the widget
900				// and field 'rating' is not present in the fields set (because WooCommerce don't mark this field in the widget Active filters)
901				if ( widget_search.length
902					&& widget_search.find('.trx_addons_woocommerce_search_ajax').length
903					&& widget_search.find('.sc_form_field_rating').length === 0 
904				) {
905					$self.find('a').on('click', function(e) {
906						var $link = jQuery(this),
907							list = $link.parents('ul').eq(0),
908							url = location.href;	//$link.attr('href');
909						e.preventDefault();
910						// Remove current filter from active filters
911						$link.parents('li').eq(0).fadeOut( 200, function() {
912							jQuery(this).remove();
913							// Prepare url - remove not exists filters
914							var parts = url.split('?'),
915								query = trx_addons_parse_query_string(url),
916								query_new = {},
917								query_val = [],
918								query_val_new = [];
919							for (var i in query) {
920								if ( i == 'min_price' || i == 'max_price' ) {
921									list.find('.chosen .amount').each( function() {
922										if ( jQuery(this).text().replace(/[\$\.\,]/g, '') == query[i].replace(/[\$\.\,]/g, '') ) {
923											query_new[i] = query[i];
924										}
925									} );
926								} else if ( i.substring(0, 7) == 'filter_' ) {
927									query_val = query[i].split(',');
928									query_val_new = [];
929									for (var j = 0; j < query_val.length; j++ ) {
930										if ( list.find('.chosen-' + i.substring(7) + '-' +query_val[j] ).length ) {
931											query_val_new.push( query_val[j] );
932										}
933									}
934									if ( query_val_new.length > 0 ) {
935										query_new[i] = query_val_new.join(',');
936									}
937								} else {
938									query_new[i] = query[i];
939								}
940							}
941							trx_addons_woocommerce_search_form_get_products_from_url( trx_addons_add_to_url( parts[0], trx_addons_woocommerce_search_form_add_orderby_to_query_params( query_new ) ) );
942						} );
943						return false;
944					} );
945				}
946			} );
947
948			// WooCommerce Ordering: Reload products on 'orderby' is changed
949			jQuery('.woocommerce-ordering:not(.trx_addons_woocommerce_search_compatibility_inited)').each( function() {
950				var form = jQuery( this ).addClass( 'trx_addons_woocommerce_search_compatibility_inited' ),
951					select = form.find( '.orderby' ),
952					widget_search = list_products_wrap.find( '.widget_woocommerce_search' ),
953					url = location.href.split( '?' );
954				if ( widget_search.length === 0 ) {
955					widget_search = jQuery( '.trx_addons_woocommerce_search_type_filter' ).eq(0).parents( '.widget_woocommerce_search' );
956				}
957				if ( widget_search.length ) {
958					select.on( 'change', function(e) {
959						var params = trx_addons_woocommerce_search_form_get_params( widget_search, '.sc_form_field_param' );
960						/*
961						var page = form.find('input[name="paged"]').val() || 1;
962						if ( page > 1 ) {
963							params['page'] = page;
964						}
965						*/
966						// Prevent to execute other scripts
967						e.preventDefault();
968						e.stopImmediatePropagation();
969						// If a widget with filters present and its mode is AJAX - get products via AJAX
970						if ( widget_search.find('.trx_addons_woocommerce_search_ajax').length ) {
971							trx_addons_woocommerce_search_form_get_products_from_url( trx_addons_add_to_url( url[0], params ) );
972						// Else - reload a current page with new params
973						} else {
974							jQuery( list_products_loading_selector )
975								.addClass( 'trx_addons_woocommerce_search_loading' )
976								.append( list_products_loading_html );
977							window.location.href = trx_addons_add_to_url( url[0], params );
978						}
979						return false;
980					} );
981				}
982			} );
983
984			// Open field ('filter' style)
985			function trx_addons_woocommerce_search_form_open_field( field, open_style, need_focus ) {
986				if ( open_style === undefined ) {
987					open_style = 'slideDown';
988				}
989				if ( need_focus === undefined ) {
990					need_focus = true;
991				}
992				var open_time = open_style == 'show'
993									? 0
994									: trx_addons_apply_filters( 'trx_addons_filter_woocommerce_filter_show_time', field.parents('.trx_addons_woocommerce_tools').length === 0 || field.parents('.trx_addons_woocommerce_search_form_fields_wrap_opened').length > 0 ? 300 : 0 );
995				// Save current value
996				var param = field.find( '.sc_form_field_param' );
997				param.data( 'old-value', param.val() );
998				// Mark field unchanged
999				param.data( 'changed', 0 );
1000				// Save last opened filter
1001				last_opened_filter = param.attr('name');
1002				// Set buttons 'Apply' and 'Cancel' to disabled
1003				if ( false && field.parents('.trx_addons_woocommerce_search').hasClass('trx_addons_woocommerce_search_apply') ) {
1004					field.find('.trx_addons_search_apply').attr('disabled', 'disabled');
1005					field.find('.trx_addons_search_cancel').attr('disabled', 'disabled');
1006				}
1007				// Open field wrap
1008				var wrap = field.addClass('sc_form_field_opened').find('.sc_form_field_wrap');
1009				if ( open_style == 'slideDown' && open_time > 0 ) {
1010					wrap.slideDown( open_time, function() {
1011						if ( need_focus && field.hasClass('sc_form_field_text') ) {
1012							field.find( 'input[type="text"]').focus();
1013						}
1014					} );
1015				} else {
1016					wrap.show();
1017					if ( need_focus && field.hasClass('sc_form_field_text') ) {
1018						field.find( 'input[type="text"]').focus();
1019					}
1020				}
1021			}
1022
1023			// Close field ('filter' style)
1024			function trx_addons_woocommerce_search_form_close_field( field, restore_value, close_style ) {
1025				// Restore last value
1026				if ( restore_value ) {
1027					trx_addons_woocommerce_search_form_restore_field_value( field );
1028				}
1029				last_opened_filter = '';
1030				// Close field wrap
1031				field.removeClass('sc_form_field_opened');
1032				if ( close_style === undefined ) {
1033					close_style = 'slideUp';
1034				}
1035				var close_time = close_style == 'hide'
1036									? 0
1037									: trx_addons_apply_filters( 'trx_addons_filter_woocommerce_filter_show_time', field.parents('.trx_addons_woocommerce_tools').length === 0 || field.parents('.trx_addons_woocommerce_search_form_fields_wrap_opened').length > 0 ? 300 : 0 );
1038				if ( close_style == 'slideUp' && close_time > 0 ) {
1039					field.find('.sc_form_field_wrap').slideUp( close_time );
1040				} else {
1041					field.find('.sc_form_field_wrap').hide();
1042				}
1043			}
1044
1045			// Restore field's value ('filter' style)
1046			function trx_addons_woocommerce_search_form_restore_field_value( field ) {
1047				var param = field.find('.sc_form_field_param'),
1048					value = param.data('old-value');
1049				// Restore old value in the param
1050				param.val( value );
1051				// Mark title as filled and update selected items and restore field's view (mark items as checked, restore search string, etc.)
1052				trx_addons_woocommerce_search_form_restore_field_view( field );
1053			}
1054
1055			// Restore field's view ('filter' style)
1056			function trx_addons_woocommerce_search_form_restore_field_view( field ) {
1057				var param = field.find('.sc_form_field_param'),
1058					value = param.val();
1059				// Mark title as filled and update selected items
1060				trx_addons_woocommerce_search_form_param_changed( param );
1061				// Restore field's view (mark items as checked, restore search string, etc.)
1062				if ( field.hasClass('sc_form_field_select')
1063					|| field.hasClass('sc_form_field_image')
1064					|| field.hasClass('sc_form_field_color')
1065					|| field.hasClass('sc_form_field_button')
1066				) {
1067					field.find('.sc_form_field_item_checked').removeClass('sc_form_field_item_checked');
1068					var parts = ( '' + value ).split( ',' );
1069					for (var i = 0; i < parts.length; i++ ) {
1070						field.find('[data-value="'+parts[i]+'"]').addClass('sc_form_field_item_checked');
1071					}
1072				} else if ( field.hasClass('sc_form_field_text') ) {
1073					field.find('.sc_form_field_input').val( value );
1074				} else if ( field.hasClass('sc_form_field_slider') ) {
1075					field.find('.ui-slider').slider( "value", value );
1076				} else if ( field.hasClass('sc_form_field_range') ) {
1077					field.find('.ui-slider').slider( "values", ( '' + value ).split( ',' ) );
1078				}
1079			}
1080
1081			// Mark title as filled and update selected total value on param changed ('filter' style)
1082			function trx_addons_woocommerce_search_form_param_changed(param) {
1083				var value    = param.val(),
1084					empty    = value === '',
1085					title_filled = !empty,
1086					wrap     = param.parents('.sc_form_field_wrap'),
1087					title    = wrap.siblings('.sc_form_field_title'),
1088					selected = title.find('.sc_form_field_selected_items'), //wrap.siblings('.sc_form_field_selected_items'),
1089					slider   = param.next('.trx_addons_range_slider '),
1090					fields_wrap = param.parents('.trx_addons_woocommerce_search_form_fields_wrap');
1091				// Mark title as 'filled'
1092				if ( slider.length == 1 ) {
1093					var min = slider.data('min'),
1094						max = slider.data('max'),
1095						val = value.split(',');
1096					title_filled = Number( val[0] ) !== Number( min ) || ( val.length > 1 && Number( val[1] ) !== Number( max ) );
1097					title.toggleClass( 'sc_form_field_title_filled', title_filled );
1098				} else {
1099					title.toggleClass( 'sc_form_field_title_filled', !empty );
1100				}
1101				// Update selected items counter
1102				wrap.find('.sc_form_field_items_selected_value').html( value ? value.split(',').length : 0 );
1103				// Update info with selected items
1104				if ( selected.length
1105					&& ( 
1106						wrap.parents('.trx_addons_woocommerce_tools').length === 0
1107						||
1108						fields_wrap.hasClass( 'trx_addons_woocommerce_search_form_fields_wrap_opened' )
1109						)
1110				) {
1111					// Get value to display below title
1112					//var value_to_show = decodeURIComponent(''+value).split(',').map(trx_addons_proper).join(', ');
1113					var value_to_show = '',
1114						parts = (''+value).split(','),
1115						$item = null;
1116					for ( var i=0; i<parts.length; i++ ) {
1117						// Try find a text label (name) of the selected item
1118						$item = wrap.find('.sc_form_field_item[data-value="'+parts[i]+'"] .sc_form_field_item_text');
1119						value_to_show += ( value_to_show ? ', ' : '' )
1120										+ ( $item.length && $item.text() == $item.html()
1121											? $item.text()											// Use text label (name)
1122											: trx_addons_proper( decodeURIComponent( parts[i] ) )	// Use selected slug (value)
1123											);
1124					}
1125					// Display selected items below title
1126					if ( selected.html() === '' && title_filled ) {
1127						selected.hide().html( value_to_show ).slideDown();
1128					} else if ( selected.html() !== '' && ! title_filled ) {
1129						selected.slideUp( function() {
1130							selected.html( '' ).show();
1131						} );
1132					} else {
1133						selected.html( title_filled ? value_to_show : '' );
1134					}
1135				}
1136				// Update filters total counters
1137				var filters_total = 0;
1138				fields_wrap.find('.sc_form_field_title_filled + .sc_form_field_wrap .sc_form_field_param').each( function() {
1139					var $self = jQuery( this ),
1140						field = $self.parents('.sc_form_field');
1141					// Exclude the field "Category" from totals and prevent 'Clear all' to be displayed on category selected
1142					if ( ! field.hasClass('sc_form_field_product_cat') ) {
1143						filters_total += field.hasClass('sc_form_field_text') || field.hasClass('sc_form_field_range') ? 1 : $self.val().split(',').length;
1144					}
1145				});
1146				fields_wrap.parents('form').find( '.trx_addons_woocommerce_search_button_filters_total' )
1147					.html( filters_total )
1148					.toggleClass( 'trx_addons_woocommerce_search_button_filters_total_empty', filters_total === 0 );
1149				// Show/hide 'Clear all'
1150				fields_wrap.toggleClass( 'trx_addons_woocommerce_search_form_fields_filled', filters_total > 0 );
1151			}
1152
1153			// Return comma-separated values from the field with multiple select allowed ('filter' style)
1154			function trx_addons_woocommerce_search_form_get_multiple_field_value( $wrap ) {
1155				var value = '';
1156				$wrap.find('.sc_form_field_item_checked').each( function() {
1157					value += ( value !== '' ? ',' : '' ) + jQuery(this).data('value');
1158				} );
1159				return value;
1160			}
1161
1162			// Get products page from specified url and replace products on the page
1163			function trx_addons_woocommerce_search_form_get_products_from_url( shop_url, fields_wrap ) {
1164				reload_is_busy = true;
1165				var need_open_fields_wrap = false,
1166					widget_number = 0;
1167				if ( fields_wrap && fields_wrap.length ) {
1168					if ( mask_fields_wrap_on_loading ) {
1169						if ( ! list_products_loading ) {
1170							fields_wrap.append( list_products_loading_html );
1171						}
1172						need_open_fields_wrap = false;	//fields_wrap.hasClass('trx_addons_woocommerce_search_form_fields_wrap_opened')
1173														//	&& ! fields_wrap.parents('.trx_addons_woocommerce_search').hasClass('trx_addons_woocommerce_search_apply');
1174						widget_number = fields_wrap.parents('.trx_addons_woocommerce_search_type_filter').data('number') || 1;
1175					}
1176					fields_wrap.removeClass('trx_addons_woocommerce_search_form_fields_changed');
1177				}
1178				// Reset a current page number
1179				jQuery( 'input[name="paged"]' ).val( 1 );
1180				jQuery( '.woocommerce-load-more' ).data( 'page', 1 ).parent().show();
1181				// Mark products wrapper with 'loading'
1182				if ( ! list_products_loading ) {
1183					jQuery( list_products_loading_selector )
1184						.addClass( 'trx_addons_woocommerce_search_loading' )
1185						.append( list_products_loading_html )
1186						.find('>' + list_products_loading_class)
1187							.addClass('trx_addons_hidden')
1188							.fadeIn(200);
1189				}
1190				list_products_loading++;
1191				// Make GET query to the shop
1192				jQuery.get( shop_url ).done( function( response ) {
1193					list_products_loading--;
1194					if ( list_products_loading ) {
1195						list_products_replace();
1196					} else {
1197						jQuery( list_products_loading_selector )
1198							.find('>' + list_products_loading_class)
1199							.fadeOut( 200, function() {
1200								list_products_replace( true );
1201							} );
1202					}
1203					function list_products_replace( remove_loading ) {
1204						var $response = jQuery( response ),
1205							new_products = $response.find( list_products_selector ).html(),
1206							new_inline_css = $response.find( inline_css_selector ).html(),
1207							new_total = $response.find('.trx_addons_woocommerce_search_button_show_total').eq(0).text() || 0;
1208						// If products found
1209						if ( new_products ) {
1210							// Replace document url in the browser's address bar
1211							trx_addons_document_set_location( shop_url );
1212							// Replace products with new items
1213							list_products_wrap.html( new_products );
1214							// Replace inline css with new styles
1215							if ( inline_css_wrap.length ) {
1216								// If inline css is not found via jQuery - try search with regular expression
1217								if ( ! new_inline_css ) {
1218									var mask = '<style[^>]*id="' + inline_css_selector.substr(1).replace( /\-/g, '\\-' ) + '"[^>]*>([^<]+)</style>';
1219									var re = new RegExp( mask );
1220									var matches = response.match( re );
1221									if ( matches && matches[1] ) {
1222										new_inline_css = matches[1];
1223									}
1224								}
1225								// If found inline css for list products - replace it
1226								if ( new_inline_css ) {
1227									var new_inline_block_start = new_inline_css.indexOf( inline_css_start ),
1228										new_inline_block_end = new_inline_css.indexOf( inline_css_end ),
1229										new_inline_block = new_inline_block_start >= 0
1230																? new_inline_css.substring( new_inline_block_start, new_inline_block_end + inline_css_end.length )
1231																: '';
1232									if ( new_inline_block ) {
1233										var old_inline_css = inline_css_wrap.html(),	
1234											old_inline_block_start = old_inline_css.indexOf( inline_css_start ),
1235											old_inline_block_end = old_inline_css.indexOf( inline_css_end );
1236										if ( old_inline_block_start >= 0 ) {
1237											old_inline_css = old_inline_css.substring( 0, old_inline_block_start )
1238															+ new_inline_block
1239															+ old_inline_css.substring( old_inline_block_end + inline_css_end.length );
1240											inline_css_wrap.html( old_inline_css );
1241										}
1242									}
1243								}
1244							}
1245							// Place back a 'loading' icon
1246							if ( ! remove_loading ) {
1247								jQuery( list_products_loading_selector )
1248									.toggleClass('trx_addons_woocommerce_search_loading', true)
1249									.append( list_products_loading_html );
1250							}
1251							// Replace total products counters
1252							jQuery('.trx_addons_woocommerce_search_button_show_total').text(new_total);
1253							// Got new elements
1254							jQuery( document ).trigger( 'action.got_ajax_response', {
1255								action: 'woocommerce_ajax_get_posts',
1256								result: response,
1257								products: list_products_wrap.hasClass('products')
1258												? list_products_wrap
1259												: list_products_wrap.find('ul.products')
1260							});
1261							// Init new elements
1262							$document.trigger( 'action.init_hidden_elements', [list_products_wrap] );
1263						} else {
1264							// If a result is a redirect to the single product - commit it
1265							if ( $response.find( single_product_selector ).length ) {
1266								var url = $response.filter( 'link[rel="canonical"]' ).attr( 'href' );
1267								if ( url ) {
1268									window.location = url;
1269									return;
1270								}
1271							}
1272							alert( TRX_ADDONS_STORAGE['msg_no_products_found'] );
1273						}
1274						// Remove 'loading' from products container
1275						if ( remove_loading ) {
1276							jQuery( list_products_loading_selector )
1277								.removeClass('trx_addons_woocommerce_search_loading')
1278								.find('>' + list_products_loading_class).remove();
1279						}
1280						// If fields_wrap not empty
1281						if ( widget_number ) {
1282							// Get new object for fields_wrap after products replaced (old fields wrap may be removed)
1283							var widget = jQuery('.trx_addons_woocommerce_search_type_filter[data-number="' + widget_number + '"]').eq(0),
1284								fields_wrap = widget.find('.trx_addons_woocommerce_search_form_fields_wrap').eq(0);
1285							if ( fields_wrap.length ) {
1286								// Remove 'loading'
1287								if ( remove_loading && mask_fields_wrap_on_loading ) {
1288									fields_wrap.find('>' + list_products_loading_class).remove();
1289								}
1290								// Reopen fields wrap
1291								if ( need_open_fields_wrap ) {
1292									widget.find('.trx_addons_woocommerce_search_form_fields_wrap').addClass('trx_addons_woocommerce_search_form_fields_wrap_opened trx_addons_woocommerce_search_form_fields_wrap_show');
1293									setTimeout( function() {
1294										widget.find('.trx_addons_woocommerce_search_form_fields_wrap_show').removeClass('trx_addons_woocommerce_search_form_fields_wrap_show');
1295									}, 500 );
1296								}
1297								// Reopen last active field
1298								if ( last_opened_filter ) {// && ! fields_wrap.parents('.trx_addons_woocommerce_search ').hasClass('trx_addons_woocommerce_search_apply') ) {
1299									var field = widget.find('input[name="'+last_opened_filter+'"]').parents('.sc_form_field');
1300									trx_addons_woocommerce_search_form_open_field( field, 'show' );
1301									if ( last_clicked_item ) {
1302										field.find('.sc_form_field_item[data-value="'+last_clicked_item+'"]').focus();
1303									}
1304								}
1305								// Clear 'param-changed' data parameter
1306								fields_wrap.data('param-changed', 0);
1307							}
1308						}
1309						reload_is_busy = false;
1310					}
1311				} );
1312			}
1313
1314		} );
1315
1316		// Close opened field on click outside the field wrap
1317		var trx_addons_woocommerce_search_form_click_outside = trx_addons_throttle(
1318								function() {
1319									var opened = jQuery('.trx_addons_woocommerce_search_form .sc_form_field_opened').eq(0);
1320									if ( opened.length ) {
1321										var fields_wrap = opened.parents('.trx_addons_woocommerce_search_form_fields_wrap');
1322										if ( fields_wrap.parents('.trx_addons_woocommerce_tools').length
1323											&& ! fields_wrap.hasClass('trx_addons_woocommerce_search_form_fields_wrap_opened')
1324										) {
1325											opened.find('.sc_form_field_title').trigger('click');
1326										} else {
1327											fields_wrap.find('.trx_addons_woocommerce_search_button_show').trigger('click');
1328										}
1329									}
1330								},
1331								trx_addons_apply_filters( 'trx_addons_filter_woocommerce_search_click_outside_timeout', 10 ),
1332								true
1333							);
1334
1335		$document.on( 'click', function(e) {
1336			var $self = jQuery( e.target );
1337			if ( ! $self.hasClass('sc_form_field_wrap')
1338					&& $self.parents('.sc_form_field_wrap').length === 0
1339					&& $self.parents('.trx_addons_woocommerce_search_form_fields_wrap').length === 0
1340					&& ! $self.hasClass(list_products_loading_class)
1341			) {
1342				trx_addons_woocommerce_search_form_click_outside();
1343			}
1344			// Close opened fields wrap
1345			/*
1346			if ( ! $self.hasClass('trx_addons_woocommerce_search_form_fields_wrap_opened')
1347					&& $self.parents('.trx_addons_woocommerce_search_form_fields_wrap_opened').length === 0
1348			) {
1349				jQuery('.trx_addons_woocommerce_search_form_fields_wrap_opened').removeClass('trx_addons_woocommerce_search_form_fields_wrap_opened');
1350			}
1351			*/
1352		} );
1353		
1354		// Collect all form params to array (any style)
1355		function trx_addons_woocommerce_search_form_get_params( form, selector ) {
1356			var params = {}, not_empty = false;
1357			// Collect all filters
1358			form.find( selector ? selector : 'select,input' ).each( function() {
1359				var $self = jQuery(this),
1360					val   = $self.val(),
1361					name  = $self.attr('name'),
1362					type  = '';
1363				if ( name && ( ( val !== '' && ( '' + val ) !== '0' ) || name == 'product_cat' ) ) {
1364					if ( name == 'price' ) {
1365						var values  = val.split(','),
1366							$slider = $self.next('.trx_addons_range_slider '),
1367							min     = $slider.data('min'),
1368							max     = $slider.data('max');
1369						if ( values.length == 2 && $slider.length == 1 ) {
1370							if ( Number( values[0] ) > min ) {
1371								params['min_price'] = values[0];
1372							}
1373							if ( Number( values[1] ) < max ) {
1374								params['max_price'] = values[1];
1375							}
1376						}
1377						name = '';
1378					} else if ( name.substring(0, 3) == 'pa_' ) {
1379						type = 'query_type_' + name.substring(3);
1380						name = 'filter_' + name.substring(3);
1381					} else if ( name == 'rating' ) {
1382						name = name + '_filter';
1383					}
1384					if ( name !== '' ) {
1385						params[name] = val;
1386					}
1387					if ( type !== '' && val.indexOf(',') > 0 ) {
1388						params[type] = 'or';
1389					}
1390					not_empty = true;
1391				}
1392			} );
1393			// Add sort order
1394			if ( not_empty || selector ) {
1395				params = trx_addons_woocommerce_search_form_add_orderby_to_query_params( params );
1396			}
1397			return not_empty || typeof params['orderby'] != 'undefined' ? params : false;
1398		}
1399
1400		// Add sort order to the query params
1401		function trx_addons_woocommerce_search_form_add_orderby_to_query_params( params ) {
1402			var orderby = jQuery('.woocommerce-ordering .orderby').val();
1403			if ( orderby && orderby != 'menu_order' ) {
1404				params['orderby'] = orderby;
1405			}
1406			return params;
1407		}
1408
1409	});
1410
1411})();

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.