PageSourceSearch

https://oookaller.ru/catalog/view/javascript/common.js

js oookaller.ru collected 2026-10-07 03:34:06 UTC 13,695 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	$('#currency .currency-select').on('click', function(e) {
37		e.preventDefault();
38
39		$('#currency input[name=\'code\']').attr('value', $(this).attr('name'));
40
41		$('#currency').submit();
42	});
43
44	// Language
45	$('#language a').on('click', function(e) {
46		e.preventDefault();
47
48		$('#language input[name=\'code\']').attr('value', $(this).attr('href'));
49
50		$('#language').submit();
51	});
52
53	/* Search */
54	$('#search input[name=\'search\']').parent().find('button').on('click', function() {
55		url = $('base').attr('href') + 'index.php?route=product/search';
56
57		var value = $('header input[name=\'search\']').val();
58
59		if (value) {
60        url += '&search=' + encodeURIComponent(value).
61        // Note that although RFC3986 reserves "!", RFC5987 does not,
62        // so we do not need to escape it
63        replace(/['()]/g, escape). // i.e., %27 %28 %29
64        replace(/\*/g, '%2A').
65        replace(/\+/g, '%2B').       
66        replace(/%2F/g,"/").
67            // The following are not required for percent-encoding per RFC5987, 
68            //  so we can allow for a little better readability over the wire: |`^
69            replace(/%(?:7C|60|5E)/g, unescape);
70
71		}
72
73		location = url;
74	});
75
76	$('#search input[name=\'search\']').on('keydown', function(e) {
77		if (e.keyCode == 13) {
78			$('header input[name=\'search\']').parent().find('button').trigger('click');
79		}
80	});
81
82	// Menu
83	$('#menu .dropdown-menu').each(function() {
84		var menu = $('#menu').offset();
85		var dropdown = $(this).parent().offset();
86
87		var i = (dropdown.left + $(this).outerWidth()) - (menu.left + $('#menu').outerWidth());
88
89		if (i > 0) {
90			$(this).css('margin-left', '-' + (i + 5) + 'px');
91		}
92	});
93
94	// Product List
95	$('#list-view').click(function() {
96		$('#content .product-grid > .clearfix').remove();
97
98		//$('#content .product-layout').attr('class', 'product-layout product-list col-xs-12');
99		$('#content .row > .product-grid').attr('class', 'product-layout product-list col-xs-12');
100
101		localStorage.setItem('display', 'list');
102	});
103
104	// Product Grid
105	$('#grid-view').click(function() {
106		// What a shame bootstrap does not take into account dynamically loaded columns
107		cols = $('#column-right, #column-left').length;
108
109		if (cols == 2) {
110			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-6 col-md-6 col-sm-12 col-xs-12');
111		} else if (cols == 1) {
112			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-12');
113		} else {
114			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-6 col-xs-12');
115		}
116
117		 localStorage.setItem('display', 'grid');
118	});
119
120	if (localStorage.getItem('display') == 'list') {
121		$('#list-view').trigger('click');
122	} else {
123		$('#grid-view').trigger('click');
124	}
125
126	// Checkout
127	$(document).on('keydown', '#collapse-checkout-option input[name=\'email\'], #collapse-checkout-option input[name=\'password\']', function(e) {
128		if (e.keyCode == 13) {
129			$('#collapse-checkout-option #button-login').trigger('click');
130		}
131	});
132
133	// tooltips on hover
134	$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
135
136	// Makes tooltips work on ajax generated content
137	$(document).ajaxStop(function() {
138		$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
139	});
140});
141
142// Cart add remove functions
143var cart = {
144	'add': function(product_id, quantity) {
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				}
293
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.