PageSourceSearch

https://rockway.biz/catalog/view/javascript/common.js

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