PageSourceSearch

https://healthwyze.org/store/catalog/view/javascript/common.js

js healthwyze.org collected 2026-10-02 10:21:03 UTC 14,154 bytes, 493 lines download raw bytes

1function getURLVar(key) {
2	var value = [];
3
4	var query = String(document.location).split('?');
5
6	if (query[1]) {
7		var part = query[1].split('&');
8
9		for (i = 0; i < part.length; i++) {
10			var data = part[i].split('=');
11
12			if (data[0] && data[1]) {
13				value[data[0]] = data[1];
14			}
15		}
16
17		if (value[key]) {
18			return value[key];
19		} else {
20			return '';
21		}
22	}
23}
24
25$(document).ready(function() {
26	
27	// Highlight any found errors
28	$('.text-danger').each(function() {
29		var element = $(this).parent().parent();
30		
31		if (element.hasClass('form-group')) {
32			element.addClass('has-error');
33		}
34	});
35		
36	// Currency
37	$('#form-currency .currency-select').on('click', function(e) {
38		e.preventDefault();
39
40		$('#form-currency input[name=\'code\']').val($(this).attr('name'));
41
42		$('#form-currency').submit();
43	});
44
45	// Language
46	$('#form-language .language-select').on('click', function(e) {
47		e.preventDefault();
48
49		$('#form-language input[name=\'code\']').val($(this).attr('name'));
50
51		$('#form-language').submit();
52	});
53
54	/* Search */
55	$('#search input[name=\'search\']').parent().find('button').on('click', function() {
56		var url = $('base').attr('href') + 'index.php?route=product/search';
57
58		var value = $('header input[name=\'search\']').val();
59
60		if (value) {
61			url += '&search=' + encodeURIComponent(value);
62		}
63
64		location = url;
65	});
66
67	$('#search input[name=\'search\']').on('keydown', function(e) {
68		if (e.keyCode == 13) {
69			$('header input[name=\'search\']').parent().find('button').trigger('click');
70		}
71	});
72
73	// Menu
74	$('#menu .dropdown-menu').each(function() {
75		var menu = $('#menu').offset();
76		var dropdown = $(this).parent().offset();
77
78		var i = (dropdown.left + $(this).outerWidth()) - (menu.left + $('#menu').outerWidth());
79
80		if (i > 0) {
81			$(this).css('margin-left', '-' + (i + 10) + 'px');
82		}
83	});
84
85	// Product List
86	$('#list-view').click(function() {
87		$('#content .product-grid > .clearfix').remove();
88
89		//$('#content .product-layout').attr('class', 'product-layout product-list col-xs-12');
90		$('#content .row > .product-grid').attr('class', 'product-layout product-list col-xs-12');
91	$('#grid-view').removeClass('active');
92	$('#list-view').addClass('active');
93		
94		localStorage.setItem('display', 'list');
95	});
96
97	// Product Grid
98	$('#grid-view').click(function() {
99
100		// What a shame bootstrap does not take into account dynamically loaded columns
101		var cols = $('#column-right, #column-left').length; 
102
103		if (cols == 2) {
104			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-6 col-md-6 col-sm-12 col-xs-12');
105		} else if (cols == 1) {
106			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-12');
107		} else {
108			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-6 col-xs-12');
109		}
110
111		 $('#list-view').removeClass('active');
112		$('#grid-view').addClass('active');
113
114		localStorage.setItem('display', 'grid');
115	});
116
117	if (localStorage.getItem('display') == 'grid') {
118		$('#grid-view').trigger('click');
119		$('#grid-view').addClass('active');
120	} else {
121		$('#list-view').trigger('click');
122		$('#list-view').addClass('active');
123	}
124
125	// Checkout
126	$(document).on('keydown', '#collapse-checkout-option input[name=\'email\'], #collapse-checkout-option input[name=\'password\']', function(e) {
127		if (e.keyCode == 13) {
128			$('#collapse-checkout-option #button-login').trigger('click');
129		}
130	});
131
132	// tooltips on hover
133	$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
134
135	// Makes tooltips work on ajax generated content
136	$(document).ajaxStop(function() {
137		$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
138	});
139});
140
141// Cart add remove functions
142var cart = {
143	'add': function(product_id, quantity) {
144		$.ajax({
145			url: 'index.php?route=checkout/cart/add',
146			type: 'post',
147			data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
148			dataType: 'json',
149			beforeSend: function() {
150				$('#cart > button').button('loading');
151			},
152			complete: function() {
153				$('#cart > button').button('reset');
154			},			
155			success: function(json) {
156				$('.alert, .text-danger').remove();
157
158				if (json['redirect']) {
159					location = json['redirect'];
160				}
161
162				if (json['success']) {
163					$('#content').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
164					
165					// Need to set timeout otherwise it wont update the total
166					setTimeout(function () {
167						$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '<i class="fa fa-angle-down"></i></span>');
168					}, 100);
169				
170					$('html, body').animate({ scrollTop: 0 }, 'slow');
171
172					$('#cart > ul').load('index.php?route=common/cart/info ul li');
173				}
174			},
175	        error: function(xhr, ajaxOptions, thrownError) {
176	            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
177			}
178		});
179	},
180	'update': function(key, quantity) {
181		$.ajax({
182			url: 'index.php?route=checkout/cart/edit',
183			type: 'post',
184			data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
185			dataType: 'json',
186			beforeSend: function() {
187				$('#cart > button').button('loading');
188			},
189			complete: function() {
190				$('#cart > button').button('reset');
191			},			
192			success: function(json) {
193				// Need to set timeout otherwise it wont update the total
194				setTimeout(function () {
195					$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '<i class="fa fa-angle-down"></i></span>');
196				}, 100);
197
198				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
199					location = 'index.php?route=checkout/cart';
200				} else {
201					$('#cart > ul').load('index.php?route=common/cart/info ul li');
202				}
203			},
204	        error: function(xhr, ajaxOptions, thrownError) {
205	            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
206			}
207		});
208	},
209	'remove': function(key) {
210		$.ajax({
211			url: 'index.php?route=checkout/cart/remove',
212			type: 'post',
213			data: 'key=' + key,
214			dataType: 'json',
215			beforeSend: function() {
216				$('#cart > button').button('loading');
217			},
218			complete: function() {
219				$('#cart > button').button('reset');
220			},			
221			success: function(json) {
222				// Need to set timeout otherwise it wont update the total
223				setTimeout(function () {
224					$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '<i class="fa fa-angle-down"></i></span>');
225				}, 100);
226					
227				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
228					location = 'index.php?route=checkout/cart';
229				} else {
230					$('#cart > ul').load('index.php?route=common/cart/info ul li');
231				}
232			},
233	        error: function(xhr, ajaxOptions, thrownError) {
234	            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
235			}
236		});
237	}
238}
239
240var voucher = {
241	'add': function() {
242
243	},
244	'remove': function(key) {
245		$.ajax({
246			url: 'index.php?route=checkout/cart/remove',
247			type: 'post',
248			data: 'key=' + key,
249			dataType: 'json',
250			beforeSend: function() {
251				$('#cart > button').button('loading');
252			},
253			complete: function() {
254				$('#cart > button').button('reset');
255			},
256			success: function(json) {
257				// Need to set timeout otherwise it wont update the total
258				setTimeout(function () {
259					$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '<i class="fa fa-angle-down"></i></span>');
260				}, 100);
261
262				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
263					location = 'index.php?route=checkout/cart';
264				} else {
265					$('#cart > ul').load('index.php?route=common/cart/info ul li');
266				}
267			},
268	        error: function(xhr, ajaxOptions, thrownError) {
269	            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
270			}
271		});
272	}
273}
274
275var wishlist = {
276	'add': function(product_id) {
277		$.ajax({
278			url: 'index.php?route=account/wishlist/add',
279			type: 'post',
280			data: 'product_id=' + product_id,
281			dataType: 'json',
282			success: function(json) {
283				$('.alert').remove();
284
285				if (json['redirect']) {
286		location = json['redirect'];
287			}
288
289		if (json['success']) {
290			$('#content').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
291		}	
292
293				$('#wishlist-total span').html(json['total']);
294			 $('#wishlist-total').attr('title', json['total']);
295
296				$('html, body').animate({ scrollTop: 0 }, 'slow');
297			},
298	        error: function(xhr, ajaxOptions, thrownError) {
299	            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
300	        }
301		});
302	},
303	'remove': function() {
304
305	}
306}
307
308var compare = {
309	'add': function(product_id) {
310		$.ajax({
311			url: 'index.php?route=product/compare/add',
312			type: 'post',
313			data: 'product_id=' + product_id,
314			dataType: 'json',
315			success: function(json) {
316				$('.alert').remove();
317
318				if (json['success']) {
319					$('#content').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
320
321					$('#compare-total').html(json['total']);
322
323					$('html, body').animate({ scrollTop: 0 }, 'slow');
324				}
325			},
326	        error: function(xhr, ajaxOptions, thrownError) {
327	            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
328	        }
329		});
330	},
331	'remove': function() {
332
333	}
334}
335
336/* Agree to Terms */
337$(document).delegate('.agree', 'click', function(e) {
338	e.preventDefault();
339
340	$('#modal-agree').remove();
341
342	var element = this;
343
344	$.ajax({
345		url: $(element).attr('href'),
346		type: 'get',
347		dataType: 'html',
348		success: function(data) {
349			html  = '<div id="modal-agree" class="modal">';
350			html += '  <div class="modal-dialog">';
351			html += '    <div class="modal-content">';
352			html += '      <div class="modal-header">';
353			html += '        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
354			html += '        <h4 class="modal-title">' + $(element).text() + '</h4>';
355			html += '      </div>';
356			html += '      <div class="modal-body">' + data + '</div>';
357			html += '    </div';
358			html += '  </div>';
359			html += '</div>';
360
361			$('body').append(html);
362
363			$('#modal-agree').modal('show');
364		}
365	});
366});
367
368// Autocomplete */
369(function($) {
370	$.fn.autocomplete = function(option) {
371		return this.each(function() {
372			this.timer = null;
373			this.items = new Array();
374	
375			$.extend(this, option);
376	
377			$(this).attr('autocomplete', 'off');
378			
379			// Focus
380			$(this).on('focus', function() {
381				this.request();
382			});
383			
384			// Blur
385			$(this).on('blur', function() {
386				setTimeout(function(object) {
387					object.hide();
388				}, 200, this);				
389			});
390			
391			// Keydown
392			$(this).on('keydown', function(event) {
393				switch(event.keyCode) {
394					case 27: // escape
395						this.hide();
396						break;
397					default:
398						this.request();
399						break;
400				}				
401			});
402			
403			// Click
404			this.click = function(event) {
405				event.preventDefault();
406	
407				value = $(event.target).parent().attr('data-value');
408	
409				if (value && this.items[value]) {
410					this.select(this.items[value]);
411				}
412			}
413			
414			// Show
415			this.show = function() {
416				var pos = $(this).position();
417	
418				$(this).siblings('ul.dropdown-menu').css({
419					top: pos.top + $(this).outerHeight(),
420					left: pos.left
421				});
422	
423				$(this).siblings('ul.dropdown-menu').show();
424			}
425			
426			// Hide
427			this.hide = function() {
428				$(this).siblings('ul.dropdown-menu').hide();
429			}		
430			
431			// Request
432			this.request = function() {
433				clearTimeout(this.timer);
434		
435				this.timer = setTimeout(function(object) {
436					object.source($(object).val(), $.proxy(object.response, object));
437				}, 200, this);
438			}
439			
440			// Response
441			this.response = function(json) {
442				html = '';
443	
444				if (json.length) {
445					for (i = 0; i < json.length; i++) {
446						this.items[json[i]['value']] = json[i];
447					}
448	
449					for (i = 0; i < json.length; i++) {
450						if (!json[i]['category']) {
451							html += '<li data-value="' + json[i]['value'] + '"><a href="#">' + json[i]['label'] + '</a></li>';
452						}
453					}
454	
455					// Get all the ones with a categories
456					var category = new Array();
457	
458					for (i = 0; i < json.length; i++) {
459						if (json[i]['category']) {
460							if (!category[json[i]['category']]) {
461								category[json[i]['category']] = new Array();
462								category[json[i]['category']]['name'] = json[i]['category'];
463								category[json[i]['category']]['item'] = new Array();
464							}
465	
466							category[json[i]['category']]['item'].push(json[i]);
467						}
468					}
469	
470					for (i in category) {
471						html += '<li class="dropdown-header">' + category[i]['name'] + '</li>';
472	
473						for (j = 0; j < category[i]['item'].length; j++) {
474							html += '<li data-value="' + category[i]['item'][j]['value'] + '"><a href="#">&nbsp;&nbsp;&nbsp;' + category[i]['item'][j]['label'] + '</a></li>';
475						}
476					}
477				}
478	
479				if (html) {
480					this.show();
481				} else {
482					this.hide();
483				}
484	
485				$(this).siblings('ul.dropdown-menu').html(html);
486			}
487			
488			$(this).after('<ul class="dropdown-menu"></ul>');
489			$(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this));	
490			
491		});
492	}
493})(window.jQuery);

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.