PageSourceSearch

https://amrutphilately.com/js/tools.js

js amrutphilately.com collected 2026-10-02 23:19:33 UTC 20,075 bytes, 642 lines download raw bytes

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

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.