PageSourceSearch

https://lojadaseguranca.pt/catalog/view/theme/journal3/js/common.js

js lojadaseguranca.pt collected 2026-10-06 07:21:35 UTC 17,269 bytes, 567 lines download raw bytes

1// Array includes polyfill
2if (!Array.prototype.includes) {
3	Object.defineProperty(Array.prototype, 'includes', {
4		value: function (searchElement, fromIndex) {
5
6			if (this == null) {
7				throw new TypeError('"this" is null or not defined');
8			}
9
10			// 1. Let O be ? ToObject(this value).
11			var o = Object(this);
12
13			// 2. Let len be ? ToLength(? Get(O, "length")).
14			var len = o.length >>> 0;
15
16			// 3. If len is 0, return false.
17			if (len === 0) {
18				return false;
19			}
20
21			// 4. Let n be ? ToInteger(fromIndex).
22			//    (If fromIndex is undefined, this step produces the value 0.)
23			var n = fromIndex | 0;
24
25			// 5. If n ≥ 0, then
26			//  a. Let k be n.
27			// 6. Else n < 0,
28			//  a. Let k be len + n.
29			//  b. If k < 0, let k be 0.
30			var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
31
32			function sameValueZero(x, y) {
33				return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
34			}
35
36			// 7. Repeat, while k < len
37			while (k < len) {
38				// a. Let elementK be the result of ? Get(O, ! ToString(k)).
39				// b. If SameValueZero(searchElement, elementK) is true, return true.
40				if (sameValueZero(o[k], searchElement)) {
41					return true;
42				}
43				// c. Increase k by 1.
44				k++;
45			}
46
47			// 8. Return false
48			return false;
49		}
50	});
51}
52
53$(function () {
54	// Currency
55	$('#form-currency .currency-select').unbind().on('click', function (e) {
56		e.preventDefault();
57
58		$('#form-currency input[name=\'code\']').val($(this).data('name'));
59
60		$('#form-currency').submit();
61	});
62
63	// Language
64	$('#form-language .language-select').unbind().on('click', function (e) {
65		e.preventDefault();
66
67		$('#form-language input[name=\'code\']').val($(this).data('name'));
68
69		$('#form-language').submit();
70	});
71});
72
73window['cart'] = window['cart'] || {};
74
75window['cart'].add = function (product_id, quantity, quick_buy) {
76	quantity = quantity || 1;
77
78	$.ajax({
79		url: 'index.php?route=checkout/cart/add',
80		type: 'post',
81		data: 'product_id=' + product_id + '&quantity=' + quantity,
82		dataType: 'json',
83		beforeSend: function () {
84			$('[data-toggle="tooltip"]').tooltip('hide');
85			$('[onclick*="cart.add(\'' + product_id + '\'"]').button('loading');
86		},
87		complete: function () {
88			$('[onclick*="cart.add(\'' + product_id + '\'"]').button('reset');
89		},
90		success: function (json) {
91			$('.alert, .text-danger').remove();
92
93			if (json['redirect']) {
94				if (json['options_popup']) {
95					if ($('html').hasClass('iphone') || $('html').hasClass('ipad')) {
96						iNoBounce.enable();
97					}
98
99					var html = '';
100
101					html += '<div class="popup-wrapper popup-options">';
102					html += '	<div class="popup-container">';
103					html += '		<button class="btn popup-close"></button>';
104					html += '		<div class="popup-body">';
105					html += '		<div class="popup-inner-body">';
106					html += '			<div class="journal-loading"><i class="fa fa-spinner fa-spin"></i></div>';
107					html += '			<iframe src="index.php?route=journal3/product&product_id=' + product_id + '&popup=options&product_quantity=' + quantity + '&' + (quick_buy ? 'quick_buy=true' : '') + '" width="100%" height="100%" frameborder="0" onload="this.height = this.contentWindow.document.body.offsetHeight; $(this).prev(\'.journal-loading\').fadeOut();"></iframe>';
108					html += '		</div>';
109					html += '		</div>';
110					html += '	</div>';
111					html += '	<div class="popup-bg popup-bg-closable"></div>';
112					html += '</div>';
113
114					// show modal
115					$('.popup-wrapper').remove();
116
117					$('body').append(html);
118
119					setTimeout(function () {
120						$('html').addClass('popup-open popup-center');
121					}, 10);
122				} else {
123					location = json['redirect'];
124				}
125			}
126
127			if (json['success']) {
128				if (json['options_popup']) {
129					if ($('html').hasClass('iphone') || $('html').hasClass('ipad')) {
130						iNoBounce.enable();
131					}
132
133					var html = '';
134
135					html += '<div class="popup-wrapper popup-options">';
136					html += '	<div class="popup-container">';
137					html += '		<button class="btn popup-close"></button>';
138					html += '		<div class="popup-body">';
139					html += '		<div class="popup-inner-body">';
140					html += '			<div class="journal-loading"><i class="fa fa-spinner fa-spin"></i></div>';
141					html += '			<iframe src="index.php?route=journal3/product&product_id=' + product_id + '&popup=options&' + (quick_buy ? 'quick_buy=true' : '') + '" width="100%" height="100%" frameborder="0" onload="this.height = this.contentWindow.document.body.offsetHeight; $(this).prev(\'.journal-loading\').fadeOut();"></iframe>';
142					html += '		</div>';
143					html += '		</div>';
144					html += '	</div>';
145					html += '	<div class="popup-bg popup-bg-closable"></div>';
146					html += '</div>';
147
148					// show modal
149					$('.popup-wrapper').remove();
150
151					$('body').append(html);
152
153					setTimeout(function () {
154						$('html').addClass('popup-open popup-center');
155					}, 10);
156				} else {
157					if (json['notification']) {
158						show_notification(json['notification']);
159
160						if (quick_buy) {
161							location = Journal['checkoutUrl'];
162						}
163					} else {
164						$('header').after('<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				}
167
168				// Need to set timeout otherwise it wont update the total
169				setTimeout(function () {
170					$('#cart-total').html(json['total']);
171					$('#cart-items,.cart-badge').html(json['items_count']);
172
173					if (json['items_count']) {
174						$('#cart-items,.cart-badge').removeClass('count-zero');
175					} else {
176						$('#cart-items,.cart-badge').addClass('count-zero');
177					}
178				}, 100);
179
180				if (Journal['scrollToTop']) {
181					$('html, body').animate({ scrollTop: 0 }, 'slow');
182				}
183
184				$('.cart-content ul').load('index.php?route=common/cart/info ul li');
185
186				if (parent.window['_QuickCheckout']) {
187					parent.window['_QuickCheckout'].save();
188				}
189			}
190		},
191		error: function (xhr, ajaxOptions, thrownError) {
192			alert(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
193		}
194	});
195};
196
197window['cart'].remove = function (key) {
198	$.ajax({
199		url: 'index.php?route=checkout/cart/remove',
200		type: 'post',
201		data: 'key=' + key,
202		dataType: 'json',
203		beforeSend: function () {
204			$('#cart > button').button('loading');
205		},
206		complete: function () {
207			$('#cart > button').button('reset');
208		},
209		success: function (json) {
210			// Need to set timeout otherwise it wont update the total
211			setTimeout(function () {
212				$('#cart-total').html(json['total']);
213				$('#cart-items,.cart-badge').html(json['items_count']);
214
215				if (json['items_count']) {
216					$('#cart-items,.cart-badge').removeClass('count-zero');
217				} else {
218					$('#cart-items,.cart-badge').addClass('count-zero');
219				}
220			}, 100);
221
222			if ($('html').hasClass('route-checkout-cart') || $('html').hasClass('route-checkout-checkout')) {
223				location = 'index.php?route=checkout/cart';
224			} else {
225				$('.cart-content ul').load('index.php?route=common/cart/info ul li');
226			}
227		},
228		error: function (xhr, ajaxOptions, thrownError) {
229			alert(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
230		}
231	});
232};
233
234window['cart'].update = function (key, quantity) {
235	$.ajax({
236		url: 'index.php?route=checkout/cart/edit',
237		type: 'post',
238		data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
239		dataType: 'json',
240		beforeSend: function () {
241			$('#cart > button').button('loading');
242		},
243		complete: function () {
244			$('#cart > button').button('reset');
245		},
246		success: function (json) {
247			// Need to set timeout otherwise it wont update the total
248			setTimeout(function () {
249				$('#cart-total').html(json['total']);
250				$('#cart-items,.cart-badge').html(json['items_count']);
251
252				if (json['items_count']) {
253					$('#cart-items,.cart-badge').removeClass('count-zero');
254				} else {
255					$('#cart-items,.cart-badge').addClass('count-zero');
256				}
257			}, 100);
258
259			if ($('html').hasClass('route-checkout-cart') || $('html').hasClass('route-checkout-checkout')) {
260				location = 'index.php?route=checkout/cart';
261			} else {
262				$('.cart-content ul').load('index.php?route=common/cart/info ul li');
263			}
264		},
265		error: function (xhr, ajaxOptions, thrownError) {
266			alert(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
267		}
268	});
269};
270
271window['wishlist'] = window['wishlist'] || {};
272
273window['wishlist'].add = function (product_id) {
274	$.ajax({
275		url: 'index.php?route=account/wishlist/add',
276		type: 'post',
277		data: 'product_id=' + product_id,
278		dataType: 'json',
279		success: function (json) {
280			$('.alert').remove();
281
282			if (json['redirect']) {
283				location = json['redirect'];
284			}
285
286			if (json['success']) {
287				$('[data-toggle="tooltip"]').tooltip('hide');
288
289				if (json['notification']) {
290					show_notification(json['notification']);
291				} else {
292					$('header').after('<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>');
293				}
294			}
295
296			$('#wishlist-total span').html(json['total']);
297			$('#wishlist-total').attr('title', json['total']);
298			$('.wishlist-badge').text(json['count']);
299
300			if (json['count']) {
301				$('.wishlist-badge').removeClass('count-zero');
302			} else {
303				$('.wishlist-badge').addClass('count-zero');
304			}
305
306			if (Journal['scrollToTop']) {
307				$('html, body').animate({ scrollTop: 0 }, 'slow');
308			}
309		},
310		error: function (xhr, ajaxOptions, thrownError) {
311			alert(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
312		}
313	});
314};
315
316window['compare'] = window['compare'] || {};
317
318window['compare'].add = function (product_id) {
319	$.ajax({
320		url: 'index.php?route=product/compare/add',
321		type: 'post',
322		data: 'product_id=' + product_id,
323		dataType: 'json',
324		success: function (json) {
325			$('.alert').remove();
326
327			if (json['success']) {
328				$('[data-toggle="tooltip"]').tooltip('hide');
329
330				if (json['notification']) {
331					show_notification(json['notification']);
332				} else {
333					$('header').after('<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>');
334				}
335
336				$('#compare-total').html(json['total']);
337				$('.compare-badge').text(json['count']);
338
339				if (json['count']) {
340					$('.compare-badge').removeClass('count-zero');
341				} else {
342					$('.compare-badge').addClass('count-zero');
343				}
344
345				if (Journal['scrollToTop']) {
346					$('html, body').animate({ scrollTop: 0 }, 'slow');
347				}
348			}
349		},
350		error: function (xhr, ajaxOptions, thrownError) {
351			alert(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
352		}
353	});
354};
355
356window['quickview'] = function (product_id) {
357	product_id = parseInt(product_id, 10);
358
359	// hide tooltip
360	$('[data-toggle="tooltip"]').tooltip('hide');
361
362	var html = '';
363
364	html += '<div class="popup-wrapper popup-quickview">';
365	html += '	<div class="popup-container">';
366	html += '		<button class="btn popup-close"></button>';
367	html += '		<div class="popup-body">';
368	html += '			<div class="popup-inner-body">';
369	html += '				<div class="journal-loading"><i class="fa fa-spinner fa-spin"></i></div>';
370	html += '				<iframe src="index.php?route=journal3/product&product_id=' + product_id + '&popup=quickview" width="100%" height="100%" frameborder="0" onload="this.height = this.contentWindow.document.body.offsetHeight; $(this).prev(\'.journal-loading\').hide();"></iframe>';
371	html += '			</div>';
372	html += '		</div>';
373	html += '	</div>';
374	html += '	<div class="popup-bg popup-bg-closable"></div>';
375	html += '</div>';
376
377	// show modal
378	$('.popup-wrapper').remove();
379
380	$('body').append(html);
381
382	setTimeout(function () {
383		$('html').addClass('popup-open popup-center');
384	}, 10);
385};
386
387window['open_popup'] = function (module_id) {
388	if ($('html').hasClass('iphone') || $('html').hasClass('ipad')) {
389		iNoBounce.enable();
390	}
391
392	module_id = parseInt(module_id, 10);
393
394	var html = '';
395
396	html += '<div class="popup-wrapper popup-module">';
397	html += '	<div class="popup-container">';
398	html += '		<button class="btn popup-close"></button>';
399	html += '		<div class="popup-body">';
400	html += '		<div class="popup-inner-body">';
401	html += '		</div>';
402	html += '		</div>';
403	html += '	</div>';
404	html += '	<div class="popup-bg popup-bg-closable"></div>';
405	html += '</div>';
406
407	// show modal
408	$('.popup-wrapper').remove();
409
410	$('body').append(html);
411
412	setTimeout(function () {
413		$('html').addClass('popup-open popup-center');
414	}, 10);
415
416	$('.popup-container').css('visibility', 'hidden');
417
418	$.ajax({
419		url: 'index.php?route=journal3/popup/get&module_id=' + module_id + '&popup=module',
420		success: function (html) {
421			var $html = $(html);
422			var $popup = $html.siblings('.module-popup');
423			var $style = $html.siblings('style');
424			var $content = $popup.find('.popup-container');
425
426			$('#popup-style-' + module_id).remove();
427			$('head').append($style.attr('id', 'popup-style-' + module_id));
428			$('.popup-wrapper').attr('class', $popup.attr('class'));
429			$('.popup-container').html($content.html());
430
431			$('.popup-container').css('visibility', 'visible');
432		},
433		error: function (xhr, ajaxOptions, thrownError) {
434			alert(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
435		}
436	});
437};
438
439window['open_login_popup'] = function () {
440	if ($('html').hasClass('iphone') || $('html').hasClass('ipad')) {
441		iNoBounce.enable();
442	}
443
444	var html = '';
445
446	html += '<div class="popup-wrapper popup-login">';
447	html += '	<div class="popup-container">';
448	html += '		<button class="btn popup-close"></button>';
449	html += '		<div class="popup-body">';
450	html += '		<div class="popup-inner-body">';
451	html += '			<div class="journal-loading"><i class="fa fa-spinner fa-spin"></i></div>';
452	html += '			<iframe src="index.php?route=account/login&popup=login" width="100%" height="100%" frameborder="0" onload="this.height = this.contentWindow.document.body.offsetHeight; $(this).prev(\'.journal-loading\').fadeOut();"></iframe>';
453	html += '		</div>';
454	html += '		</div>';
455	html += '	</div>';
456	html += '	<div class="popup-bg popup-bg-closable"></div>';
457	html += '</div>';
458
459	// show modal
460	$('.popup-wrapper').remove();
461
462	$('body').append(html);
463
464	setTimeout(function () {
465		$('html').addClass('popup-open popup-center');
466	}, 10);
467};
468
469window['open_register_popup'] = function () {
470	if ($('html').hasClass('iphone') || $('html').hasClass('ipad')) {
471		iNoBounce.enable();
472	}
473
474	var html = '';
475
476	html += '<div class="popup-wrapper popup-register">';
477	html += '	<div class="popup-container">';
478	html += '		<button class="btn popup-close"></button>';
479	html += '		<div class="popup-body">';
480	html += '		<div class="popup-inner-body">';
481	html += '			<div class="journal-loading"><i class="fa fa-spinner fa-spin"></i></div>';
482	html += '			<iframe src="index.php?route=account/register&popup=register" width="100%" height="100%" frameborder="0" onload="this.height = this.contentWindow.document.body.offsetHeight; $(this).prev(\'.journal-loading\').fadeOut();"></iframe>';
483	html += '		</div>';
484	html += '		</div>';
485	html += '	</div>';
486	html += '	<div class="popup-bg popup-bg-closable"></div>';
487	html += '</div>';
488
489	// show modal
490	$('.popup-wrapper').remove();
491
492	$('body').append(html);
493
494	setTimeout(function () {
495		$('html').addClass('popup-open popup-center');
496	}, 10);
497};
498
499window['show_notification'] = function (opts) {
500	opts = $.extend({
501		position: 'center',
502		className: '',
503		title: '',
504		image: '',
505		message: '',
506		buttons: [],
507		timeout: Journal.notificationHideAfter
508	}, opts);
509
510	if ($('.notification-wrapper-' + opts.position).length === 0) {
511		$('body').append('<div class="notification-wrapper notification-wrapper-' + opts.position + '"></div>');
512	}
513
514	var html = '';
515
516	var buttons = $.map(opts.buttons, function (button) {
517		return '<a class="' + button.className + '" href="' + button.href + '">' + button.name + '</a>';
518	});
519
520	html += '<div class="notification ' + opts.className + '">';
521	html += '	<button class="btn notification-close"></button>';
522	html += '	<div class="notification-content">';
523
524	if (opts.image) {
525		html += '		<img src="' + opts.image + '" srcset="' + opts.image + ' 1x, ' + opts.image2x + ' 2x">';
526	}
527
528	html += '		<div>';
529	html += '			<div class="notification-title">' + opts.title + '</div>';
530	html += '			<div class="notification-text">' + opts.message + '</div>';
531	html += '		</div>';
532	html += '	</div>';
533
534	if (buttons && buttons.length) {
535		html += '<div class="notification-buttons">' + buttons.join('\n') + '</div>';
536	}
537
538	html += '</div>';
539
540	var $notification = $(html);
541
542	$('.notification-wrapper-' + opts.position).append($notification);
543
544	if (opts.timeout) {
545		setTimeout(function () {
546			$notification.find('.notification-close').trigger('click');
547		}, opts.timeout);
548	}
549
550	return $notification;
551};
552
553window['loader'] = function (el, status) {
554	var $el = $(el);
555
556	if (status) {
557		$el.attr('style', 'position: relative');
558		$el.append('<div class="journal-loading-overlay"><div class="journal-loading"><i class="fa fa-spinner fa-spin"></i></div></div>');
559	} else {
560		$el.attr('style', '');
561		$el.find('.journal-loading-overlay').remove();
562	}
563};
564
565window['resize_iframe'] = function (module_id, height) {
566	$('.module-popup-' + module_id + ' iframe').height(height);
567};

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.