PageSourceSearch

https://www.mascotasalfalfa.com/catalog/view/javascript/common.js

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