PageSourceSearch

https://www.healthporter.co.nz/catalog/view/theme/journal3/js/filter.js

js healthporter.co.nz collected 2026-09-29 09:02:15 UTC 6,805 bytes, 259 lines download raw bytes

1function journal_filter_url() {
2	var f = {};
3
4	$('input[data-filter-trigger]:checked, select[data-filter-trigger]').each(function () {
5		var $this = $(this);
6
7		var name = 'f' + $this.attr('name');
8		var value = $this.val().trim();
9
10		f[name] = f[name] || [];
11		f[name].push(value);
12	});
13
14	if ($('.filter-price').length) {
15		var min = $('.filter-price-min').data('min');
16		var max = $('.filter-price-max').data('max');
17		var from = parseInt($('.filter-price-min').val(), 10);
18		var to = parseInt($('.filter-price-max').val(), 10);
19
20		if (((from !== '') && (from !== min)) || ((to !== '') && (to !== max))) {
21			f['fmin'] = [from];
22			f['fmax'] = [to];
23		}
24	}
25
26
27	var sort = $('#input-sort').data('filter-sort');
28	var order = $('#input-sort').data('filter-order');
29
30	if (sort && order) {
31		f['sort'] = [sort];
32		f['order'] = [order];
33	}
34
35	var limit = $('#input-limit').data('filter-limit');
36
37	if (limit) {
38		f['limit'] = [limit];
39	}
40
41	var url = [];
42
43	$.each(f, function (k, v) {
44		url.push(k + '=' + v.join(Journal['filterUrlValuesSeparator'] || ','));
45	});
46
47	url = url.join('&');
48
49	if (!url) {
50		return Journal['filterBase'];
51	}
52
53	if (Journal['filterBase'].indexOf('?') === -1) {
54		return Journal['filterBase'] + '?' + url;
55	}
56
57	return Journal['filterBase'] + '&' + url;
58}
59
60function journal_filter_price_slider() {
61	$('.filter-price .range-slider input').ionRangeSlider({
62		type: 'double',
63		min: $('.filter-price-min').data('min'),
64		max: $('.filter-price-max').data('max'),
65		from: $('.filter-price-min').val(),
66		to: $('.filter-price-max').val(),
67		onFinish: function (data) {
68			$('.filter-price-min').val(data.from);
69			$('.filter-price-max').val(data.to).trigger('blur');
70		},
71		prettify: function (value) {
72			if (Journal['currency_left']) {
73				return accounting.formatMoney(value, Journal['currency_left'], 0, Journal['currency_thousand'], Journal['currency_decimal'], '%s%v');
74			}
75
76			return accounting.formatMoney(value, Journal['currency_right'], 0, Journal['currency_thousand'], Journal['currency_decimal'], '%v%s');
77		}
78	});
79}
80
81function journal_filter(url, opts) {
82	opts = opts || {};
83
84	var source = opts.source;
85	var updateHistory = opts.updateHistory;
86
87	try {
88		var u = new URL(url);
89
90		u.host = window.location.host;
91		u.hostname = window.location.hostname;
92		u.protocol = window.location.protocol;
93
94		url = u.toString();
95	} catch (e) {
96	}
97
98	if (Journal.infiniteScrollInstance) {
99		Journal.infiniteScrollInstance.destroy();
100	}
101
102	$.ajax({
103		url: url,
104		dataType: 'html',
105		beforeSend: function () {
106			var $slider = $('.filter-price .range-slider input');
107
108			if ($slider.length && $slider.data('ionRangeSlider')) {
109				$slider.data('ionRangeSlider').destroy();
110			}
111
112			$('[data-toggle="tooltip"]').tooltip('hide');
113
114			loader('.container > .row', true);
115		},
116		complete: function () {
117			loader('.container > .row', false);
118
119			if (Journal['filterScrollTop'] || (source === 'pagination')) {
120				$('html, body').animate({ scrollTop: 0 }, 700);
121			}
122		},
123		success: function (response) {
124			var $response = $(response);
125
126			Journal['filterCollapsed'] = {};
127
128			$('.module-filter .module-item .panel-heading a').each(function () {
129				var $this = $(this);
130				Journal['filterCollapsed'][$this.data('filter')] = $this.hasClass('collapsed');
131			});
132
133			$('.module-filter').replaceWith($response.find('.module-filter'));
134			$('.main-products-wrapper').replaceWith($response.find('.main-products-wrapper'));
135			$('#input-sort, #input-limit').removeAttr('onchange');
136
137			if (updateHistory !== false && window.history && window.history.pushState) {
138				var state;
139
140				if (source === 'pagination') {
141					state = { Title: document.title, Url: url };
142					window.history.pushState(state, state.Title, state.Url);
143				} else {
144					var currentUrl = journal_filter_url();
145
146					if (currentUrl.length === url.length) {
147						state = { Title: document.title, Url: url };
148						window.history.pushState(state, state.Title, state.Url);
149					} else {
150						if (!opts.refilter) {
151							opts.refilter = true;
152							journal_filter(currentUrl, opts);
153						}
154					}
155				}
156			}
157
158			var $panel_group = $('.panel-group');
159
160			$panel_group.on('show.bs.collapse', function (e) {
161				$(e.target).parent().addClass('panel-active');
162				$(e.target).parent().removeClass('panel-collapsed');
163			});
164
165			$panel_group.on('hide.bs.collapse', function (e) {
166				$(e.target).parent().removeClass('panel-active');
167				$(e.target).parent().addClass('panel-collapsing');
168			});
169
170			$panel_group.on('hidden.bs.collapse', function (e) {
171				$(e.target).parent().removeClass('panel-collapsing');
172				$(e.target).parent().addClass('panel-collapsed');
173			});
174
175			Object.keys(Journal['filterCollapsed']).forEach(function (key) {
176				var $collapse = $($('.module-filter .module-item .panel-heading a[data-filter="' + key + '"]').attr('href'));
177
178				if (Journal['filterCollapsed'][key] === true) {
179					$collapse.collapse('hide');
180				}
181
182				if (Journal['filterCollapsed'][key] === false) {
183					$collapse.collapse('show');
184				}
185			});
186
187			Journal.lazyLoadInstance && Journal.lazyLoadInstance.update();
188
189			journal_filter_price_slider();
190			journal_enable_stepper();
191			journal_enable_countdown();
192
193			if (Journal.infiniteScrollInstance) {
194				$('.ias-trigger').remove();
195				setTimeout(function () {
196					Journal.infiniteScrollInstance.reinitialize();
197				}, 100);
198			}
199		}
200	});
201}
202
203jQuery(function ($) {
204	// price slider
205	journal_filter_price_slider();
206
207	// handle price change
208	var old;
209
210	$(document).delegate('.filter-price-min, .filter-price-max', 'focus', function (e) {
211		old = e.target.value;
212	});
213
214	$(document).delegate('.filter-price-min, .filter-price-max', 'blur keydown', function (e) {
215		if ((e.type === 'keydown' && e.keyCode === 13) || (e.type === 'focusout')) {
216			var value = e.target.value.trim();
217
218			if ($.isNumeric(value) && (old !== value)) {
219				journal_filter(journal_filter_url());
220
221				return false;
222			}
223		}
224	});
225
226	// handle filters changes
227	$(document).delegate('[data-filter-trigger]', 'change', function () {
228		journal_filter(journal_filter_url(), { source: 'filters' });
229
230		return false;
231	});
232
233	// handle pagination changes
234	$(document).delegate('.pagination a', 'click', function () {
235		journal_filter($(this).attr('href'), { source: 'pagination' });
236
237		return false;
238	});
239
240	// handle sort and limit changes
241	$('#input-sort, #input-limit').removeAttr('onchange');
242
243	$(document).delegate('#input-sort, #input-limit', 'change', function () {
244		journal_filter($(this).val());
245
246		return false;
247	});
248
249	// handle back button
250	$(window).on('popstate', function (e) {
251		// journal_filter(window.location.href, { updateHistory: false });
252		window.location.reload();
253	});
254
255	// handle reset button
256	$(document).delegate('.reset-filter', 'click', function () {
257		journal_filter(Journal['filterBase']);
258	});
259});

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.