PageSourceSearch

https://theotravis.com/media/j2store/js/filter.js?33f28c

js theotravis.com collected 2026-09-25 01:04:40 UTC 15,376 bytes, 428 lines download raw bytes

1jQuery(function($) {
2	var filters = {
3		/**
4		 * Method to return absolute path
5		 */
6		getAbsolutePath : function(url ,donotSet,options) {
7			var loc = window.location;
8			var pathName = loc.pathname.substring(0,loc.pathname.lastIndexOf('/') + 1);
9			//let us check the url is non-seo friendly ?
10			if(loc.href.indexOf("view") > -1 && loc.href.indexOf("option") > -1 && loc.href.indexOf('Itemid') > -1){
11
12				// first remove the slash in orgin
13				var origin_slash = loc.origin.substring(loc.origin.length-1,loc.origin.length );
14				var origin = loc.origin;
15				if(origin_slash == '/'){
16					origin = loc.origin.substring(1,loc.origin.length-1 );
17				}
18
19				// add the slash in pathname
20				var pathName_slash = pathName.substring(0,1);
21				if(pathName_slash != '/'){
22					pathName = '/'+pathName;
23				}
24				var absolute_url = origin+pathName;
25				url_link = '';
26				if( $(options.form_id).length > 0  &&  $(options.form_id).attr('data-link') ){
27					if($(options.form_id).data('link')){
28						var form_id_slash = $(options.form_id).data('link').substring(0,1);
29						//check first char is / if yes remove it
30						if(form_id_slash == '/'){
31							url_link = $(options.form_id).data('link').substring(1,$(options.form_id).data('link').length );
32						}
33
34					}
35				}else if($(options.topFilter_id).length > 0 && $(options.topFilter_id).attr('data-link') ){
36					var topFilter_id_slash = $(options.topFilter_id).data('link').substring(0,1);
37					//check first char is / if yes remove it
38					if(topFilter_id_slash == '/'){
39						url_link = $(options.topFilter_id).data('link').substring(1,$(options.topFilter_id).data('link').length );
40					}
41
42				}else if($('.j2store-product-list').length > 0 && $('.j2store-product-list').attr('data-link') ){
43					var product_slash = $('.j2store-product-list').data('link').substring(0,1);
44					//check first char is / if yes remove it
45					if(product_slash == '/'){
46						url_link = $('.j2store-product-list').data('link').substring(1,$('.j2store-product-list').data('link').length );
47					}
48
49					//here we have to do another safety measure
50				}else if(j2store_product_base_link !==''){
51					var productbase_slash = j2store_product_base_link.substring(0,1);
52					//check first char is / if yes remove it
53					if(productbase_slash == '/'){
54						url_link = j2store_product_base_link.substring(1,j2store_product_base_link.length );
55					}
56
57				}
58				absolute_url =absolute_url + url_link;
59//				url = url.indexOf('&',0)  === -1 ? "&"+url : url;
60				var absolute_url_slash = absolute_url.substring(absolute_url.length-1,absolute_url.length );
61				if(absolute_url_slash == '/'){
62					url_slash = url.substring(0,1);
63					if(url_slash == '/'){
64						url = url.substring(1,url.length);
65					}
66				}
67				var item_id = loc.href.substring(loc.href.indexOf('Itemid'));
68
69				var option_url = '&option=com_j2store&view=products';
70				if(item_id){
71					option_url = option_url+"&"+item_id;
72				}
73				var index_file = loc.href.indexOf("index.php");
74				if(index_file){
75					absolute_url = absolute_url+"index.php";
76				}
77				url_check = url.indexOf("?") === -1 ? "?" : "&";
78				if(url_check == '?'){
79					url_amp = url.substring(0,1);
80					if(url_amp == '&'){
81						url = url.substring(1,url.length);
82					}
83
84				}
85				url = url+option_url;
86				url = url_check + url ;
87				document.location.href  = absolute_url+url;
88
89			}else{
90				var absolute_url = loc.href.substring(0,loc.href.length	- ((loc.pathname + loc.search + loc.hash).length - pathName.length));	// remove the first occurance & sign from the url
91
92				url = url.substr(1);
93				var site_url = absolute_url.indexOf("?") === -1 ? "?" : "&";
94				if(donotSet == true){
95					return site_url + url;
96				}else{
97
98					document.location.href = site_url + url;
99				}
100			}
101
102		},
103
104        getQueryParam : function(param) {
105            var queryParams = window.location.search.substr(1).split('&').reduce(function (q, query) {
106                var chunks = query.split('=');
107                var key = chunks[0];
108                var value = chunks[1];
109                return (q[key] = value, q);
110            }, {});
111            var keys = Object.keys(queryParams);
112            for (var i = 0; i < keys.length; i++) {
113                if(param == keys[i].substr(0,param.length)){
114                    return true;
115                }
116            }
117            return false;
118        },
119
120		removeParameter : function(url, parameter, onlyselected) {
121			var urlparts = url.split('?');
122
123			if (urlparts.length >= 2) {
124				var urlBase = urlparts.shift(); // get first part, and remove
125												// from array
126				var queryString = urlparts.join("?"); // join it back up
127				var prefix = parameter + '=';
128				var pars = queryString.split(/[&;]/g);
129				for ( var i = pars.length; i-- > 0;)
130					// reverse iteration as may be destructive
131					if (pars[i].lastIndexOf(prefix, 0) !== -1) // idiom for
132																// string.startsWith
133						pars.splice(i, 1);
134
135				url = urlBase + '?' + pars.join('&');
136			}
137			return url;
138		}
139
140	}
141
142	$.J2StoreFilters = function(options) {
143		this.init(options);
144	}
145
146	$.J2StoreFilters.prototype = {
147
148		init : function(options) {
149
150			/**
151			 * let us assing default value for the var .
152			 * incase  the option is empty
153			 */
154			if(options.form_id ==''){
155				options.form_id='#productsideFilters';
156			}
157
158			if(options.topFilter_id ==''){
159				options.topFilter_id='#productFilters';
160			}
161
162			/** let us first check the element exists **/
163			if((options.form_id).length != 0){
164
165			/**  now  call  trigger the sideFilters  Brands , Vendors , Product Filters **/
166				this.sideFilter(options);
167
168			/**  now  call trigger the Category filters **/
169				this.categoryFilter(options);
170
171			/** now also call the price slider **/
172				//this.priceSlider(options);
173
174			/** Will remove the href params query of manufacturer_ids[] * */
175			$(options.form_id).find('.manufacturer-filters a').on('click',function() {
176				document.getElementById('j2store-product-loading').style.display='block';
177				if (filters.getQueryParam("manufacturer_ids")) {
178					location.href = filters.removeParameter(window.location.href,'manufacturer_ids[]');
179				} else {
180					$(options.form_id).find(".j2store-brand-checkboxes").each(function() {
181							this.checked = false;
182					});
183				}
184				document.getElementById('j2store-product-loading').style.display='none';
185			});
186
187			/** Will remove the href params query of vendor_ids[] * */
188			/** Event fire when Clear Link cliked for Vendors  **/
189			$(options.form_id).find('.j2store-product-vendor-filters a').on('click',function() {
190						document.getElementById('j2store-product-loading').style.display='block';
191						if (filters.getQueryParam("vendor_ids")) {
192							location.href = filters.removeParameter(
193									window.location.href, 'vendor_ids[]');
194						}
195						document.getElementById('j2store-product-loading').style.display='none';
196					});
197
198			/** Event fire when Clear Link cliked form Product filters  **/
199			$(options.form_id).find('.productfilters-list a').on('click',function() {
200					document.getElementById('j2store-product-loading').style.display='block';
201						if (filters.getQueryParam("productfilter_ids")) {
202							jQuery("." + $(this).data('class')).each(
203									function() {
204										this.checked = false;
205							});
206
207					 var url = '';
208					 $(options.form_id).find('input[type="checkbox"]').each(function() {
209									if (this.checked) {
210										url += '&' + this.name+ '=' + this.value;}
211								});
212
213					 	if($(options.form_id).find("li.active").length > 0){
214					 		var active_li = $(options.form_id).find("li.active").find('a');
215					 		url += '&' + $(active_li).data('key') + '='+ $(active_li).data('value');
216					 	}
217
218					 	if( $(options.form_id+  " #j2store-slider-range").length !=0){
219					 		//let us append price filters
220					 		url +='&pricefrom='+$(options.form_id).find("#min_price_input").attr('value');
221					 		url +='&priceto='+$(options.form_id).find("#max_price_input").attr('value');
222					 	}
223
224						 filters.getAbsolutePath(url ,false,options);
225						}
226				document.getElementById('j2store-product-loading').style.display='none';
227					});
228			}
229
230			/** call the event fire for TopFilters **/
231			this.topFilter(options);
232
233		},
234		categoryFilter : function(options){
235			$(options.form_id).find('.j2product-categories').on('click',function(e) {
236				document.getElementById('j2store-product-loading').style.display='block';
237				var url = '';
238				// we can make use this line to clear the filter
239				if($('.j2product-categories > a').data('key')) {
240					 url += '&' + $(this).find('a').data('key')+ '='	+ $(this).find('a').data('value');
241				}
242
243				if($(options.form_id).find("li.active").length != 0){
244					$(options.form_id).find('input[type="checkbox"]:checked').each(function(index, el) {
245						url += '&'+ $(el).attr('name')+ '='+ $(el).attr('value');
246					});
247				}
248
249				if($(options.topFilter_id).length != 0){
250					if($(options.topFilter_id).find('input[name=search]').length != 0 ){
251						var search = $(options.topFilter_id).find('input[name=search]');
252						if(search !=''){
253							url += '&' + $(search).attr('name') + '='+ $(search).attr('value');
254					 	}
255					}
256
257					 if($(options.topFilter_id).find('select[name=sortby]').length !=0){
258						 var sortby = $(options.topFilter_id).find('select[name=sortby] option:selected');
259						 if(sortby){
260							 url += '&' + $(options.topFilter_id).find('select[name=sortby]').attr('name') + '='+ sortby.val();
261						 }
262					 }
263				}
264
265				if( $(options.form_id+  " #j2store-slider-range").length !=0){
266					//let us append price filters
267					url +='&pricefrom='+$(options.form_id).find("#min_price_input").attr('value');
268					url +='&priceto='+$(options.form_id).find("#max_price_input").attr('value');
269				}
270
271				filters.getAbsolutePath(url,false,options);
272			});
273		},
274
275		sideFilter : function(options){
276			$(options.form_id).find('input[type="checkbox"]').on('change',function(el) {
277				document.getElementById('j2store-product-loading').style.display='block';
278						var url = '';
279						if((options.form_id).length != 0){
280							$(options.form_id).find('input[type="checkbox"]').each(function() {
281								if (this.checked) {
282									url += '&' + this.name + '='+ this.value;
283								}
284							});
285
286
287							//let us check category related div exists
288							if($(options.form_id).find("li.active").length != 0){
289								var active_li = $(options.form_id).find("li.active").find('a');
290								url += '&' + $(active_li).data('key') + '='+ $(active_li).data('value');
291							}
292
293
294							//check price slider exists
295							if($(options.form_id).find("#j2store-slider-range").length !=0){
296								//let us append price filters
297								url +='&pricefrom='+$(options.form_id).find("#min_price_input").attr('value');
298								url +='&priceto='+$(options.form_id).find("#max_price_input").attr('value');
299							}
300						}
301
302						if($(options.topFilter_id).length != 0){
303							// step 4 : let us check filter search exists
304							if($(options.topFilter_id).find('input[name=search]').length != 0 ){
305								 var search = $(options.topFilter_id).find('input[name=search]');
306								 	if(search !=''){
307								 		url += '&' + $(search).attr('name') + '='+ $(search).attr('value');
308
309								 	}
310							}
311
312							if($(options.topFilter_id).find('select[name=sortby]').length !=0){
313							 	var sortby = $(options.topFilter_id).find('select[name=sortby] option:selected');
314								 if(sortby){
315									 url += '&' + $(options.topFilter_id).find('select[name=sortby]').attr('name') + '='+ sortby.val();
316								 }
317							}
318						}
319
320
321						filters.getAbsolutePath(url ,false ,options);
322
323					});
324		},
325
326		topFilter : function(options){
327			if($(options.topFilter_id).length != 0){
328				var url ='';
329				//prevent the form submit incase search filter exists
330				$(options.topFilter_id).submit(function(e){
331					e.preventDefault();
332					//let us check category related div exists
333					if($(options.form_id).find("li.active").length > 0){
334						var active_li = $(options.form_id).find("li.active").find('a');
335						url += '&' + $(active_li).data('key') + '='+ $(active_li).data('value');
336					}
337					if($(options.form_id).find("li.active").length != 0){
338						 $(options.form_id).find('input[type="checkbox"]:checked').each(function(index, el) {
339										url += '&'+ $(el).attr('name')+ '='+ $(el).attr('value');
340						 });
341					}
342
343					 if($(options.topFilter_id).find('input[name=search]').length != 0 ){
344						 var search = $(options.topFilter_id).find('input[name=search]');
345						 if(search !=''){
346							 url += '&' + $(search).attr('name') + '='+ $(search).val();
347						 }
348					 }
349
350					 if($(options.topFilter_id).find('select[name=sortby]').length !=0){
351						 var sortby = $(options.topFilter_id).find('select[name=sortby] option:selected');
352						 url += '&' + $(options.topFilter_id).find('select[name=sortby]').attr('name') + '='+ sortby.val();
353					 }
354
355					//check price slider exists
356					 if( $(options.form_id).find("#j2store-slider-range").length !=0){
357							//let us append price filters
358							url +='&pricefrom='+$(options.form_id).find("#min_price_input").val();
359							url +='&priceto='+$(options.form_id).find("#max_price_input").val();
360					}
361
362					 filters.getAbsolutePath(url ,false ,options);
363				});
364
365			}
366		},
367		priceSlider:function(options){
368			$(options.form_id).find("#j2store-slider-range").slider({
369
370					slide: function( event, ui ) {
371						document.getElementById('j2store-product-loading').style.display='block';
372						var url = '';
373						if((options.form_id).length != 0){
374							if($(options.form_id).find("li.active").length > 0){
375								var active_li = $(options.form_id).find("li.active").find('a');
376									url += '&' + $(active_li).data('key') + '='+ $(active_li).data('value');
377							}
378
379							// step 2 :  let us check any filters like brand ,vendor , pfilters exists
380							if($(options.form_id).find('input[type="checkbox"]:checked').length !=0){
381								$(options.form_id).find('input[type="checkbox"]').each(function() {
382										if (this.checked) {
383											url += '&' + this.name + '='+ this.value;
384										}
385								});
386							}
387
388						}
389
390
391						if($(options.topFilter_id).length != 0){
392							var search = $(options.topFilter_id).find('input[name=search]').length;
393						 	if(search > 0 ){
394						 		url += '&' + $(options.topFilter_id).find('input[name=search]').attr('name') + '='+ $(options.topFilter_id).find('input[name=search]').attr('value');
395
396						 	}
397						 	var sortby = $(options.topFilter_id).find('select[name=sortby] option:selected');
398							 if( $(options.topFilter_id).find('select[name=sortby]').length > 0){
399								 url += '&' + $(options.topFilter_id).find('select[name=sortby]').attr('name') + '='+ sortby.val();
400							 }
401						}
402
403						if( $(options.form_id).find("#j2store-slider-range").length !=0){
404							//let us append  price filters
405							url +='&pricefrom='+ui.values[0];
406							url +='&priceto='+ui.values[1];
407
408							$(options.form_id).find( "#min_price" ).html(ui.values[ 0 ]);
409							$(options.form_id).find( "#max_price" ).html(  ui.values[ 1 ] );
410						}
411
412						filters.getAbsolutePath(url ,false ,options);
413
414					}
415			});
416		},
417	};
418
419/*	var base_url;
420	$(document).ready(function() {
421		base_url = window.location.href;
422		console.log(base_url);
423	  });*/
424
425	// call the class
426	var myClassObj = new $.J2StoreFilters({'form_id':'#productsideFilters' ,'topFilter_id':'#productFilters'});
427
428});

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.