PageSourceSearch

https://www.eraled.sk/catalog/view/javascript/common.js

js eraled.sk collected 2026-10-06 13:15:48 UTC 18,216 bytes, 639 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}
24function isEmpty( el ){
25  return !$.trim(el.html())
26}
27$(document).ajaxStop(function() {
28	function isEmpty( el ){
29		return !$.trim(el.html())
30	}
31	if (!isEmpty($('#product'))) {
32		  $('#product .option-container').addClass('has-option');      
33	}	
34});
35function divWidthMenu() {
36	
37}
38function customResponsive(){
39	var window_w = parseInt($(window).width());	
40	
41	$("#logo img").each(function() {
42        if( this.complete ) {
43            divWidthMenu.call( this );
44        } else {
45            $(this).one('load', divWidthMenu);
46        }
47    });
48	
49}
50$(window).resize(function() {
51	customResponsive();
52});
53
54
55//sticky menu
56function stickyMenu(){
57	var winInnW = window.innerWidth;
58	var winScrT = $(window).scrollTop();
59	var headerSpaceH = $('.container-fix').outerHeight(true);
60	var scroll = $(window).scrollTop();
61	var currentP = 0;
62	stickyOffset = $('header').outerHeight(true);
63	
64	$('.headerSpace').remove();	
65	$('.container-fix').after('<div class="headerSpace unvisible" style="height: '+headerSpaceH+'px;" ></div>');	
66	// if(scroll != currentP){
67		// if(winInnW>1024){
68			// if(winScrT>stickyOffset){
69				// $('.container-fix').addClass('fix-header');			
70				// $('.headerSpace').removeClass('unvisible');
71			// } else{
72				// $('.container-fix').removeClass('fix-header');
73				// $('.headerSpace').addClass('unvisible');
74			// }
75		// } else{
76			// $('.container-fix').removeClass('fix-header');
77			// $('.headerSpace').addClass('unvisible');
78		// }
79	// } 
80	currentP = $(window).scrollTop();
81}
82
83$(document).ready(function() {
84	
85	$('body').on('click', '.ajxloadpg', function(e) {
86		e.preventDefault();
87		var me = this;
88		$('#content .custom-category').css({ opacity: .1 });
89		$.get( $(me).attr('href'), {}, function (r) { 
90			$('.custom-products').append( $('.custom-products', $(r)).html() );
91			$('.custom-category .toolbar-bottom').replaceWith( $('.custom-category .toolbar-bottom', $(r)) );
92			if (localStorage.getItem('display') == 'list') {			
93				$('#list-view').trigger('click');
94			} else {
95				$('#grid-view').trigger('click');
96			}
97			history.pushState( {}, '', $(me).data('pstt') );
98			
99			$('#content .custom-category').css({ opacity: 1 }); 
100		} );
101		return false;
102	});
103	
104	var act_xhr = false;
105	$('#column-left [name=\'filter[]\']').on('change', function() {
106		if ( act_xhr ) act_xhr.abort();
107		$('#content .custom-category').css({ opacity: .1 });
108		filter = [];
109		$('#column-left input[name^=\'filter\']:checked').each(function(element) {
110			filter.push(this.value);
111		});
112		act_xhr = $.pjax( { scrollTo: false, timeout:0, data: { 'filter': filter.join(',') }, 'container': '#content', 'fragment': '#content' } ).complete(function () { 
113			if (localStorage.getItem('display') == 'list') {			
114				$('#list-view').trigger('click');
115			} else {
116				$('#grid-view').trigger('click');
117			}
118			act_xhr = false; 
119		});
120	});
121	
122	//stickyMenu();
123	var sticky_menu = $('#sticky-menu').attr('data-sticky');
124	if (sticky_menu==1){
125		$(window).on('resize scroll', stickyMenu);	
126	}
127	
128	$('.container-fix').hover(function(){ 
129		$(this).addClass("fix-header-act");
130	},function(){ 
131		$(this).removeClass("fix-header-act");
132	});
133	
134	customResponsive();
135	
136	if (!isEmpty($('#product'))) {
137		  $('#product .option-container').addClass('has-option');      
138	}
139	if (!isEmpty($('#product2'))) {
140		  $('#product2 .option-container').addClass('has-option');      
141	}
142	
143	// Highlight any found errors
144	$('.text-danger').each(function() {
145		var element = $(this).parent().parent();
146
147		if (element.hasClass('form-group')) {
148			element.addClass('has-error');
149		}
150	});
151
152	// Currency
153	$('#form-currency .currency-select').on('click', function(e) {
154		e.preventDefault();
155
156		$('#form-currency input[name=\'code\']').val($(this).attr('name'));
157
158		$('#form-currency').submit();
159	});
160
161	// Language
162	$('#form-language .language-select').on('click', function(e) {
163		e.preventDefault();
164
165		$('#form-language input[name=\'code\']').val($(this).attr('name'));
166
167		$('#form-language').submit();
168	});
169
170	/* Search */
171	$('#search input[name=\'search\']').parent().find('button').on('click', function() {
172		var url = $('base').attr('href') + 'index.php?route=product/search';
173
174		var value = $('header #search input[name=\'search\']').val();
175
176		if (value) {
177			url += '&search=' + encodeURIComponent(value);
178		}
179
180		location = url;
181	});
182
183	$('#search input[name=\'search\']').on('keydown', function(e) {
184		if (e.keyCode == 13) {
185			$('header #search input[name=\'search\']').parent().find('button').trigger('click');
186		}
187	});
188
189	// Menu
190	$('#menu .dropdown-menu').each(function() {
191		var menu = $('#menu').offset();
192		var dropdown = $(this).parent().offset();
193
194		var i = (dropdown.left + $(this).outerWidth()) - (menu.left + $('#menu').outerWidth());
195
196		if (i > 0) {
197			$(this).css('margin-left', '-' + (i + 10) + 'px');
198		}
199	});
200
201	// Product List
202	$('body').on('click', '#list-view', function() {
203		$('.custom-products').addClass('custom-products-row');
204		$(this).addClass('selected');
205		$('#grid-view').removeClass('selected');
206		$('#content .product-grid > .clearfix').remove();
207		$('#content .product-grid').attr('class', 'product-layout product-list col-xs-12');
208		$('#content .product-list .caption').addClass('col-md-8 col-sm-8 col-sms-12');
209		$('#content .product-list .image').addClass('col-md-3 col-sm-4 col-sms-12');
210		
211
212		localStorage.setItem('display', 'list');
213	});
214    $('body').on('click', '.btn-list', function() {
215		$('.custom-products').addClass('custom-products-row');
216		$(this).addClass('selected');
217		$('#grid-view').removeClass('selected');
218		$('#content .product-grid > .clearfix').remove();
219		$('#content .product-grid').attr('class', 'product-layout product-list col-xs-12');
220		$('#content .custom-products-row .product-list .caption').addClass('col-md-8 col-sm-8 col-sms-12');
221		$('#content .custom-products-row .product-list .images-container').addClass('col-md-3 col-sm-4 col-sms-12');
222		
223
224		localStorage.setItem('display', 'list');
225	});
226	// Product Grid
227	$('body').on('click', '#grid-view', function() {
228		$('.custom-products').removeClass('custom-products-row');
229		$(this).addClass('selected');
230		$('#list-view').removeClass('selected');
231		// What a shame bootstrap does not take into account dynamically loaded columns
232		cols = $('#column-right, #column-left').length;
233
234		if (cols == 2) {
235			$('#content .product-layout').attr('class', 'product-layout product-grid col-md-6 col-sm-6 col-xs-2 two-items');
236		} else if (cols == 1) {
237			$('#content .product-layout').attr('class', 'product-layout product-grid col-md-3 col-sm-6 col-xs-6 four-items');
238		} else {
239			$('#content .product-layout').attr('class', 'product-layout product-grid col-md-3 col-sm-6 col-xs-6 four-items');
240		}
241		$('#content .product-grid .caption').removeClass('col-md-8 col-sm-8 col-sms-12');
242		$('#content .product-grid .image').removeClass('col-md-3 col-sm-4 col-sms-12');
243		
244
245		 localStorage.setItem('display', 'grid');
246	});
247
248	if (localStorage.getItem('display') == 'list') {
249		
250		$('#list-view').trigger('click');
251	} else {
252		$('#grid-view').trigger('click');
253	}
254	
255	// Product Grid
256	$('body').on('click', '.btn-grid', function() {
257		$('.custom-products').removeClass('custom-products-row');
258		$(this).addClass('selected');
259		$('.btn-list').removeClass('selected');
260		$('#content .custom-products .product-grid .caption').removeClass('col-md-8 col-sm-8 col-sms-12');
261		$('#content .custom-products .product-grid .images-container').removeClass('col-md-3 col-sm-4 col-sms-12');
262		
263
264		 localStorage.setItem('display', 'grid');
265	});
266
267	// Checkout
268	$(document).on('keydown', '#collapse-checkout-option input[name=\'email\'], #collapse-checkout-option input[name=\'password\']', function(e) {
269		if (e.keyCode == 13) {
270			$('#collapse-checkout-option #button-login').trigger('click');
271		}
272	});
273
274	// tooltips on hover
275	$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
276
277	// Makes tooltips work on ajax generated content
278	$(document).ajaxStop(function() {
279		$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
280	});
281	
282	/* vypnuty right-click*/
283	/*document.addEventListener('contextmenu', event => event.preventDefault());*/
284});
285
286// Cart add remove functions
287var cart = {
288	'add': function(product_id, quantity) {
289		$.ajax({
290			url: 'index.php?route=checkout/cart/add',
291			type: 'post',
292			data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
293			dataType: 'json',
294			beforeSend: function() {
295				$('#cart > button').button('loading');
296			},
297			complete: function() {
298				$('#cart > button').button('reset');
299			},
300			success: function(json) {
301				$('.alert-dismissible, .text-danger').remove();
302
303				if (json['redirect']) {
304					location = json['redirect'];
305				}
306
307				if (json['success']) {
308					$('body').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>');
309
310					// Need to set timeout otherwise it wont update the total
311					setTimeout(function () {
312						$('#cart > button').html('<i class="icon-basket-loaded icons"></i><span id="cart-total">' + json['total'] + '</span>');
313					}, 100);
314
315					$('html, body').animate({ scrollTop: 0 }, 'slow');
316
317					$('#cart > ul').load('index.php?route=common/cart/info ul li');
318				}
319			},
320			error: function(xhr, ajaxOptions, thrownError) {
321				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
322			}
323		});
324	},
325	'update': function(key, quantity) {
326		$.ajax({
327			url: 'index.php?route=checkout/cart/edit',
328			type: 'post',
329			data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
330			dataType: 'json',
331			beforeSend: function() {
332				$('#cart > button').button('loading');
333			},
334			complete: function() {
335				$('#cart > button').button('reset');
336			},
337			success: function(json) {
338				// Need to set timeout otherwise it wont update the total
339				setTimeout(function () {
340					$('#cart > button').html('<i class="icon-basket-loaded icons"></i><span id="cart-total">' + json['total'] + '</span>');
341				}, 100);
342
343				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
344					location = 'index.php?route=checkout/cart';
345				} else {
346					$('#cart > ul').load('index.php?route=common/cart/info ul li');
347				}
348			},
349			error: function(xhr, ajaxOptions, thrownError) {
350				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
351			}
352		});
353	},
354	'remove': function(key) {
355		$.ajax({
356			url: 'index.php?route=checkout/cart/remove',
357			type: 'post',
358			data: 'key=' + key,
359			dataType: 'json',
360			beforeSend: function() {
361				$('#cart > button').button('loading');
362			},
363			complete: function() {
364				$('#cart > button').button('reset');
365			},
366			success: function(json) {
367				// Need to set timeout otherwise it wont update the total
368				setTimeout(function () {
369					$('#cart > button').html('<i class="icon-basket-loaded icons"></i><span id="cart-total">' + json['total'] + '</span>');
370				}, 100);
371
372				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
373					location = 'index.php?route=checkout/cart';
374				} else {
375					$('#cart > ul').load('index.php?route=common/cart/info ul li');
376				}
377			},
378			error: function(xhr, ajaxOptions, thrownError) {
379				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
380			}
381		});
382	}
383}
384
385var voucher = {
386	'add': function() {
387
388	},
389	'remove': function(key) {
390		$.ajax({
391			url: 'index.php?route=checkout/cart/remove',
392			type: 'post',
393			data: 'key=' + key,
394			dataType: 'json',
395			beforeSend: function() {
396				$('#cart > button').button('loading');
397			},
398			complete: function() {
399				$('#cart > button').button('reset');
400			},
401			success: function(json) {
402				// Need to set timeout otherwise it wont update the total
403				setTimeout(function () {
404					$('#cart > button').html('<i class="icon-basket-loaded icons"></i><span id="cart-total">' + json['total'] + '</span>');
405				}, 100);
406
407				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
408					location = 'index.php?route=checkout/cart';
409				} else {
410					$('#cart > ul').load('index.php?route=common/cart/info ul li');
411				}
412			},
413			error: function(xhr, ajaxOptions, thrownError) {
414				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
415			}
416		});
417	}
418}
419
420var wishlist = {
421	'add': function(product_id) {
422		$.ajax({
423			url: 'index.php?route=account/wishlist/add',
424			type: 'post',
425			data: 'product_id=' + product_id,
426			dataType: 'json',
427			success: function(json) {
428				$('.alert-dismissible').remove();
429
430				if (json['redirect']) {
431					location = json['redirect'];
432				}
433
434				if (json['success']) {
435					$('body').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>');
436				}
437
438				$('#wishlist-total span').html(json['total']);
439				$('#wishlist-total').attr('title', json['total']);
440
441				$('html, body').animate({ scrollTop: 0 }, 'slow');
442			},
443			error: function(xhr, ajaxOptions, thrownError) {
444				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
445			}
446		});
447	},
448	'remove': function() {
449
450	}
451}
452
453var compare = {
454	'add': function(product_id) {
455		$.ajax({
456			url: 'index.php?route=product/compare/add',
457			type: 'post',
458			data: 'product_id=' + product_id,
459			dataType: 'json',
460			success: function(json) {
461				$('.alert-dismissible').remove();
462
463				if (json['success']) {
464					$('body').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>');
465
466					$('#compare-total').html(json['total']);
467
468					$('html, body').animate({ scrollTop: 0 }, 'slow');
469				}
470			},
471			error: function(xhr, ajaxOptions, thrownError) {
472				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
473			}
474		});
475	},
476	'remove': function() {
477
478	}
479}
480
481/* Agree to Terms */
482$(document).delegate('.agree', 'click', function(e) {
483	e.preventDefault();
484
485	$('#modal-agree').remove();
486
487	var element = this;
488
489	$.ajax({
490		url: $(element).attr('href'),
491		type: 'get',
492		dataType: 'html',
493		success: function(data) {
494			html  = '<div id="modal-agree" class="modal">';
495			html += '  <div class="modal-dialog">';
496			html += '    <div class="modal-content">';
497			html += '      <div class="modal-header">';
498			html += '        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
499			html += '        <h4 class="modal-title">' + $(element).text() + '</h4>';
500			html += '      </div>';
501			html += '      <div class="modal-body">' + data + '</div>';
502			html += '    </div>';
503			html += '  </div>';
504			html += '</div>';
505
506			$('body').append(html);
507
508			$('#modal-agree').modal('show');
509		}
510	});
511});
512
513// Autocomplete */
514(function($) {
515	$.fn.autocomplete = function(option) {
516		return this.each(function() {
517			this.timer = null;
518			this.items = new Array();
519
520			$.extend(this, option);
521
522			$(this).attr('autocomplete', 'off');
523
524			// Focus
525			$(this).on('focus', function() {
526				this.request();
527			});
528
529			// Blur
530			$(this).on('blur', function() {
531				setTimeout(function(object) {
532					object.hide();
533				}, 200, this);
534			});
535
536			// Keydown
537			$(this).on('keydown', function(event) {
538				switch(event.keyCode) {
539					case 27: // escape
540						this.hide();
541						break;
542					default:
543						this.request();
544						break;
545				}
546			});
547
548			// Click
549			this.click = function(event) {
550				event.preventDefault();
551
552				value = $(event.target).parent().attr('data-value');
553
554				if (value && this.items[value]) {
555					this.select(this.items[value]);
556				}
557			}
558
559			// Show
560			this.show = function() {
561				var pos = $(this).position();
562
563				$(this).siblings('ul.dropdown-menu').css({
564					top: pos.top + $(this).outerHeight(),
565					left: pos.left
566				});
567
568				$(this).siblings('ul.dropdown-menu').show();
569			}
570
571			// Hide
572			this.hide = function() {
573				$(this).siblings('ul.dropdown-menu').hide();
574			}
575
576			// Request
577			this.request = function() {
578				clearTimeout(this.timer);
579
580				this.timer = setTimeout(function(object) {
581					object.source($(object).val(), $.proxy(object.response, object));
582				}, 200, this);
583			}
584
585			// Response
586			this.response = function(json) {
587				html = '';
588
589				if (json.length) {
590					for (i = 0; i < json.length; i++) {
591						this.items[json[i]['value']] = json[i];
592					}
593
594					for (i = 0; i < json.length; i++) {
595						if (!json[i]['category']) {
596							html += '<li data-value="' + json[i]['value'] + '"><a href="#">' + json[i]['label'] + '</a></li>';
597						}
598					}
599
600					// Get all the ones with a categories
601					var category = new Array();
602
603					for (i = 0; i < json.length; i++) {
604						if (json[i]['category']) {
605							if (!category[json[i]['category']]) {
606								category[json[i]['category']] = new Array();
607								category[json[i]['category']]['name'] = json[i]['category'];
608								category[json[i]['category']]['item'] = new Array();
609							}
610
611							category[json[i]['category']]['item'].push(json[i]);
612						}
613					}
614
615					for (i in category) {
616						html += '<li class="dropdown-header">' + category[i]['name'] + '</li>';
617
618						for (j = 0; j < category[i]['item'].length; j++) {
619							html += '<li data-value="' + category[i]['item'][j]['value'] + '"><a href="#">&nbsp;&nbsp;&nbsp;' + category[i]['item'][j]['label'] + '</a></li>';
620						}
621					}
622				}
623
624				if (html) {
625					this.show();
626				} else {
627					this.hide();
628				}
629
630				$(this).siblings('ul.dropdown-menu').html(html);
631			}
632
633			$(this).after('<ul class="dropdown-menu"></ul>');
634			$(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this));
635
636		});
637	}
638})(window.jQuery);
639

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.