PageSourceSearch

https://real4wd.com/wp-content/plugins/woo-vehicle-parts-finder/assets/js/scripts.js?ver=6.9.9

js real4wd.com collected 2026-09-30 21:14:42 UTC 14,577 bytes, 394 lines download raw bytes

1jQuery( document ).ready(function($) {
2	var $term_id;
3
4	// Reset Form on Page Load
5	$('.widget-woo-vpf-filter form').each(function() {
6		$(this)[0].reset();
7	});
8	
9	// Disable Dependent Fields
10	if( woo_vpf_params.disable_dependent_fields == 'yes' ) {
11		
12		$('.widget-woo-vpf-filter select').attr( 'disabled', 'disabled' );
13		$('.widget-woo-vpf-filter select[name="make"]').removeAttr( 'disabled' );
14		$('.widget-woo-vpf-filter select[name="category"]').removeAttr( 'disabled' );
15		
16		if( $('.widget-woo-vpf-filter select[name="make"]').val() > 0 ) {
17			$('.widget-woo-vpf-filter select[name="model"]').removeAttr( 'disabled' );
18		}
19		
20		if( $('.widget-woo-vpf-filter select[name="model"]').val() > 0 ) {
21			$('.widget-woo-vpf-filter select[name="year_id"]').removeAttr( 'disabled' );
22		}
23		
24		if( $('.widget-woo-vpf-filter select[name="year_id"]').val() > 0 ) {
25			$('.widget-woo-vpf-filter select[name="engine"]').removeAttr( 'disabled' );
26		}
27		
28		$( document.body ).on('woo_vpf_models_updated', function(event, elem_container, elem_select) {
29			if( elem_container.find('select[name="make"]').val() == '' ) {
30				elem_container.find('select[name="model"]').attr( 'disabled', 'disabled' );
31			} else {
32				elem_container.find('select[name="model"]').removeAttr( 'disabled' );
33			}
34
35			elem_container.find('select[name="year_id"]').attr( 'disabled', 'disabled' );
36			elem_container.find('select[name="engine"]').attr( 'disabled', 'disabled' );
37		});
38		
39		$( document.body ).on('woo_vpf_years_updated', function(event, elem_container, elem_select) {
40			if( elem_container.find('select[name="model"]').val() == '' ) {
41				elem_container.find('select[name="year_id"]').attr( 'disabled', 'disabled' );
42			} else {
43				elem_container.find('select[name="year_id"]').removeAttr( 'disabled' );
44			}
45			
46			elem_container.find('select[name="engine"]').attr( 'disabled', 'disabled' );
47		});
48		
49		$( document.body ).on('woo_vpf_engines_updated', function(event, elem_container, elem_select) {
50			if( elem_container.find('select[name="year_id"]').val() == '' ) {
51				elem_container.find('select[name="engine"]').attr( 'disabled', 'disabled' );
52			} else {
53				elem_container.find('select[name="engine"]').removeAttr( 'disabled' );
54			}
55		});
56	}
57	
58	// Chosen
59	if( woo_vpf_params.is_chosen == 'yes' ) {
60		$('.widget-woo-vpf-filter select').chosen();
61		
62		$( document.body ).on('woo_vpf_models_updated', function(event, elem_container, elem_select) {
63			elem_container.find('select[name="model"]').trigger('chosen:updated');
64			elem_container.find('select[name="year_id"]').trigger('chosen:updated');
65			elem_container.find('select[name="engine"]').trigger('chosen:updated');
66		});
67		
68		$( document.body ).on('woo_vpf_years_updated', function(event, elem_container, elem_select) {
69			elem_container.find('select[name="year_id"]').trigger('chosen:updated');
70			elem_container.find('select[name="engine"]').trigger('chosen:updated');
71		});
72		
73		$( document.body ).on('woo_vpf_engines_updated', function(event, elem_container, elem_select) {
74			elem_container.find('select[name="engine"]').trigger('chosen:updated');
75		});
76	}
77	
78	// Dynamic DropDowns
79	if( $('.widget-woo-vpf-filter select[name="model"]').length ) {
80		$( document.body ).on('change', '.widget-woo-vpf-filter select[name="make"]', function() {
81			var $elem = $(this).closest('form');
82			$elem.addClass('woo-vpf-processing');
83		
84			$term_id = $(this).val();
85			$.post( woo_vpf_params.ajax_url, {'parent':$term_id, 'panel':'front', 'action':'woo_vpf_get_terms'}, function( response ) {
86				$elem.removeClass('woo-vpf-processing');
87				
88				if( $elem.find('select[name="model"]').length ) {
89					$elem.find('select[name="model"] option:not(:first)').remove();
90					$elem.find('select[name="model"]').append( response );
91				}
92				
93				if( $elem.find('select[name="year_id"]').length ) {
94					$elem.find('select[name="year_id"] option:not(:first)').remove();
95				}
96			
97				if( $elem.find('select[name="engine"]').length ) {
98					$elem.find('select[name="engine"] option:not(:first)').remove();
99				}
100			
101				$( document.body ).trigger( 'woo_vpf_models_updated', [ $elem, $elem.find('select[name="model"]') ] );
102			});
103		});
104	}
105	
106	if( $('.widget-woo-vpf-filter select[name="year_id"]').length ) {
107		$( document.body ).on('change', '.widget-woo-vpf-filter select[name="model"]', function() {
108			var $elem = $(this).closest('form');
109			$elem.addClass('woo-vpf-processing');
110		
111			$term_id = $(this).val();
112			$.post( woo_vpf_params.ajax_url, {'parent':$term_id, 'panel':'front', 'action':'woo_vpf_get_terms'}, function( response ) {
113				$elem.removeClass('woo-vpf-processing');
114				
115				if( $elem.find('select[name="year_id"]').length ) {
116					$elem.find('select[name="year_id"] option:not(:first)').remove();
117					$elem.find('select[name="year_id"]').append( response );
118				}
119			
120				if( $elem.find('select[name="engine"]').length ) {
121					$elem.find('select[name="engine"] option:not(:first)').remove();
122				}
123			
124				$( document.body ).trigger( 'woo_vpf_years_updated', [ $elem, $elem.find('select[name="year_id"]') ] );
125			});
126		});
127	}
128	
129	if( $('.widget-woo-vpf-filter select[name="engine"]').length ) {
130		$( document.body ).on('change', '.widget-woo-vpf-filter select[name="year_id"]', function() {
131			var $elem = $(this).closest('form');
132			$elem.addClass('woo-vpf-processing');
133			
134			$term_id = $(this).val();
135			$.post( woo_vpf_params.ajax_url, {'parent':$term_id, 'panel':'front', 'action':'woo_vpf_get_terms'}, function( response ) {
136				$elem.removeClass('woo-vpf-processing');
137				
138				if( $elem.find('select[name="engine"]').length ) {
139					$elem.find('select[name="engine"] option:not(:first)').remove();
140					$elem.find('select[name="engine"]').append( response );
141				}
142				
143				$( document.body ).trigger( 'woo_vpf_engines_updated', [ $elem, $elem.find('select[name="engine"]') ] );
144			});
145		});
146	}
147	
148	// Validation Rules
149	if( woo_vpf_params.activate_validation == 'yes' ) {
150		
151		$( document.body ).on('submit', '.widget-woo-vpf-filter form', function() {
152			var $elem = $(this);
153			
154			var $error_text = ''; var $error_elem = '';
155			
156			// Validation: Make
157			if( $error_elem == '' ) {
158				if( woo_vpf_params.validate_make == 'yes' && $elem.find('select[name="make"]').length ) {
159					if( $elem.find('select[name="make"]').val() == '' ) {
160						$error_elem = $elem.find('select[name="make"]');
161						$error_text = woo_vpf_params.validate_make_text;
162					}
163				}
164			}
165			
166			// Validation: Model
167			if( $error_elem == '' ) {
168				if( woo_vpf_params.validate_model == 'yes' && $elem.find('select[name="model"]').length ) {
169					if( $elem.find('select[name="model"]').val() == '' ) {
170						$error_elem = $elem.find('select[name="model"]');
171						$error_text = woo_vpf_params.validate_model_text;
172					}
173				}
174			}
175			
176			// Validation: Year
177			if( $error_elem == '' ) {
178				if( woo_vpf_params.validate_year == 'yes' && $elem.find('select[name="year_id"]').length ) {
179					if( $elem.find('select[name="year_id"]').val() == '' ) {
180						$error_elem = $elem.find('select[name="year_id"]');
181						$error_text = woo_vpf_params.validate_year_text;
182					}
183				}
184			}
185			
186			// Validation: Engine
187			if( $error_elem == '' ) {
188				if( woo_vpf_params.validate_engine == 'yes' && $elem.find('select[name="engine"]').length ) {
189					if( $elem.find('select[name="engine"]').val() == '' ) {
190						$error_elem = $elem.find('select[name="engine"]');
191						$error_text = woo_vpf_params.validate_engine_text;
192					}
193				}
194			}
195			
196			// Validation: Category
197			if( $error_elem == '' ) {
198				if( woo_vpf_params.validate_category == 'yes' && $elem.find('select[name="category"]').length ) {
199					if( $elem.find('select[name="category"]').val() == '' ) {
200						$error_elem = $elem.find('select[name="category"]');
201						$error_text = woo_vpf_params.validate_category_text;
202					}
203				}
204			}
205			
206			// Validation: Keyword
207			if( $error_elem == '' ) {
208				if( woo_vpf_params.validate_keyword == 'yes' && $elem.find('input[name="s"]').length ) {
209					if( $elem.find('input[name="s"]').val() == '' ) {
210						$error_elem = $elem.find('input[name="s"]');
211						$error_text = woo_vpf_params.validate_keyword_text;
212					}
213				}
214			}
215			
216			// Validation: Alerts / Styles
217			$elem.find('.woo-vpf-error').removeClass('woo-vpf-error');
218			if( $error_elem != '' ) {
219			
220				if( woo_vpf_params.validation_alert == 'yes' ) {
221					if( $error_text != '' ) {
222						alert( $error_text );
223					}
224				}
225				
226				if( woo_vpf_params.validation_style == 'yes' ) {
227					$error_elem.closest('.woo-vpf-field').addClass('woo-vpf-error');
228				}
229				
230				return false;
231			} else {
232				return true;
233			}
234			
235		});
236		
237	}
238	
239	
240	
241	/* My Vehicles */
242	
243	// Radio Button Link
244	$(document).on('click', '.woo-vpf-mv-container .mv-item-radio', function(event) {
245		$(this).closest('.mv-item').find('.mv-lnk-browse').get(0).click();
246	});
247	
248	// Expand/Collapse Widget
249	$( document.body ).on('click', '.woo-vpf-mv-container.mv-has-expandable-wrapper > .mv-header, .woo-vpf-mv-container.mv-has-flyout-wrapper > .mv-header', function(event) {
250		var $elem = $(this).closest('.woo-vpf-mv-container');
251		if( $elem.hasClass('mv-expanded') ) {
252			$elem.addClass('mv-collapse').removeClass('mv-expanded').find('.mv-inner').slideUp();
253		} else {
254			$elem.addClass('mv-expanded').removeClass('mv-collapse').find('.mv-inner').slideDown();
255		}
256	});
257	
258	// Close Current Widget when Opens Another Widget
259	$(document).click(function(e) {
260		$('.woo-vpf-mv-container.mv-has-flyout-wrapper').each(function() {
261			var $elem = $(this).closest('.woo-vpf-mv-container');
262			
263			if ( ! $elem.is(e.target) && $elem.has(e.target).length === 0 ) {
264				if( $elem.hasClass('mv-expanded') ) {
265					$elem.addClass('mv-collapse').removeClass('mv-expanded').find('.mv-inner').slideUp();
266				}
267			}
268		});
269	});
270	
271	// Reset Search
272	$('.woo-vpf-reset-search').click(function(event) {
273		event.preventDefault();
274		
275		var $href = $(this).attr('href');		
276		var $elem = $(this).closest('form');
277		$elem.addClass('woo-vpf-processing');
278			
279		$.post( woo_vpf_params.ajax_url, {'action':'woo_vpf_reset_search'}, function( response ) {
280			if( $href != '#' ) {
281				window.location.href = $href;
282			} else {
283				window.location.href = window.location.href;
284			}
285		});
286	});
287	
288	// Save User Search from History to Permanent Save
289	$(document).on('click', '.woo-vpf-mv-container .mv-lnk-save', function(event) {
290		event.preventDefault();
291		
292		if( $(this).hasClass('mv-lnk-disable') ) {
293			return;
294		}
295		
296		var $elem = $(this).closest('.woo-vpf-mv-container');
297		$elem.find('.woo-vpf-loader').show();
298		
299		var $search_id = $(this).attr('data-search-id');
300		var $search_type = $(this).attr('data-search-type');
301		$.post( woo_vpf_params.ajax_url, {'search_id':$search_id, 'search_type':$search_type, 'action':'woo_vpf_save_search'}, function( response ) {
302			woo_vpf_set_my_vehicles_html(response);			
303			$elem.find('.woo-vpf-loader').hide();
304		});
305	});
306	
307	// Delete User Search
308	$(document).on('click', '.woo-vpf-mv-container .mv-lnk-delete', function(event) {
309		event.preventDefault();
310		
311		if( $(this).hasClass('mv-lnk-disable') ) {
312			return;
313		}
314		
315		var $elem = $(this).closest('.woo-vpf-mv-container');
316		$elem.find('.woo-vpf-loader').show();
317		
318		var $search_id = $(this).attr('data-search-id');
319		var $search_type = $(this).attr('data-search-type');
320		$.post( woo_vpf_params.ajax_url, {'search_id':$search_id, 'search_type':$search_type, 'action':'woo_vpf_delete_search'}, function( response ) {
321			woo_vpf_set_my_vehicles_html(response);			
322			$elem.find('.woo-vpf-loader').hide();
323		});
324	});
325	
326	// Clear History
327	$(document).on('click', '.woo-vpf-mv-container .mv-clear-history', function(event) {
328		event.preventDefault();
329		
330		var $elem = $(this).closest('.woo-vpf-mv-container');
331		$elem.find('.woo-vpf-loader').show();
332		
333		var $search_type = $(this).attr('data-search-type');
334		$.post( woo_vpf_params.ajax_url, {'search_type':$search_type, 'action':'woo_vpf_clear_history'}, function( response ) {
335			woo_vpf_set_my_vehicles_html(response);
336			$elem.find('.woo-vpf-loader').hide();
337		});
338	});
339	
340	// Modal
341	if( $('.woo-vpf-modal').length ) {
342		// Add a Vehicle Popup
343		$(document).on('click', '.woo-vpf-mv-container .mv-add-vehicle', function(event) {
344			event.preventDefault();
345			
346			var $title = $(this).attr('data-title');
347			
348			$.colorbox({
349				inline:true,
350				width:'500',
351				maxWidth:'95%',
352				maxHeight:'95%',
353				href:'#woo-vpf-modal-filter',
354				title:$title,
355				className:'woo-vpf-popup',
356				onComplete:function(){
357					$('#cboxWrapper').find('select, input[name="s"]').val('');
358				
359					//$('#cboxWrapper').find('select[name="make"]').trigger('change');
360					$('#cboxWrapper').find('select[name="model"], select[name="year_id"], select[name="engine"]').find('option:not(:first)').remove();
361					
362					if( woo_vpf_params.disable_dependent_fields == 'yes' ) {
363						$('#cboxWrapper').find('select[name="model"], select[name="year_id"], select[name="engine"]').attr( 'disabled', 'disabled' );
364					}
365					
366					$('#cboxWrapper .widget-woo-vpf-filter select').trigger("chosen:updated");
367				}
368			});
369		});
370	}
371	
372	// Common Functions
373	function woo_vpf_set_my_vehicles_html(response) {
374		if( response != '' ) {
375			$response_container = $(response).filter('.woo-vpf-mv-container');
376			
377			if( $('.woo-vpf-mv-container > .mv-header').length ) {
378				$('.woo-vpf-mv-container > .mv-header').html( $response_container.find('.mv-header').html() );
379			}
380			
381			if( $('.woo-vpf-mv-container .mv-section-vehicles-saved').length ) {
382				$('.woo-vpf-mv-container .mv-section-vehicles-saved').html( $response_container.find('.mv-section-vehicles-saved').html() );
383			}
384			
385			if( $('.woo-vpf-mv-container .mv-section-vehicles-history .mv-items').length ) {
386				$('.woo-vpf-mv-container .mv-section-vehicles-history .mv-items').html( $response_container.find('.mv-section-vehicles-history .mv-items').html() );
387			}
388			
389			if( $('.woo-vpf-mv-container .mv-section-vehicles-history .mv-actions .mv-clear-history').length ) {
390				$('.woo-vpf-mv-container .mv-section-vehicles-history .mv-actions .mv-clear-history').html( $response_container.find('.mv-section-vehicles-history .mv-actions .mv-clear-history').html() );
391			}
392		}
393	}
394});

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.