PageSourceSearch

https://minoko.com.ua/catalog/view/javascript/common.js

js minoko.com.ua collected 2026-10-07 19:41:57 UTC 21,085 bytes, 672 lines download raw bytes

1function getURLVar(key) {
2	var value = [];
3	var query = String(document.location).split('?');
4	if (query[1]) {
5		var part = query[1].split('&');
6		for (i = 0; i < part.length; i++) {
7			var data = part[i].split('=');
8			if (data[0] && data[1]) {
9				value[data[0]] = data[1];
10			}
11		}
12		if (value[key]) {
13			return value[key];
14		} else {
15			return '';
16		}
17	} else {	// Изменения для seo_url от Русской сборки OpenCart 3x
18		var query = String(document.location.pathname).split('/');
19		if (query[query.length - 1] == 'cart') value['route'] = 'checkout/cart';
20		if (query[query.length - 1] == 'checkout') value['route'] = 'checkout/checkout';
21
22		if (value[key]) {
23			return value[key];
24		} else {
25			return '';
26		}
27	}
28}
29function close_window(){
30	$('.alert').remove();
31}
32$(document).ready(function() {
33	$('body').on('click', '.close-mobile-search', function () {
34		$(this).parent().parent().find('.dropdown-menu').hide();
35		$('#search input').val('');
36		$('html, body').removeClass('lock');
37		$('.close-mobile-search').removeClass('active');
38
39	});
40    $("#morning").attr('checked','checked');
41    // Знайти останню кнопку і посилання в блоці simplecheckout_proceed_payment
42    
43    // Перевірити стан чекбокса і встановити/зняти клас disabled
44    function toggleButtonState() {
45        if ($('#morning').is(':checked')) {
46            console.log('checked');
47            $('#simplecheckout_button_confirm').removeClass('disabled');
48        } else {
49            console.log('not checked');
50            $('#simplecheckout_button_confirm').addClass('disabled');
51        }
52    }
53    
54    // Встановити початковий стан кнопки і посилання
55    toggleButtonState();
56    
57    // Додати обробник на зміну стану чекбокса
58    $('body').on('click', function() {
59        toggleButtonState();
60    });
61
62	var contactsPopup = $('.contacts_popup');
63
64	$(document).on('click', function(e) {
65		if (contactsPopup.hasClass('open') && 
66			!contactsPopup.is(e.target) && 
67			contactsPopup.has(e.target).length === 0 && 
68			!$('#call_phone_toggle').is(e.target)) {
69			
70			contactsPopup.removeClass('open');
71		}
72	});
73	
74	$('#call_phone_toggle').on('click', function(e) {
75		e.stopPropagation(); // Зупиняємо поширення події
76		e.preventDefault();
77		contactsPopup.toggleClass('open');
78	});
79	// Highlight any found errors
80	$('.text-danger').each(function() {
81		var element = $(this).parent().parent();
82
83		if (element.hasClass('form-group')) {
84			element.addClass('has-error');
85		}
86	});
87
88	$('body').on('click', '.btn-exit', function(){
89		$('.container-cart').removeClass('in');
90	});
91
92	$('.main-menu').on('click', function(){
93		$('.main-menu-content').toggleClass('in');
94		$('.categories_listWraper').removeClass('in');
95		$('body').removeClass('fixbody');
96	});
97
98	$('#categories_listButtonClose').on('click', function () {
99		$('.categories_listWraper').removeClass('in');
100		$('body').removeClass('fixbody');
101		$('body').removeClass('lock');
102	});
103
104	$('#cart').on('click', function(){
105		$('.container-cart').toggleClass('in');
106	});
107
108	$('.section-wishlist > div').on('click', function(){
109		$(this).parent().toggleClass('add-wishlist');
110	});
111
112	$('.item-catalog-panel, .mobile-catalog').on('click', function () {
113		// console.log('click test');
114		$('.categories_listWraper').toggleClass('in');
115		$('body').toggleClass('fixbody');
116		$('body').toggleClass('lock');
117	});
118
119	$('.main-title-category').on('click', function(e){
120		$('.categoriesList li').removeClass('open');
121	});
122
123	$('.categories_lvl1Box .open').on('click', function () {
124		$(this).parent().parent().addClass('open');
125	});
126
127	// Currency
128	$('#form-currency .currency-select').on('click', function(e) {
129		e.preventDefault();
130
131		$('#form-currency input[name=\'code\']').val($(this).attr('name'));
132
133		$('#form-currency').submit();
134	});
135
136	// Language
137	/*$('#form-language .language-select').on('click', function(e) {
138		e.preventDefault();
139
140		$('#form-language input[name=\'code\']').val($(this).attr('name'));
141
142		$('#form-language').submit();
143	});*/
144	
145	/* Search */
146
147	//var url_split = window.location.href;
148
149	// Розбиття URL на частини за допомогою '/':
150	//var parts = url_split.split('/');
151	//console.log(parts);
152	// Припустимо, що префікс мови завжди буде першим сегментом після домену:
153	//var languagePrefix = parts[3]; // Ось тут 3 - це індекс сегмента, де знаходиться префікс мови
154
155	var pathParts = window.location.pathname.split('/').filter(Boolean); // прибираємо порожні елементи
156	var supportedLangs = ['ru', 'en', 'pl']; // додай свої мови
157	var languagePrefix = supportedLangs.includes(pathParts[0]) ? pathParts[0] : '';
158
159	console.log('Language Prefix:', languagePrefix);
160
161	$('#search input[name=\'search\']').parent().find('button').on('click', function() {
162		//var url = $('base').attr('href') + 'index.php?route=product/search';
163		if(languagePrefix != 'search'){
164			var url = $('base').attr('href') + ''+languagePrefix+'/index.php?route=product/search';
165		} else {
166			var url = $('base').attr('href') + 'index.php?route=product/search';
167		}
168
169
170		var value = $('#search input[name=\'search\']').val();
171
172		if (value) {
173			url += '&search=' + encodeURIComponent(value);
174		}
175
176		location = url;
177	});
178
179	$('#search input[name=\'search\']').on('keydown', function(e) {
180		if (e.keyCode == 13) {
181			$('#search input[name=\'search\']').parent().find('button').trigger('click');
182		}
183	});
184
185	// Menu
186	$('#menu .dropdown-menu').each(function() {
187		var menu = $('#menu').offset();
188		var dropdown = $(this).parent().offset();
189
190		var i = (dropdown.left + $(this).outerWidth()) - (menu.left + $('#menu').outerWidth());
191
192		if (i > 0) {
193			$(this).css('margin-left', '-' + (i + 10) + 'px');
194		}
195	});
196
197	// Product List
198	$('#list-view').click(function() {
199		$('#content .product-grid > .clearfix').remove();
200
201		$('#content .row > .product-grid').attr('class', 'product-layout product-list col-xs-12');
202		$('#grid-view').removeClass('active');
203		$('#list-view').addClass('active');
204
205		localStorage.setItem('display', 'list');
206	});
207
208	// Product Grid
209	$('#grid-view').click(function() {
210		// What a shame bootstrap does not take into account dynamically loaded columns
211		var cols = $('#column-right, #column-left').length;
212
213		if (cols == 2) {
214			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-6 col-md-6 col-sm-12 col-xs-12');
215		} else if (cols == 1) {
216			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-12');
217		} else {
218			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-6 col-xs-12');
219		}
220
221		$('#list-view').removeClass('active');
222		$('#grid-view').addClass('active');
223
224		localStorage.setItem('display', 'grid');
225	});
226
227	if (localStorage.getItem('display') == 'list') {
228		$('#list-view').trigger('click');
229		$('#list-view').addClass('active');
230	} else {
231		$('#grid-view').trigger('click');
232		$('#grid-view').addClass('active');
233	}
234
235	// Checkout
236	$(document).on('keydown', '#collapse-checkout-option input[name=\'email\'], #collapse-checkout-option input[name=\'password\']', function(e) {
237		if (e.keyCode == 13) {
238			$('#collapse-checkout-option #button-login').trigger('click');
239		}
240	});
241
242	// tooltips on hover
243	$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
244
245	// Makes tooltips work on ajax generated content
246	$(document).ajaxStop(function() {
247		$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
248	});
249});
250
251var cart = {
252	'add': function(product_id, quantity) {
253		$.ajax({
254			url: 'index.php?route=checkout/cart/add',
255			type: 'post',
256			data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
257			dataType: 'json',
258			success: function(json) {
259				$('.alert-dismissible, .text-danger').remove();
260
261				if (json['redirect']) {
262					location = json['redirect'];
263				}
264
265				if (json['success']) {
266					$('#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>');
267
268					// Need to set timeout otherwise it wont update the total
269					setTimeout(function () {
270						$('#cart-total').html('' + json['total'] + '');
271					}, 100);
272
273					//$('html, body').animate({ scrollTop: 0 }, 'slow');
274
275					var offset = $("#cart-total").offset();
276					// var img = $('.item-product-image' + product_id).find('img').attr('src');
277					var img = $('.product_' + product_id + ' a img').attr('src');
278					var flyer = $('<img class="flyer-img" src="' + img + '">');
279
280					flyer.clone().css({
281						'position': 'absolute',
282						'z-index': '100',
283						'left': flyer.offset()['left'],
284						'top': flyer.offset()['top'],
285					}).appendTo(".product_" + product_id + " a img").animate({
286							top: offset['top'] + 10,
287							left: offset['left'] + 10,
288							width: 0,
289							opacity: 0,
290						}, 1000, function(){
291							$(this).remove();
292					});
293
294					$('.mini-cart .container-cart > ul').load('index.php?route=common/cart/info ul');
295					// $('.container-cart').addClass('in');
296					setTimeout(close_window, 1000);
297				}
298			},
299			error: function(xhr, ajaxOptions, thrownError) {
300				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
301			}
302		});
303	},
304	'update': function(key, quantity) {
305		$.ajax({
306			url: 'index.php?route=checkout/cart/edit',
307			type: 'post',
308			data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
309			dataType: 'json',
310			success: function(json) {
311				// Need to set timeout otherwise it wont update the total
312				setTimeout(function () {
313					$('#cart-total').html('' + json['total'] + '');
314				}, 100);
315
316				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
317					location = 'index.php?route=checkout/cart';
318				} else {
319					$('.mini-cart .container-cart > ul').load('index.php?route=common/cart/info ul');
320				}
321			},
322			error: function(xhr, ajaxOptions, thrownError) {
323				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
324			}
325		});
326	},
327	'remove': function(key) {
328		$.ajax({
329			url: 'index.php?route=checkout/cart/remove',
330			type: 'post',
331			data: 'key=' + key,
332			dataType: 'json',
333			success: function(json) {
334				// Need to set timeout otherwise it wont update the total
335				setTimeout(function () {
336					$('#cart-total').html('' + json['total'] + '');
337				}, 100);
338
339				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
340					location = 'index.php?route=checkout/cart';
341				} else {
342					$('.mini-cart .container-cart > ul').load('index.php?route=common/cart/info ul');
343				}
344
345				setTimeout(close_window, 1000);
346			},
347			error: function(xhr, ajaxOptions, thrownError) {
348				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
349			}
350		});
351	}
352}
353
354var voucher = {
355	'add': function() {
356
357	},
358	'remove': function(key) {
359		$.ajax({
360			url: 'index.php?route=checkout/cart/remove',
361			type: 'post',
362			data: 'key=' + key,
363			dataType: 'json',
364			success: function(json) {
365				// Need to set timeout otherwise it wont update the total
366				setTimeout(function () {
367					$('#cart-total').html('' + json['total'] + '');
368				}, 100);
369
370				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
371					location = 'index.php?route=checkout/cart';
372				} else {
373					$('.mini-cart .container-cart > ul').load('index.php?route=common/cart/info ul');
374				}
375			},
376			error: function(xhr, ajaxOptions, thrownError) {
377				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
378			}
379		});
380	}
381}
382
383var wishlist = {
384	'add': function(product_id) {
385		$('.alert-success').remove();
386		$.ajax({
387			url: 'index.php?route=account/wishlist/add',
388			type: 'post',
389			data: 'product_id=' + product_id,
390			dataType: 'json',
391			success: function(json) {
392				$('.alert-dismissible').remove();
393
394				if (json['redirect']) {
395					location = json['redirect'];
396				}
397
398				if (json['success']) {
399					if(!json['error_product']){
400						$('#content').parent().before('<div class="alert alert-success"><svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="0 0 56 56" fill="none"><rect x="4" y="4" width="48" height="48" rx="24" fill="#fdbbbd"/><path fill-rule="evenodd" clip-rule="evenodd" d="M19.4639 22.5264C20.4016 21.5891 21.6731 21.0625 22.9989 21.0625C24.3248 21.0625 25.5963 21.5891 26.5339 22.5264L27.9989 23.9902L29.4639 22.5264C29.9252 22.0489 30.4769 21.668 31.0869 21.4059C31.6969 21.1439 32.353 21.006 33.0169 21.0002C33.6808 20.9944 34.3392 21.1209 34.9537 21.3723C35.5682 21.6237 36.1264 21.995 36.5959 22.4645C37.0654 22.9339 37.4366 23.4922 37.688 24.1067C37.9394 24.7212 38.066 25.3796 38.0602 26.0434C38.0544 26.7073 37.9165 27.3634 37.6544 27.9735C37.3924 28.5835 37.0115 29.1352 36.5339 29.5964L27.9989 38.1327L19.4639 29.5964C18.5266 28.6588 18 27.3873 18 26.0614C18 24.7356 18.5266 23.4641 19.4639 22.5264V22.5264Z" fill="#ffdfe0"/><rect x="4" y="4" width="48" height="48" rx="24" stroke="#ffdfe0" stroke-width="8"/></svg> ' + json['success'] + ' <div class="alert_buttons"><button type="button" class="close_alert" data-dismiss="alert">
400' + json['text_back'] + '</button></div></div>');
401					} else {
402						$('#content').parent().before('<div class="alert alert-success"><svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="0 0 56 56" fill="none"><rect x="4" y="4" width="48" height="48" rx="24" fill="#fdbbbd"/><path fill-rule="evenodd" clip-rule="evenodd" d="M19.4639 22.5264C20.4016 21.5891 21.6731 21.0625 22.9989 21.0625C24.3248 21.0625 25.5963 21.5891 26.5339 22.5264L27.9989 23.9902L29.4639 22.5264C29.9252 22.0489 30.4769 21.668 31.0869 21.4059C31.6969 21.1439 32.353 21.006 33.0169 21.0002C33.6808 20.9944 34.3392 21.1209 34.9537 21.3723C35.5682 21.6237 36.1264 21.995 36.5959 22.4645C37.0654 22.9339 37.4366 23.4922 37.688 24.1067C37.9394 24.7212 38.066 25.3796 38.0602 26.0434C38.0544 26.7073 37.9165 27.3634 37.6544 27.9735C37.3924 28.5835 37.0115 29.1352 36.5339 29.5964L27.9989 38.1327L19.4639 29.5964C18.5266 28.6588 18 27.3873 18 26.0614C18 24.7356 18.5266 23.4641 19.4639 22.5264V22.5264Z" fill="#ffdfe0"/><rect x="4" y="4" width="48" height="48" rx="24" stroke="#ffdfe0" stroke-width="8"/></svg> ' + json['error_product'] + ' <div class="alert_buttons"><button type="button" class="close_alert" data-dismiss="alert">' + json['text_back'] + '</button></div></div>');
403					}
404
405					// setTimeout(close_window, 1000);
406				}
407				$('#wishlist-total span.whishlist-total').css('display', 'flex');
408				$('#wishlist-total span.whishlist-total').html(json['total']);
409				$('#wishlist-total').attr('title', json['total']);
410			},
411			error: function(xhr, ajaxOptions, thrownError) {
412				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
413			}
414		});
415	},
416	'remove': function() {
417
418	}
419}
420
421var compare = {
422	'add': function(product_id) {
423		$.ajax({
424			url: 'index.php?route=product/compare/add',
425			type: 'post',
426			data: 'product_id=' + product_id,
427			dataType: 'json',
428			success: function(json) {
429				$('.alert-dismissible').remove();
430
431				if (json['success']) {
432					$('#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>');
433
434					$('#compare-total').html(json['total']);
435
436					$('html, body').animate({ scrollTop: 0 }, 'slow');
437				}
438			},
439			error: function(xhr, ajaxOptions, thrownError) {
440				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
441			}
442		});
443	},
444	'remove': function() {
445
446	}
447}
448
449/* Agree to Terms */
450$(document).delegate('.agree', 'click', function(e) {
451	e.preventDefault();
452
453	$('#modal-agree').remove();
454
455	var element = this;
456    console.log($(element).attr('href'));
457	$.ajax({
458		url: $(element).attr('href'),
459		type: 'get',
460		dataType: 'html',
461		success: function(data) {
462			html  = '<div id="modal-agree" class="modal">';
463			html += '  <div class="modal-dialog">';
464			html += '    <div class="modal-content">';
465			html += '      <div class="modal-header">';
466			html += '        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
467			html += '        <h4 class="modal-title">' + $(element).text() + '</h4>';
468			html += '      </div>';
469			html += '      <div class="modal-body">' + data + '</div>';
470			html += '    </div>';
471			html += '  </div>';
472			html += '</div>';
473
474			$('body').append(html);
475
476			$('#modal-agree').modal('show');
477		}
478	});
479});
480/* login_modal */
481$(document).delegate('.modal_login', 'click', function(e) {
482	e.preventDefault();
483	$('#modal-login').remove();
484	$('#modal-registration .close').click();
485
486	$.ajax({
487		url: 'index.php?route=account/login/modal',
488		type: 'get',
489		dataType: 'html',
490		success: function(data) {
491
492
493
494			$('body').append(data);
495
496			$('#modal-login').modal('show');
497		}
498	});
499});
500
501/* registration_modal */
502$(document).delegate('.registration_modal', 'click', function(e) {
503	e.preventDefault();
504	//$('#modal-forgotten').remove();
505	$('#modal-registration').remove();
506	$('#modal-login .close').click();
507
508	$.ajax({
509		url: 'index.php?route=account/simpleregister/modal',
510		type: 'get',
511		dataType: 'html',
512		success: function(data) {
513
514
515
516			$('body').append('<div id="modal-registration" class="modal">' + data + '</div>');
517
518			$('#modal-registration').modal('show');
519		},
520		error:function(json){
521
522		}
523	});
524});
525
526/* forgotten_modal */
527$(document).delegate('#forgotten_modal', 'click', function(e) {
528	e.preventDefault();
529	$('#modal-login .close').click();
530	$('#modal-forgotten').remove();
531
532
533
534	$.ajax({
535		url: 'index.php?route=account/forgotten/modal',
536		type: 'get',
537		dataType: 'html',
538		success: function(data) {
539
540			$('body').append(data);
541
542			$('#modal-forgotten').modal('show');
543		}
544	});
545});
546
547// Autocomplete */
548(function($) {
549	$.fn.autocomplete = function(option) {
550		return this.each(function() {
551			this.timer = null;
552			this.items = new Array();
553
554			$.extend(this, option);
555
556			$(this).attr('autocomplete', 'off');
557
558			// Focus
559			$(this).on('focus', function() {
560				this.request();
561			});
562
563			// Blur
564			$(this).on('blur', function() {
565				setTimeout(function(object) {
566					object.hide();
567				}, 200, this);
568			});
569
570			// Keydown
571			$(this).on('keydown', function(event) {
572				switch(event.keyCode) {
573					case 27: // escape
574						this.hide();
575						break;
576					default:
577						this.request();
578						break;
579				}
580			});
581
582			// Click
583			this.click = function(event) {
584				event.preventDefault();
585
586				value = $(event.target).parent().attr('data-value');
587
588				if (value && this.items[value]) {
589					this.select(this.items[value]);
590				}
591			}
592
593			// Show
594			this.show = function() {
595				var pos = $(this).position();
596
597				$(this).siblings('ul.dropdown-menu').css({
598					top: pos.top + $(this).outerHeight(),
599					left: pos.left
600				});
601
602				$(this).siblings('ul.dropdown-menu').show();
603			}
604
605			// Hide
606			this.hide = function() {
607				$(this).siblings('ul.dropdown-menu').hide();
608			}
609
610			// Request
611			this.request = function() {
612				clearTimeout(this.timer);
613
614				this.timer = setTimeout(function(object) {
615					object.source($(object).val(), $.proxy(object.response, object));
616				}, 200, this);
617			}
618
619			// Response
620			this.response = function(json) {
621				html = '';
622
623				if (json.length) {
624					for (i = 0; i < json.length; i++) {
625						this.items[json[i]['value']] = json[i];
626					}
627
628					for (i = 0; i < json.length; i++) {
629						if (!json[i]['category']) {
630							html += '<li data-value="' + json[i]['value'] + '"><a href="#">' + json[i]['label'] + '</a></li>';
631						}
632					}
633
634					// Get all the ones with a categories
635					var category = new Array();
636
637					for (i = 0; i < json.length; i++) {
638						if (json[i]['category']) {
639							if (!category[json[i]['category']]) {
640								category[json[i]['category']] = new Array();
641								category[json[i]['category']]['name'] = json[i]['category'];
642								category[json[i]['category']]['item'] = new Array();
643							}
644
645							category[json[i]['category']]['item'].push(json[i]);
646						}
647					}
648
649					for (i in category) {
650						html += '<li class="dropdown-header">' + category[i]['name'] + '</li>';
651
652						for (j = 0; j < category[i]['item'].length; j++) {
653							html += '<li data-value="' + category[i]['item'][j]['value'] + '"><a href="#">&nbsp;&nbsp;&nbsp;' + category[i]['item'][j]['label'] + '</a></li>';
654						}
655					}
656				}
657
658				if (html) {
659					this.show();
660				} else {
661					this.hide();
662				}
663
664				$(this).siblings('ul.dropdown-menu').html(html);
665			}
666
667			$(this).after('<ul class="dropdown-menu"></ul>');
668			$(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this));
669
670		});
671	}
672})(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.