PageSourceSearch

https://www.zamnesia.com/js/tools.js?_=560f8f09da050aa5b6497d2740097f16

js zamnesia.com collected 2026-09-24 18:31:37 UTC 14,473 bytes, 523 lines download raw bytes

1/*
2* 2007-2011 PrestaShop
3*
4* NOTICE OF LICENSE
5*
6* This source file is subject to the Open Software License (OSL 3.0)
7* that is bundled with this package in the file LICENSE.txt.
8* It is also available through the world-wide-web at this URL:
9* http://opensource.org/licenses/osl-3.0.php
10* If you did not receive a copy of the license and are unable to
11* obtain it through the world-wide-web, please send an email
12* to [email protected] so we can send you a copy immediately.
13*
14* DISCLAIMER
15*
16* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
17* versions in the future. If you wish to customize PrestaShop for your
18* needs please refer to http://www.prestashop.com for more information.
19*
20*  @author PrestaShop SA <[email protected]>
21*  @copyright  2007-2011 PrestaShop SA
22*  @version  Release: $Revision: 7014 $
23*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
24*  International Registered Trademark & Property of PrestaShop SA
25*/
26
27function ps_round(value, precision)
28{
29	if (typeof(roundMode) == 'undefined')
30		roundMode = 2;
31	if (typeof(precision) == 'undefined')
32		precision = 2;
33
34	method = roundMode;
35	if (method == 0)
36		return ceilf(value, precision);
37	else if (method == 1)
38		return floorf(value, precision);
39	precisionFactor = precision == 0 ? 1 : Math.pow(10, precision);
40	return Math.round(value * precisionFactor) / precisionFactor;
41}
42
43function	autoUrl(name, dest)
44{
45	var loc;
46	var id_list;
47
48	id_list = document.getElementById(name);
49	loc = id_list.options[id_list.selectedIndex].value;
50	if (loc != 0)
51		location.href = dest+loc;
52	return ;
53}
54
55function	autoUrlNoList(name, dest)
56{
57	var loc;
58
59	loc = document.getElementById(name).checked;
60	location.href = dest + (loc == true ? 1 : 0);
61	return ;
62}
63
64/*
65** show or hide element e depending on condition show
66*/
67function toggle(e, show)
68{
69	e.style.display = show ? '' : 'none';
70}
71
72function toggleMultiple(tab)
73{
74	var len = tab.length;
75
76	for (var i = 0; i < len; i++)
77		if (tab[i].style)
78			toggle(tab[i], tab[i].style.display == 'none');
79}
80
81/**
82* Show dynamicaly an element by changing the sytle "display" property
83* depending on the option selected in a select.
84*
85* @param string $select_id id of the select who controls the display
86* @param string $elem_id prefix id of the elements controlled by the select
87*   the real id must be : 'elem_id'+nb with nb the corresponding number in the
88*   select (starting with 0).
89*/
90function showElemFromSelect(select_id, elem_id)
91{
92	var select = document.getElementById(select_id);
93	for (var i = 0; i < select.length; ++i)
94	{
95		var elem = document.getElementById(elem_id + select.options[i].value);
96		if (elem != null)
97			toggle(elem, i == select.selectedIndex);
98	}
99}
100
101/**
102* Get all div with specified name and for each one (by id), toggle their visibility
103*/
104function openCloseAllDiv(name, option)
105{
106	var tab = $('*[name='+name+']');
107	for (var i = 0; i < tab.length; ++i)
108		toggle(tab[i], option);
109}
110
111/**
112* Toggle the value of the element id_button between text1 and text2
113*/
114function toggleElemValue(id_button, text1, text2)
115{
116	var obj = document.getElementById(id_button);
117	if (obj)
118		obj.value = ((!obj.value || obj.value == text2) ? text1 : text2);
119}
120
121function addBookmark(url, title)
122{
123	if (window.sidebar)
124		return window.sidebar.addPanel(title, url, "");
125	else if ( window.external )
126		return window.external.AddFavorite( url, title);
127	else if (window.opera && window.print)
128		return true;
129	return true;
130}
131
132function writeBookmarkLink(url, title, text, img)
133{
134	var insert = '';
135	if (img)
136		insert = writeBookmarkLinkObject(url, title, '<img src="' + img + '" alt="' + escape(text) + '" title="' + escape(text) + '" />') + '&nbsp';
137	insert += writeBookmarkLinkObject(url, title, text);
138	document.write(insert);
139}
140
141function writeBookmarkLinkObject(url, title, insert)
142{
143	if (window.navigator.userAgent.indexOf('Chrome') != -1)
144		return ('');
145	else if (window.sidebar || window.external)
146		return ('<a href="javascript:addBookmark(\'' + escape(url) + '\', \'' + escape(title) + '\')">' + insert + '</a>');
147	else if (window.opera && window.print)
148		return ('<a rel="sidebar" href="' + escape(url) + '" title="' + escape(title) + '">' + insert + '</a>');
149	return ('');
150}
151
152function checkCustomizations()
153{
154	var pattern = new RegExp(' ?filled ?');
155
156	if (typeof customizationFields != 'undefined')
157		for (var i = 0; i < customizationFields.length; i++)
158			/* If the field is required and empty then we abort */
159			if (parseInt(customizationFields[i][1]) == 1 && ($('#' + customizationFields[i][0]).html() == '' ||  $('#' + customizationFields[i][0]).html() != $('#' + customizationFields[i][0]).val()) && !pattern.test($('#' + customizationFields[i][0]).attr('class')))
160				return false;
161	return true;
162}
163
164function emptyCustomizations()
165{
166	if(typeof(customizationFields) == 'undefined') return;
167
168	for (var i = 0; i < customizationFields.length; i++)
169	{
170		$('#' + customizationFields[i][0]).html('');
171		$('#' + customizationFields[i][0]).val('');
172	}
173}
174
175function ceilf(value, precision)
176{
177	if (typeof(precision) == 'undefined')
178		precision = 0;
179	var precisionFactor = precision == 0 ? 1 : Math.pow(10, precision);
180	var tmp = value * precisionFactor;
181	var tmp2 = tmp.toString();
182	// If the current value has already the desired precision
183	if (tmp2.indexOf('.') === false)
184		return (value);
185	if (tmp2.charAt(tmp2.length - 1) == 0)
186		return value;
187	return Math.ceil(tmp) / precisionFactor;
188}
189
190function floorf(value, precision)
191{
192	if (typeof(precision) == 'undefined')
193		precision = 0;
194	var precisionFactor = precision == 0 ? 1 : Math.pow(10, precision);
195	var tmp = value * precisionFactor;
196	var tmp2 = tmp.toString();
197	// If the current value has already the desired precision
198	if (tmp2.indexOf('.') === false)
199		return (value);
200	if (tmp2.charAt(tmp2.length - 1) == 0)
201		return value;
202	return Math.floor(tmp) / precisionFactor;
203}
204
205function setCurrency(id_currency)
206{
207	$.ajax({
208		type: 'POST',
209		url: baseDir + 'changecurrency.php',
210		data: 'id_currency='+parseInt(id_currency),
211		success: function(msg)
212		{
213			location.reload(true);
214		}
215	});
216}
217
218function isArrowKey(k_ev)
219{
220	var unicode=k_ev.keyCode? k_ev.keyCode : k_ev.charCode;
221	if (unicode >= 37 && unicode <= 40)
222		return true;
223
224}
225
226function readCookie(name) {
227	var nameEQ = name + "=";
228	var ca = document.cookie.split(';');
229	for(var i=0;i < ca.length;i++) {
230		var c = ca[i];
231		while (c.charAt(0)===' ') {
232			c = c.substring(1,c.length);
233		}
234
235		if (c.indexOf(nameEQ) === 0) {
236		  return c.substring(nameEQ.length,c.length);
237		}
238	}
239
240	return '';
241}
242
243function setCookie(cname, cvalue, exdays) {
244	var d = new Date();
245	d.setTime(d.getTime() + (exdays*24*60*60*1000));
246	var expires = "expires="+d.toGMTString();
247	document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
248}
249
250//On dom ready
251$().ready(function()
252{
253	// Hide all elements with .hideOnSubmit class when parent form is submit
254	$('form').submit(function()
255	{
256		$(this).find('.hideOnSubmit').hide();
257	});
258
259	$('.pagination_duplicate').change(function () {
260		$("select[name=pagination] option[value='" + $(this).val() + "']").attr('selected', true);
261	})
262});
263
264String.prototype.capitalize = function(){
265	return this.toLowerCase().replace(/(^|\s|¿|\(|\'|\")[a-z\u00E0-\u00FC]/g, function(l){ return l.toUpperCase() });
266};
267
268String.fromHtmlEntities = function(string) {
269	return (string+"").replace(/&#\d+;/gm,function(s) {
270		return String.fromCharCode(s.match(/\d+/gm)[0]);
271	})
272};
273
274function getUrlParam(name, url) {
275	if (!url) url = window.location.href;
276	name = name.replace(/[\[\]]/g, '\\$&');
277	var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
278		results = regex.exec(url);
279	if (!results) return null;
280	if (!results[2]) return '';
281	return decodeURIComponent(results[2].replace(/\+/g, ' '));
282}
283
284//return a formatted price
285function formatCurrency(price, currencyFormat, currencySign, currencyBlank)
286{
287	// if you modified this function, don't forget to modify the PHP function displayPrice (in the Tools.php class)
288	blank = '';
289	price = parseFloat(price).toFixed(6);
290	price = ps_round(price, priceDisplayPrecision);
291	if (currencyBlank > 0)
292		blank = ' ';
293	if (currencyFormat == 1)
294		price = currencySign + blank + formatNumber(price, priceDisplayPrecision, ',', '.');
295	if (currencyFormat == 2)
296		price = (formatNumber(price, priceDisplayPrecision, ' ', ',') + blank + currencySign);
297	if (currencyFormat == 3)
298		price = (currencySign + blank + formatNumber(price, priceDisplayPrecision, '.', ','));
299	if (currencyFormat == 4)
300		price = (formatNumber(price, priceDisplayPrecision, ',', '.') + blank + currencySign);
301	if (currencyFormat == 5)
302		price = (formatNumber(price, priceDisplayPrecision, '.', ',') + blank + currencySign);
303	if (currencyFormat == 6)
304		price = (formatNumber(price, priceDisplayPrecision, '', ',') + blank + currencySign);
305	return wrapPriceInHtml(price);
306}
307
308function wrapPriceInHtml(priceStr) {
309	// Remove excess whitespaces
310	priceStr = priceStr.trim();
311
312	// Find number with possible separators
313	const numberRegex = /(\d[\d.,]*)/;
314	const numMatch = priceStr.match(numberRegex);
315
316	if (!numMatch) return priceStr; // No nunber - return as it is
317
318	const fullNumber = numMatch[1];
319
320	// Detect separator
321	let decimalSeparator = null;
322
323	if (fullNumber.includes(",") && fullNumber.includes(".")) {
324		// Both present - last symbol is decimal
325		decimalSeparator = (fullNumber.lastIndexOf(",") > fullNumber.lastIndexOf(".")) ? "," : ".";
326	} else if (fullNumber.includes(",")) {
327		decimalSeparator = ",";
328	} else if (fullNumber.includes(".")) {
329		decimalSeparator = ".";
330	}
331
332	let integer = fullNumber;
333	let fractional = "";
334
335	if (decimalSeparator) {
336		const parts = fullNumber.split(decimalSeparator);
337		integer = parts[0];
338		fractional = parts[1] || "";
339	}
340
341	// Detect place of currency - before or after number
342	const before = priceStr.slice(0, numMatch.index);
343	const after = priceStr.slice(numMatch.index + fullNumber.length);
344
345	const currencySign = (before + after).trim(); // whole currency and numbers beyond price
346
347	let html = "";
348
349	if (before.trim()) {
350		// Currency before number
351		html += `<span class="currency_sign">${before}</span>`;
352	}
353
354	html += `<span class="integer_part_of_price">${integer}${fractional ? decimalSeparator : ""}</span>`;
355
356	if (fractional) {
357		html += `<span class="fractial_part_of_price">${fractional}</span>`;
358	}
359
360	if (after.trim() && !before.trim()) {
361		// Currency after number
362		html += `<span class="currency_sign">${after}</span>`;
363	}
364
365	return html;
366}
367
368//return a formatted number
369function formatNumber(value, numberOfDecimal, thousenSeparator, virgule)
370{
371	value = parseFloat(value).toFixed(numberOfDecimal);
372	var val_string = value+'';
373	var tmp = val_string.split('.');
374	var abs_val_string = (tmp.length == 2) ? tmp[0] : val_string;
375	var deci_string = ('0.' + (tmp.length == 2 ? tmp[1] : 0)).substr(2);
376	var nb = abs_val_string.length;
377
378	for (var i = 1 ; i < 4; i++)
379		if (value >= Math.pow(10, (3 * i)))
380			abs_val_string = abs_val_string.substring(0, nb - (3 * i)) + thousenSeparator + abs_val_string.substring(nb - (3 * i));
381
382	if (parseInt(numberOfDecimal) == 0)
383		return abs_val_string;
384	return abs_val_string + virgule + (deci_string > 0 ? deci_string : '00');
385}
386
387//verify if value is in the array
388function in_array(value, array)
389{
390	for (var i in array)
391		if (array[i] == value)
392			return true;
393	return false;
394}
395
396function resizeAddressesBox(nameBox)
397{
398	maxHeight = 0;
399
400	if (typeof(nameBox) == 'undefined') {
401		nameBox = '.addresses .address';
402	}
403	$(nameBox).each(function() {
404		$(this).css('height', 'auto');
405		currentHeight = $(this).height();
406		if (maxHeight < currentHeight) {
407			maxHeight = currentHeight;
408		}
409	});
410	$(nameBox).height(maxHeight);
411}
412
413function resizeFancybox() {
414	var $fwrap = $('#fancybox-wrap');
415	var modal = $fwrap.find('.popup-content').first();
416	if (!modal.width()) {
417		return;
418	}
419
420	var maxWidth = parseInt(modal.data('max-width')) || 450;
421	var outerPadding = parseInt(modal.data('padding')) || 0;
422	var outerMargin = parseInt(modal.data('margin')) || 20;
423	var minDiff = outerPadding * 2 + outerMargin * 2;
424	var width = modal.width();
425	var availableWidth = $(window).width() - minDiff;
426
427	var newWidth = 0;
428	//window collapse
429	if (availableWidth < width) {
430		newWidth = availableWidth;
431	}
432	//window expand
433	else if (availableWidth > width && width != maxWidth) {
434		if (availableWidth > maxWidth) {
435			newWidth = maxWidth;
436		}
437		else {
438			newWidth = availableWidth;
439		}
440	}
441
442	newWidth = newWidth || width;
443	modal.width(newWidth);
444	$('#fancybox-content').width(newWidth);
445  $('#fancybox-content').find('.popup-content').css('width', newWidth);
446	$fwrap.width(newWidth + outerPadding * 2);
447
448	$fwrap.stop()
449		.animate({
450			'left' : (($(window).width() - $fwrap.outerWidth()) / 2)
451		}, 160);
452	//$fwrap.css('left', (($(window).width() - $fwrap.outerWidth()) / 2) + 'px');
453	//$.fancybox.center();
454}
455
456jQuery.browser = {};
457(function () {
458    jQuery.browser.msie = false;
459    jQuery.browser.version = 0;
460    if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
461        jQuery.browser.msie = true;
462        jQuery.browser.version = RegExp.$1;
463    }
464})();
465//jQuery.fn.extend({
466//    live: function (event, callback) {
467//       if (this.selector) {
468//            jQuery(document).on(event, this.selector, callback);
469//        }
470//        return this;
471//    }
472//});
473jQuery.fn.equalHeights = function () {
474	var maxHeight = 0,
475		self      = jQuery(this);
476		self.css('height', '');
477	self.each(function () {
478		var height = jQuery(this).innerHeight();
479		if (height > maxHeight) {
480			maxHeight = height;
481		}
482	});
483	return self.css('height', maxHeight);
484};
485
486function copyStringToClipboard(str) {
487	// Create new element
488	var el = document.createElement('textarea');
489	// Set value (string to be copied)
490	el.value = str;
491	// Set non-editable to avoid focus and move outside of view
492	el.setAttribute('readonly', '');
493	el.style = {position: 'absolute', left: '-9999px'};
494	document.body.appendChild(el);
495	// Select text inside element
496	el.select();
497	// Copy text to clipboard
498	document.execCommand('copy');
499	// Remove temporary element
500	document.body.removeChild(el);
501}
502
503function waitForVisibleElement(selector, callback, timeout = 5000) {
504	const start = Date.now();
505
506	function check() {
507		const $el = $(selector + ':visible');
508
509		if ($el.length) {
510			callback($el);
511			return;
512		}
513
514		if (Date.now() - start >= timeout) {
515			console.warn('Visible element not found:', selector);
516			return;
517		}
518
519		requestAnimationFrame(check);
520	}
521
522	check();
523}

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.