PageSourceSearch

https://www.powerplustools.de/js/tools.js

js powerplustools.de collected 2026-09-25 20:42:37 UTC 19,353 bytes, 631 lines download raw bytes

1/*
2* 2007-2015 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-2015 PrestaShop SA
22*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
23*  International Registered Trademark & Property of PrestaShop SA
24*/
25
26function formatedNumberToFloat(price, currencyFormat, currencySign)
27{
28	price = price.replace(currencySign, '');
29	if (currencyFormat === 1)
30		return parseFloat(price.replace(',', '').replace(' ', ''));
31	else if (currencyFormat === 2)
32		return parseFloat(price.replace(' ', '').replace(',', '.'));
33	else if (currencyFormat === 3)
34		return parseFloat(price.replace('.', '').replace(' ', '').replace(',', '.'));
35	else if (currencyFormat === 4)
36		return parseFloat(price.replace(',', '').replace(' ', ''));
37	return price;
38}
39
40//return a formatted number
41function formatNumber(value, numberOfDecimal, thousenSeparator, virgule)
42{
43	value = value.toFixed(numberOfDecimal);
44	var val_string = value+'';
45	var tmp = val_string.split('.');
46	var abs_val_string = (tmp.length === 2) ? tmp[0] : val_string;
47	var deci_string = ('0.' + (tmp.length === 2 ? tmp[1] : 0)).substr(2);
48	var nb = abs_val_string.length;
49
50	for (var i = 1 ; i < 4; i++)
51		if (value >= Math.pow(10, (3 * i)))
52			abs_val_string = abs_val_string.substring(0, nb - (3 * i)) + thousenSeparator + abs_val_string.substring(nb - (3 * i));
53
54	if (parseInt(numberOfDecimal) === 0)
55		return abs_val_string;
56	return abs_val_string + virgule + (deci_string > 0 ? deci_string : '00');
57}
58
59function formatCurrency(price, currencyFormat, currencySign, currencyBlank)
60{
61	// if you modified this function, don't forget to modify the PHP function displayPrice (in the Tools.php class)
62	var blank = '';
63	price = parseFloat(price.toFixed(10));
64	price = ps_round(price, priceDisplayPrecision);
65	if (currencyBlank > 0)
66		blank = ' ';
67	if (currencyFormat == 1)
68		return currencySign + blank + formatNumber(price, priceDisplayPrecision, ',', '.');
69	if (currencyFormat == 2)
70		return (formatNumber(price, priceDisplayPrecision, ' ', ',') + blank + currencySign);
71	if (currencyFormat == 3)
72		return (currencySign + blank + formatNumber(price, priceDisplayPrecision, '.', ','));
73	if (currencyFormat == 4)
74		return (formatNumber(price, priceDisplayPrecision, ',', '.') + blank + currencySign);
75	if (currencyFormat == 5)
76		return (currencySign + blank + formatNumber(price, priceDisplayPrecision, '\'', '.'));
77	return price;
78}
79
80function ps_round_helper(value, mode)
81{
82	// From PHP Math.c
83	if (value >= 0.0)
84	{
85		tmp_value = Math.floor(value + 0.5);
86		if ((mode == 3 && value == (-0.5 + tmp_value)) ||
87			(mode == 4 && value == (0.5 + 2 * Math.floor(tmp_value / 2.0))) ||
88			(mode == 5 && value == (0.5 + 2 * Math.floor(tmp_value / 2.0) - 1.0)))
89			tmp_value -= 1.0;
90	}
91	else
92	{
93		tmp_value = Math.ceil(value - 0.5);
94		if ((mode == 3 && value == (0.5 + tmp_value)) ||
95			(mode == 4 && value == (-0.5 + 2 * Math.ceil(tmp_value / 2.0))) ||
96			(mode == 5 && value == (-0.5 + 2 * Math.ceil(tmp_value / 2.0) + 1.0)))
97			tmp_value += 1.0;
98	}
99
100	return tmp_value;
101}
102
103function ps_log10(value)
104{
105	return Math.log(value) / Math.LN10;
106}
107
108function ps_round_half_up(value, precision)
109{
110	var mul = Math.pow(10, precision);
111	var val = value * mul;
112
113	var next_digit = Math.floor(val * 10) - 10 * Math.floor(val);
114	if (next_digit >= 5)
115		val = Math.ceil(val);
116	else
117		val = Math.floor(val);
118
119	return val / mul;
120}
121
122function ps_round(value, places)
123{
124	if (typeof(roundMode) === 'undefined')
125		roundMode = 2;
126	if (typeof(places) === 'undefined')
127		places = 2;
128
129	var method = roundMode;
130
131	if (method === 0)
132		return ceilf(value, places);
133	else if (method === 1)
134		return floorf(value, places);
135	else if (method === 2)
136		return ps_round_half_up(value, places);
137	else if (method == 3 || method == 4 || method == 5)
138	{
139		// From PHP Math.c
140		var precision_places = 14 - Math.floor(ps_log10(Math.abs(value)));
141		var f1 = Math.pow(10, Math.abs(places));
142
143		if (precision_places > places && precision_places - places < 15)
144		{
145			var f2 = Math.pow(10, Math.abs(precision_places));
146			if (precision_places >= 0)
147				tmp_value = value * f2;
148			else
149				tmp_value = value / f2;
150
151			tmp_value = ps_round_helper(tmp_value, roundMode);
152
153			/* now correctly move the decimal point */
154			f2 = Math.pow(10, Math.abs(places - precision_places));
155			/* because places < precision_places */
156			tmp_value /= f2;
157		}
158		else
159		{
160			/* adjust the value */
161			if (places >= 0)
162				tmp_value = value * f1;
163			else
164				tmp_value = value / f1;
165
166			if (Math.abs(tmp_value) >= 1e15)
167				return value;
168		}
169
170		tmp_value = ps_round_helper(tmp_value, roundMode);
171		if (places > 0)
172			tmp_value = tmp_value / f1;
173		else
174			tmp_value = tmp_value * f1;
175
176		return tmp_value;
177	}
178}
179
180function autoUrl(name, dest)
181{
182	var loc;
183	var id_list;
184
185	id_list = document.getElementById(name);
186	loc = id_list.options[id_list.selectedIndex].value;
187	if (loc != 0)
188		location.href = dest+loc;
189	return ;
190}
191
192function autoUrlNoList(name, dest)
193{
194	var loc;
195
196	loc = document.getElementById(name).checked;
197	location.href = dest + (loc == true ? 1 : 0);
198	return ;
199}
200
201/*
202** show or hide element e depending on condition show
203*/
204function toggle(e, show)
205{
206	e.style.display = show ? '' : 'none';
207}
208
209function toggleMultiple(tab)
210{
211    var len = tab.length;
212
213    for (var i = 0; i < len; i++)
214        if (tab[i].style)
215            toggle(tab[i], tab[i].style.display == 'none');
216}
217
218/**
219* Show dynamicaly an element by changing the sytle "display" property
220* depending on the option selected in a select.
221*
222* @param string $select_id id of the select who controls the display
223* @param string $elem_id prefix id of the elements controlled by the select
224*   the real id must be : 'elem_id'+nb with nb the corresponding number in the
225*   select (starting with 0).
226*/
227function showElemFromSelect(select_id, elem_id)
228{
229	var select = document.getElementById(select_id);
230	for (var i = 0; i < select.length; ++i)
231	{
232	    var elem = document.getElementById(elem_id + select.options[i].value);
233		if (elem != null)
234			toggle(elem, i == select.selectedIndex);
235	}
236}
237
238/**
239* Get all div with specified name and for each one (by id), toggle their visibility
240*/
241function openCloseAllDiv(name, option)
242{
243	var tab = $('*[name='+name+']');
244	for (var i = 0; i < tab.length; ++i)
245		toggle(tab[i], option);
246}
247
248function toggleDiv(name, option)
249{
250	$('*[name='+name+']').each(function(){
251		if (option == 'open')
252		{
253			$('#buttonall').data('status', 'close');
254			$(this).hide();
255		}
256		else
257		{
258			$('#buttonall').data('status', 'open');
259			$(this).show();
260		}
261	})
262}
263
264function toggleButtonValue(id_button, text1, text2)
265{
266	if ($('#'+id_button).find('i').first().hasClass('process-icon-compress'))
267	{
268		$('#'+id_button).find('i').first().removeClass('process-icon-compress').addClass('process-icon-expand');
269		$('#'+id_button).find('span').first().html(text1);
270	}
271	else
272	{
273		$('#'+id_button).find('i').first().removeClass('process-icon-expand').addClass('process-icon-compress');
274		$('#'+id_button).find('span').first().html(text2);
275	}
276}
277
278
279/**
280* Toggle the value of the element id_button between text1 and text2
281*/
282function toggleElemValue(id_button, text1, text2)
283{
284	var obj = document.getElementById(id_button);
285	if (obj)
286		obj.value = ((!obj.value || obj.value == text2) ? text1 : text2);
287}
288
289function addBookmark(url, title)
290{
291	if (window.sidebar && window.sidebar.addPanel)
292		return window.sidebar.addPanel(title, url, "");
293	else if ( window.external && ('AddFavorite' in window.external))
294		return window.external.AddFavorite( url, title);
295}
296
297function writeBookmarkLink(url, title, text, img)
298{
299	var insert = '';
300	if (img)
301		insert = writeBookmarkLinkObject(url, title, '<img src="' + img + '" alt="' + escape(text) + '" title="' + removeQuotes(text) + '" />') + '&nbsp';
302	insert += writeBookmarkLinkObject(url, title, text);
303	if (window.sidebar || window.opera && window.print || (window.external && ('AddFavorite' in window.external)))
304		$('.add_bookmark, #header_link_bookmark').append(insert);
305}
306
307function writeBookmarkLinkObject(url, title, insert)
308{
309	if (window.sidebar || window.external)
310		return ('<a href="javascript:addBookmark(\'' + escape(url) + '\', \'' + removeQuotes(title) + '\')">' + insert + '</a>');
311	else if (window.opera && window.print)
312		return ('<a rel="sidebar" href="' + escape(url) + '" title="' + removeQuotes(title) + '">' + insert + '</a>');
313	return ('');
314}
315
316function checkCustomizations()
317{
318	var pattern = new RegExp(' ?filled ?');
319
320	if (typeof customizationFields != 'undefined')
321		for (var i = 0; i < customizationFields.length; i++)
322		{
323			/* If the field is required and empty then we abort */
324			if (parseInt(customizationFields[i][1]) == 1 && ($('#' + customizationFields[i][0]).html() == '' ||  $('#' + customizationFields[i][0]).text() != $('#' + customizationFields[i][0]).val()) && !pattern.test($('#' + customizationFields[i][0]).attr('class')))
325				return false;
326		}
327	return true;
328}
329
330function emptyCustomizations()
331{
332	customizationId = null;
333	if(typeof(customizationFields) == 'undefined') return;
334
335	$('.customization_block .success').fadeOut(function(){
336		$(this).remove();
337	});
338	$('.customization_block .error').fadeOut(function(){
339		$(this).remove();
340	});
341	for (var i = 0; i < customizationFields.length; i++)
342	{
343		$('#' + customizationFields[i][0]).html('');
344		$('#' + customizationFields[i][0]).val('');
345	}
346}
347
348function ceilf(value, precision)
349{
350	if (typeof(precision) === 'undefined')
351		precision = 0;
352	var precisionFactor = precision === 0 ? 1 : Math.pow(10, precision);
353	var tmp = value * precisionFactor;
354	var tmp2 = tmp.toString();
355	if (tmp2[tmp2.length - 1] === 0)
356		return value;
357	return Math.ceil(value * precisionFactor) / precisionFactor;
358}
359
360function floorf(value, precision)
361{
362	if (typeof(precision) === 'undefined')
363		precision = 0;
364	var precisionFactor = precision === 0 ? 1 : Math.pow(10, precision);
365	var tmp = value * precisionFactor;
366	var tmp2 = tmp.toString();
367	if (tmp2[tmp2.length - 1] === 0)
368		return value;
369	return Math.floor(value * precisionFactor) / precisionFactor;
370}
371
372function setCurrency(id_currency)
373{
374	$.ajax({
375		type: 'POST',
376		headers: { "cache-control": "no-cache" },
377		url: baseDir + 'index.php' + '?rand=' + new Date().getTime(),
378		data: 'controller=change-currency&id_currency='+ parseInt(id_currency),
379		success: function(msg)
380		{
381			location.reload(true);
382		}
383	});
384}
385
386function isArrowKey(k_ev)
387{
388	var unicode=k_ev.keyCode? k_ev.keyCode : k_ev.charCode;
389	if (unicode >= 37 && unicode <= 40)
390		return true;
391	return false;
392}
393
394function removeQuotes(value)
395{
396	value = value.replace(/\\"/g, '');
397	value = value.replace(/"/g, '');
398	value = value.replace(/\\'/g, '');
399	value = value.replace(/'/g, '');
400
401	return value;
402}
403
404function sprintf(format)
405{
406	for(var i=1; i < arguments.length; i++)
407		format = format.replace(/%s/, arguments[i]);
408
409	return format;
410}
411
412/**
413 * Display a MessageBox
414 * @param {string} msg
415 * @param {string} title (optional)
416 */
417function fancyMsgBox(msg, title)
418{
419    if (title) msg = "<h2>" + title + "</h2><p>" + msg + "</p>";
420    msg += "<br/><p class=\"submit\" style=\"text-align:right; padding-bottom: 0\"><input class=\"button\" type=\"button\" value=\"OK\" onclick=\"$.fancybox.close();\" /></p>";
421	if(!!$.prototype.fancybox)
422    	$.fancybox( msg, {'autoDimensions': false, 'autoSize': false, 'width': 500, 'height': 'auto', 'openEffect': 'none', 'closeEffect': 'none'} );
423}
424
425/**
426 * Display a messageDialog with different buttons including a callback for each one
427 * @param {string} question
428 * @param {mixed} title Optional title for the dialog box. Send false if you don't want any title
429 * @param {object} buttons Associative array containg a list of {buttonCaption: callbackFunctionName, ...}. Use an empty space instead of function name for no callback
430 * @param {mixed} otherParams Optional data sent to the callback function
431 */
432function fancyChooseBox(question, title, buttons, otherParams)
433{
434    var msg, funcName, action;
435	msg = '';
436    if (title)
437		msg = "<h2>" + title + "</h2><p>" + question + "</p>";
438    msg += "<br/><p class=\"submit\" style=\"text-align:right; padding-bottom: 0\">";
439    var i = 0;
440    for (var caption in buttons) {
441        if (!buttons.hasOwnProperty(caption)) continue;
442        funcName = buttons[caption];
443        if (typeof otherParams == 'undefined') otherParams = 0;
444        otherParams = escape(JSON.stringify(otherParams));
445        action = funcName ? "$.fancybox.close();window['" + funcName + "'](JSON.parse(unescape('" + otherParams + "')), " + i + ")" : "$.fancybox.close()";
446	  msg += '<button type="submit" class="button btn-default button-medium" style="margin-right: 5px;" value="true" onclick="' + action + '" >';
447	  msg += '<span>' + caption + '</span></button>'
448        i++;
449    }
450    msg += "</p>";
451	if(!!$.prototype.fancybox)
452    	$.fancybox(msg, {'autoDimensions': false, 'width': 500, 'height': 'auto', 'openEffect': 'none', 'closeEffect': 'none'});
453}
454
455function toggleLayer(whichLayer, flag)
456{
457	if (!flag)
458		$(whichLayer).hide();
459	else
460		$(whichLayer).show();
461}
462
463function openCloseLayer(whichLayer, action)
464{
465	if (!action)
466	{
467		if ($(whichLayer).css('display') == 'none')
468			$(whichLayer).show();
469		else
470			$(whichLayer).hide();
471	}
472	else if (action == 'open')
473		$(whichLayer).show();
474	else if (action == 'close')
475		$(whichLayer).hide();
476}
477
478function updateTextWithEffect(jQueryElement, text, velocity, effect1, effect2, newClass)
479{
480	if(jQueryElement.text() !== text)
481	{
482		if(effect1 === 'fade')
483			jQueryElement.fadeOut(velocity, function(){
484				$(this).addClass(newClass);
485				if(effect2 === 'fade') $(this).text(text).fadeIn(velocity);
486				else if(effect2 === 'slide') $(this).text(text).slideDown(velocity);
487					else if(effect2 === 'show')	$(this).text(text).show(velocity, function(){});
488			});
489		else if(effect1 === 'slide')
490			jQueryElement.slideUp(velocity, function(){
491				$(this).addClass(newClass);
492				if(effect2 === 'fade') $(this).text(text).fadeIn(velocity);
493				else if(effect2 === 'slide') $(this).text(text).slideDown(velocity);
494					else if(effect2 === 'show')	$(this).text(text).show(velocity);
495			});
496		else if(effect1 === 'hide')
497			jQueryElement.hide(velocity, function(){
498				$(this).addClass(newClass);
499				if(effect2 === 'fade') $(this).text(text).fadeIn(velocity);
500				else if(effect2 === 'slide') $(this).text(text).slideDown(velocity);
501					else if(effect2 === 'show')	$(this).text(text).show(velocity);
502			});
503	}
504}
505//show a JS debug
506function dbg(value)
507{
508	var active = false;//true for active
509	var firefox = true;//true if debug under firefox
510
511	if (active)
512		if (firefox)
513			console.log(value);
514		else
515			alert(value);
516}
517
518/**
519* Function : print_r()
520* Arguments: The element  - array,hash(associative array),object
521*            The limit - OPTIONAL LIMIT
522*            The depth - OPTIONAL
523* Returns  : The textual representation of the array.
524* This function was inspired by the print_r function of PHP.
525* This will accept some data as the argument and return a
526* text that will be a more readable version of the
527* array/hash/object that is given.
528*/
529function print_r(element, limit, depth)
530{
531	depth =	depth?depth:0;
532	limit = limit?limit:1;
533
534	returnString = '<ol>';
535
536	for(property in element)
537	{
538		//Property domConfig isn't accessable
539		if (property != 'domConfig')
540		{
541			returnString += '<li><strong>'+ property + '</strong> <small>(' + (typeof element[property]) +')</small>';
542
543			if (typeof element[property] == 'number' || typeof element[property] == 'boolean')
544				returnString += ' : <em>' + element[property] + '</em>';
545			if (typeof element[property] == 'string' && element[property])
546				returnString += ': <div style="background:#C9C9C9;border:1px solid black; overflow:auto;"><code>' +
547									element[property].replace(/</g, '&amp;lt;').replace(/>/g, '&amp;gt;') + '</code></div>';
548
549			if ((typeof element[property] == 'object') && (depth < limit))
550				returnString += print_r(element[property], limit, (depth + 1));
551
552			returnString += '</li>';
553		}
554	}
555	returnString += '</ol>';
556
557	if(depth == 0)
558	{
559		winpop = window.open("", "","width=800,height=600,scrollbars,resizable");
560		winpop.document.write('<pre>'+returnString+ '</pre>');
561		winpop.document.close();
562	}
563	return returnString;
564}
565
566//verify if value is in the array
567function in_array(value, array)
568{
569	for (var i in array)
570		if ((array[i] + '') === (value + ''))
571			return true;
572	return false;
573}
574
575function isCleanHtml(content)
576{
577	var events = 'onmousedown|onmousemove|onmmouseup|onmouseover|onmouseout|onload|onunload|onfocus|onblur|onchange';
578	events += '|onsubmit|ondblclick|onclick|onkeydown|onkeyup|onkeypress|onmouseenter|onmouseleave|onerror|onselect|onreset|onabort|ondragdrop|onresize|onactivate|onafterprint|onmoveend';
579	events += '|onafterupdate|onbeforeactivate|onbeforecopy|onbeforecut|onbeforedeactivate|onbeforeeditfocus|onbeforepaste|onbeforeprint|onbeforeunload|onbeforeupdate|onmove';
580	events += '|onbounce|oncellchange|oncontextmenu|oncontrolselect|oncopy|oncut|ondataavailable|ondatasetchanged|ondatasetcomplete|ondeactivate|ondrag|ondragend|ondragenter|onmousewheel';
581	events += '|ondragleave|ondragover|ondragstart|ondrop|onerrorupdate|onfilterchange|onfinish|onfocusin|onfocusout|onhashchange|onhelp|oninput|onlosecapture|onmessage|onmouseup|onmovestart';
582	events += '|onoffline|ononline|onpaste|onpropertychange|onreadystatechange|onresizeend|onresizestart|onrowenter|onrowexit|onrowsdelete|onrowsinserted|onscroll|onsearch|onselectionchange';
583	events += '|onselectstart|onstart|onstop';
584
585	var script1 = /<[\s]*script/im;
586	var script2 = new RegExp('('+events+')[\s]*=', 'im');
587	var script3 = /.*script\:/im;
588	var script4 = /<[\s]*(i?frame|embed|object)/im;
589
590	if (script1.test(content) || script2.test(content) || script3.test(content) || script4.test(content))
591		return false;
592
593	return true;
594}
595
596function getStorageAvailable() {
597	test = 'foo';
598	storage =  window.localStorage || window.sessionStorage;
599	try {
600		storage.setItem(test, test);
601		storage.removeItem(test);
602		return storage;
603	}
604	catch (error) {
605		return null;
606	}
607}
608
609$(document).ready(function()
610{
611	// Hide all elements with .hideOnSubmit class when parent form is submit
612	$('form').submit(function() {
613		$(this).find('.hideOnSubmit').hide();
614	});
615
616	$.fn.checkboxChange = function(fnChecked, fnUnchecked) {
617		if ($(this).prop('checked') && fnChecked)
618			fnChecked.call(this);
619		else if(fnUnchecked)
620			fnUnchecked.call(this);
621
622		if (!$(this).attr('eventCheckboxChange'))
623		{
624			$(this).on('change', function() { $(this).checkboxChange(fnChecked, fnUnchecked); });
625			$(this).attr('eventCheckboxChange', true);
626		}
627	};
628
629	// attribute target="_blank" is not W3C compliant
630	$('a._blank, a.js-new-window').attr('target', '_blank');
631});

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.