PageSourceSearch

https://www.also.pt/js/util/1.2/util.js?v=buildNumber

js also.pt collected 2026-10-09 22:41:49 UTC 19,730 bytes, 721 lines download raw bytes

1/*
2	Nice to know:
3
4-	$(window).load(function(){
5	    // Wird ausgeführt, wenn die Seite komplett geladen wurde
6	    // -> inklusive Bilder und andere Elemente
7	});
8
9-	$(document).ready(function(){
10	    // Wird ausgeführt, wenn der DOM-Baum vollständig geladen wurde
11	    // -> Bilder oder andere Elemente, die noch geladen werden müssen werden nicht berücksichtigt
12	});
13*/
14
15/* extend jquery. react on enter keypress event */
16$.fn.onEnter = function(func) {
17	return this.keypress(function(evt) {
18		var keycode = evt.keyCode;
19
20		// is enter key
21		if (keycode == 13) {
22			if (func != undefined) {
23				return func(evt);			
24			}
25		}
26		else {
27			return true;
28		}
29	});
30};
31
32/**
33 * Gets or sets the real value of an input field. It works like jQuery's val() function, but is compatible with placeholder shims:
34 * if given an empty string, it will not overwrite the value if it is equal to the placeholder text, and if used as a getter, it
35 * will return an empty string instead of the placeholder text.
36 */
37$.fn.realVal = function(newValue) {
38	var old = this.val();
39	var placeholder = this.attr('placeholder');
40	if (newValue != undefined) {
41		// do not overwrite the placeholder text with an empty value
42		if (!(newValue == "" && old == placeholder)) {
43			this.val(newValue);
44			this.blur(); // blur is used to trigger the HTML5 shim in a way so that this code does not depend on the shim code.
45		}
46		return this;
47	} else {
48		var result = old;
49		if (result == placeholder) {
50			result = "";
51		}
52		return result;
53	}
54};
55
56/** Erweiterungen der nativen String-Klasse
57
58ltrim, rtrim, trim
59	Tun was man erwartet.
60	Der optionale Parameter chars bestimmt Zeichen, die anstatt whitespace entfernt werden sollen,
61	z.B.   "Hä???!!!".rtrim("!?")  =>  "Hä"
62*/
63(function(clazz){
64	var p = clazz.prototype;
65
66	if (!p.ltrim)
67		p.ltrim = function(chars) {
68			return this.replace (chars ? new RegExp('^[' + chars + ']+') : /^\s+/, '');
69		};
70
71	if (!p.rtrim)
72		p.rtrim = function(chars) {
73			return this.replace (chars ? new RegExp('[' + chars + ']+$') : /\s+$/, '');
74		};
75
76	if (!p.trim)
77		p.trim = function(chars) {
78			return this.ltrim(chars).rtrim(chars);
79		};
80
81})(String);
82
83
84
85/**
86 * remove multiple wildcarts from string
87 * abc*** -> abc*
88 */
89function trimRightWildcart(sString){
90    return sString.replace(/\*+$/, '*');
91}
92
93function checkDate(i_date) {
94
95	var expression = /^([0]*[1-9]|[12]+[0-9]|3[01])([-\/\.])([0]*[1-9]|1[012])\2(19|20)[0-9]{2}$/;
96
97	if( expression.test(i_date) == false){
98		return false;
99	} else {
100		return true;
101	}
102}
103
104/* Blendet ein Element ein / aus
105	setzt "display: block", "display: none"
106*/
107function toggleElementVisbility(cssSelector){
108	toggleElementClass(cssSelector, "invisible");
109}
110
111/* Wechselt eine Klasse eines Element (fügt die klasse hinzu / nimmt die Klasse weg) */
112function toggleElementClass(cssSelector, classNameToToggle){
113	$(cssSelector).toggleClass(classNameToToggle);
114}
115
116/* Wechselt zwischen 2 Icons hin zu her
117	cssSelector 	= Element, dessen Icon gewechselt werden soll
118	firstIconClass 	= aktuelle Iconklasse
119	secondIconClass = neue Iconklasse
120*/
121function toggleIcon(cssSelector, firstIconClass, secondIconClass){
122	$(cssSelector).toggleClass(firstIconClass)
123		.toggleClass(secondIconClass);
124}
125
126
127/*
128	Zeigt ein Element für X Sekunden an und blendet es danach wieder aus
129*/
130function showObjForXSeconds(obj, seconds) {
131	if (seconds == null || seconds.length < 0 || seconds == undefined || isNaN(seconds)) {
132		seconds = 5;
133	}
134
135	seconds = seconds * 1000;
136
137	var obj = $(obj);
138
139	if (obj != null && obj.length > 0) {
140		obj.fadeIn().delay(seconds).fadeOut('slow');
141	}
142}
143
144/*
145	Funktion, die aus Klassennamen Argumente ausliest
146	Bsp: class="icon ic_warenkorb matNo_123456"
147	Ergebnis für .arg("matNo") wäre "123456"
148
149	Wenn es nicht gefunden wird, wird ein leerer String zurückgegeben
150*/
151
152$.fn.arg = function (searchString) {
153	
154	var node=this[0], rx=new RegExp(searchString + "_(\\S*)\\s?"), args;
155	if (node == undefined) {
156		return "";
157	}
158	
159	do {
160		if (node.className && (args=rx.exec(node.className)))
161			break;
162	} while (node=node.parentNode);
163
164	return args ? args[1] : "";
165};
166
167
168/*
169	Ließt einen String aus und sucht darin nach einem KEY
170	Syntax für die KeyValue-Pärchen:	key=value&key2=value2
171
172	Mögliche Anwendung für den Request-String bei Ajax-Calls
173*/
174function getAttribute (searchString, textToSearchIn) {
175
176	var attrValue = "";
177
178	//suche 'searchString' dann ein '=' und dann alles, was kein '&' ist
179	var attrValueArray = new RegExp(searchString + "=([^&]*)").exec(textToSearchIn);
180
181	if (attrValueArray != null && attrValueArray.length > 0) {
182		attrValue = attrValueArray[1];
183	}
184
185	return attrValue;
186};
187
188/*
189	Formatierung einer Zahl in ein gültiges Währungs-Format für EURO
190*/
191function formatEURCurrency(num) {
192	return formatCurrency(num, '');
193}
194
195/**
196 *	Formatierung einer Zahl in ein gültiges Währungs-Format (symbol)
197 *	@param {Number} num Number to format
198 *	@param {String} symbol Currency symbol to use
199 */
200function formatCurrency(num, symbol) {
201	return formatCurrencyComplex(num, 2, true, symbol);
202}
203
204/**
205 *  Use pegasos_core method formatDateByType(dateAsString, type)
206 */
207function formatDateByPattern(format, dateAsString){
208	return $.datepicker.formatDate(format, dateAsString);
209}
210
211/**
212 *
213 * Get a formatting description based on current salesorg
214 * See FormatOverrideService in Backend for the main specification.
215 * 
216 * @param currency 
217 */
218function _createCurrencyFormat(currency) {
219	
220	/* please do not change default values directly */
221	var format = {
222		decimalPlaces: 2,
223		decimalSeparator: getDecimalSeparator(),
224		groupingSeparator: getGroupingSeparator(),
225		currencySymbol: currency ? currency : '',
226		currencyPlacement: getCurrencySymbolPlacement()
227	};	
228	
229	return format;
230}
231
232function _createCanonicalDecimalAsString(decimalNumber, decimalPlaces) {
233
234	if(decimalNumber > 0 && decimalNumber < 0.001) {
235		decimalNumber = Number(0);
236	}
237	else {
238		decimalNumber = Number(decimalNumber);
239	}
240		
241	// set number of decimal places required. does commerical rounding (1.236 -> 1.24)
242	decimalNumber = decimalNumber.toFixed(decimalPlaces);
243	var result = decimalNumber + ''; // you gonna be a string
244	
245	var sign = decimalNumber < 0;
246    if(sign) result = result.substring(1);
247    	
248    // Nachkommastellen ermittlen
249    var idx = result.indexOf('.');
250	var fractionPart = '';
251	
252	if (idx == -1) idx = result.length;
253    else fractionPart = '.' + result.substring(idx + 1);
254
255	var convertedResult = '';
256    while(idx > 0)    {
257        if(idx - 3 > 0) {
258			convertedResult = '_' + result.substring( idx - 3, idx) + convertedResult;
259		}
260        else {
261			convertedResult = result.substring(0, idx) + convertedResult;
262		}
263        idx -= 3;
264    }
265	
266	return (sign ? '-' : '') + convertedResult + fractionPart;
267}
268
269function _formatCanonicalPrice(canonicalPrice, format) {
270
271	if(format.decimalSeparator != '.') canonicalPrice = canonicalPrice.replace('.', format.decimalSeparator);
272	if(format.groupingSeparator != '_') canonicalPrice = canonicalPrice.replace(/_/g, format.groupingSeparator);
273	
274	if(format.currencySymbol != '') {
275		if(format.currencyPlacement == 'left') canonicalPrice = format.currencySymbol + '&nbsp;' + canonicalPrice;
276		if(format.currencyPlacement == 'right') canonicalPrice = canonicalPrice + '&nbsp;' + format.currencySymbol;
277	}
278	
279	return canonicalPrice;
280}
281
282/**
283 * js implementation of backend solution formattingService for locale 
284 * based price formatting
285 *
286 * @param price a string or number that should be parseable as a price
287 * @param currency a string that is treated as a currency. can be empty
288 */
289function formatPrice(price, currency) {
290
291	if(typeof currency === 'undefined') currency = '';
292	
293	var numPrice = Number(price);
294	if(isNaN(numPrice)) {
295		return '';
296	}
297	
298	var format = _createCurrencyFormat(currency);
299	var canonicalPrice = _createCanonicalDecimalAsString(numPrice, format.decimalPlaces);
300		
301	return _formatCanonicalPrice(canonicalPrice, format);
302	
303}
304
305/**
306 * formatCurrencyComplex(number, k, fix, symbol)
307 * @param number: Die Zahl, die formatiert werden soll
308 * @param k (optional), die Anzahl der Nachkommastellen auf die die Zahl gerundet werden soll (default: 0)
309 * @param fix (optional), dieser Parameter bestimmt, ob die formatierte Zahl eine feste Anzahl von Nachkommastellen haben soll. Ist der Wert true, dann werden evtl. fehlende Stellen mit einer Null aufgeüllt.
310 * @param symbol (optional), Währungszeichen, das angezeigt werden soll
311 * @deprecated formatPriceByLocale(price, localeOrSalesorg, currency) might fit your needs as well.
312 * @deprecated fix not used in formatCurrencyComplex
313 */
314function formatCurrencyComplex(zahl, k, fix, symbol) {
315
316	if(isNaN(zahl)) {
317		return 'EOL';
318    } 
319		
320	// do magic rounding
321	if(!k) k = 0;
322	var f = Math.pow(10, k);
323    zahl = '' + parseInt(zahl * f + (.5 * (zahl > 0 ? 1 : -1)) ) / f ;
324	
325	var canonicalPrice = _createCanonicalDecimalAsString(zahl, k);
326	
327	var format = _createCurrencyFormat(symbol);
328	//format.decimalSeparator = ',';
329	//format.groupingSeparator = '.';
330	
331	return _formatCanonicalPrice(canonicalPrice, format);
332	
333}
334
335/*
336	Konvertiert ein JS-Array in eine Kommaseperierte Liste
337*/
338function convertArrayToCommaSeperatedString(arr) {
339
340	if (arr == null || arr == undefined) {
341		return "";
342	}
343
344	return arr.join(",");
345}
346
347/*
348	Konvertiert eine Kommaseperierte Liste in ein JS-Array
349*/
350function convertCommaSeperatedStringToArray(str) {
351
352	if (str == null || str == undefined) {
353		return [];
354	}
355
356	return str.split(",");
357}
358
359/* Setzt für eine Gruppe von Objekten eine Einheitliche Höhe, ausgehend von dem Objekt mit der Größten Höhe */
360function equalHeight(group) {
361	var tallest = 0;
362
363	if (group != undefined && group.length > 1) {
364		for (var i= 0; i<group.length; i++) {
365			var thisHeight = $(group[i]).height();
366			if(thisHeight > tallest) {
367				tallest = thisHeight;
368			}
369		}
370	}
371
372	if (tallest > 0) {
373		group.height(tallest);
374	}
375}
376
377
378/* Setzt für eine Gruppe von Objekten eine Einheitliche Breite, ausgehend von dem Objekt mit der Größten Breite */
379function equalWidth(group) {
380	widest = 0;
381	group.each(function() {
382		thisWidth = $(this).outerWidth();
383
384		if (thisWidth > widest) {
385			widest = thisWidth;
386		}
387	});
388	
389	 group.css({ 'width': widest });
390}
391
392/* Setzt für die jeweiligen Kindelemente einer Gruppe von Objekten eine Einheitliche Höhe, ausgehend von dem Objekt mit der Größten Höhe */
393function equalHeightForChildren(parentSelector,childSelector) {
394	$parentList = $(parentSelector);
395	if ($parentList.length <= 0) {
396		return;
397	}
398	
399	for(var i=0; i < $parentList.length; i++) {
400		$parent = $parentList.eq(i);
401		$childList = $parent.find(childSelector);
402		if ($childList.length <= 0) {
403			return;
404		}
405		equalHeight($childList);
406	}
407}
408
409/**
410 * Check if a javascript variable or object isdefined in window scope 
411 * as a global variable.
412 *
413 * Usage: alert(isdefined('myvar'));
414 */
415function isDefined(variable) {
416    return (typeof(window[variable]) == "undefined")?  false: true;
417}
418
419
420
421/**
422	Check if a pegasosLightbox is open
423*/
424
425function isALightboxOpen() {
426	
427	var pegasosObj = null;
428	
429	if (parent == this) {
430		pegasosObj = pegasos;
431	}
432	else {
433		pegasosObj = parent.pegasos;
434	}
435	
436	if (typeof(pegasosObj.lightbox) == "undefined") {
437		return false;
438	}
439	
440	return pegasosObj.lightbox.isOpen == 'undefined'? false : pegasosObj.lightbox.isOpen;
441};
442
443/**
444 * Returns the decimal separator for the current salesorg
445 */
446function getDecimalSeparator() {
447	if (window.pegasos != undefined && window.pegasos.decimalSeparator != undefined)
448		return window.pegasos.decimalSeparator; 
449	return ',';
450}
451
452/**
453 * Returns the grouping separator for the current salesorg
454 */
455function getGroupingSeparator() {
456	if (window.pegasos != undefined && window.pegasos.groupingSeparator != undefined)
457		return window.pegasos.groupingSeparator; 
458	return '.';
459}
460
461/**
462 * Returns the placement of the currency symbol
463 */
464function getCurrencySymbolPlacement() {
465	if (window.pegasos != undefined && window.pegasos.currencySymbolPlacement != undefined)
466		return window.pegasos.currencySymbolPlacement; 
467	return 'right';
468}
469
470/**
471 * Parses a string as number. 
472 * 
473 * @param number
474 * @param dec_point (optional)
475 * @param thousands_sep (optional)
476 */
477$.parseNumber = function( number, dec_point, thousands_sep ){
478	
479	if (typeof number === 'number') {
480		return number;
481	}
482	
483	thousands_sep	= (typeof thousands_sep === 'undefined') ? getGroupingSeparator() : thousands_sep;
484	dec_point		= (typeof dec_point === 'undefined') ? getDecimalSeparator() : dec_point;
485	
486	number = number.replace("&nbsp;", "");
487	number = number.replace(" ", "");
488	number = number.replace(thousands_sep, "");
489	number = number.replace(dec_point, "\.");
490	
491	return number;
492}
493
494/**
495* The (modified) excellent number formatting method from PHPJS.org.
496* http://phpjs.org/functions/number_format/
497*
498* @modified by Sam Sehnert (teamdf.com)
499* - don't redefine dec_point, thousands_sep... just overwrite with defaults.
500* - don't redefine decimals, just overwrite as numeric.
501* - Generate regex for normalizing pre-formatted numbers.
502*
503* @param float number : The number you wish to format, or TRUE to use the text contents
504* of the element as the number. Please note that this won't work for
505* elements which have child nodes with text content.
506* @param int decimals : The number of decimal places that should be displayed. Defaults to 0.
507* @param string dec_point : The character to use as a decimal point. Defaults to salesorg default.
508* @param string thousands_sep : The character to use as a thousands separator. Defaults to salesorg default.
509*
510* @return string : The formatted number as a string.
511*/
512$.formatNumber = function( number, decimals, dec_point, thousands_sep ){
513	
514	// Set the default values here, instead so we can use them in the replace below.
515	thousands_sep	= (typeof thousands_sep === 'undefined') ? getGroupingSeparator() : thousands_sep;
516	dec_point		= (typeof dec_point === 'undefined') ? getDecimalSeparator() : dec_point;
517	decimals		= !isFinite(+decimals) ? 0 : Math.abs(decimals);
518	
519	// Work out the unicode representation for the decimal place.
520	var u_dec = ('\\u'+('0000'+(dec_point.charCodeAt(0).toString(16))).substr(-4));
521	
522	// Fix the number, so that it's an actual number.
523	//number = (number + '')
524	//	.replace(new RegExp('[^'+u_dec+'0-9]','g'),'')
525	//	.replace(new RegExp(u_dec,'g'),'.');
526	
527	var n = !isFinite(+number) ? 0 : +number,
528		s = '',
529		toFixedFix = function (n, decimals) {
530			var k = Math.pow(10, decimals);
531			return '' + Math.round(n * k) / k;
532		};
533	
534	// Fix for IE parseFloat(0.55).toFixed(0) = 0;
535	s = (decimals ? toFixedFix(n, decimals) : '' + Math.round(n)).split('.');
536	if (s[0].length > 3) {
537		s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, thousands_sep);
538	}
539	
540	if ((s[1] || '').length < decimals) {
541		s[1] = s[1] || '';
542		s[1] += new Array(decimals - s[1].length + 1).join('0');
543	}
544	
545	return s.join(dec_point);
546}
547
548
549/**
550* increase quantity by 1 on left mouse click
551* decrease quantity by 1 on right mouse click
552* 
553* To use this function, you have to catch set the class "bind_cartqty" and use pegasos.bindings
554**/
555
556function doChangeQty (e, node) {
557
558	if(isNaN(node.value) || node.value==""){
559		var oldVal=0; 
560	} else{
561		var oldVal=parseInt(node.value);
562	}
563	if(e.which ==1){
564		if(oldVal == 0){
565			node.value=1;
566		} else{
567			node.value++;
568		}
569	}
570	if(e.which == 3){
571		if(oldVal <= 1){
572			node.value="";
573		} else {
574			node.value--;
575		}
576	}
577}
578
579/* get a cookie from the browser */
580function getCookieFromBrowser(c_name) {
581	var i,x,y,cookieArray=document.cookie.split(";");
582	
583	for (i=0;i<cookieArray.length;i++){
584	  x=cookieArray[i].substr(0,cookieArray[i].indexOf("="));
585	  y=cookieArray[i].substr(cookieArray[i].indexOf("=")+1);
586	  x=x.replace(/^\s+|\s+$/g,"");
587	  if (x==c_name){
588		return unescape(y);
589	  }
590	}
591}
592
593function getURLParameter(param)
594{
595    var pageURL = window.location.search.substring(1);
596    var urlVariables = pageURL.split('&');
597    for (var i = 0; i < urlVariables.length; i++) 
598    {
599        var parameterName = urlVariables[i].split('=');
600        if (parameterName[0] == param) 
601        {
602            return parameterName[1];
603        }
604    }
605}
606
607//For global usage this utils object is add to pegasos in lib pegasos_core since 1.1
608var utils = {}
609
610utils.EmailValidatorConst = new (function(){
611	var regex = /^([+-_.A-Za-z0-9])+\@(([-0-9A-Za-z])+\.)+([a-zA-Z0-9]{2,6})+$/;
612
613	this.getRegex = function() {
614		return regex;
615	}
616})();
617
618/**
619 * Simple email validator with regex from stackoverflow.com(see: utils.EmailValidatorConst).
620 * usage:
621 *      var email = "[email protected]";
622 * 	var validator = new [pegasos.]utils.EmailValidator(email);
623 *	console.log(validator.isValid()); //prints "false"
624 *
625 *      var email = "123456";
626 * 	var validator = new [pegasos.]utils.EmailValidator(email);
627 *	console.log(validator.isValid()); //prints "false"
628 */
629utils.EmailValidator = function (email) {
630	var email = email || "";
631	var regex = utils.EmailValidatorConst.getRegex();
632	
633	this.isValid = function() {
634		return regex.test(email);	
635	}
636	
637}
638
639/*
640 * Diese Funktion wechselt eine Klasse wirklich nur dann wenn die zu ersetzende Klasse existiert.
641 */
642utils.switchClass = function switchClass($element, removeClass, addClass) {
643	if($element.hasClass(removeClass)) {
644		$element.removeClass(removeClass);
645		if(!$element.hasClass(addClass)) {
646			$element.addClass(addClass);
647		}
648	}
649}
650
651utils.isIE = function() {
652	return /MSIE/.test(navigator.userAgent);
653};
654
655
656utils.isPseudoInvalidSupported = function() {
657
658	if (typeof (utils.pseudoInvalidSupported) === "undefined") {
659		try {
660			$("body").is(":invalid");//not supported for IE9
661			utils.pseudoInvalidSupported = true;
662		}
663		catch (err) {
664			utils.pseudoInvalidSupported = false;
665		}
666	}
667
668	return utils.pseudoInvalidSupported;
669}
670
671
672/* Setzt für eine Gruppe von Objekten eine Einheitliche Höhe, ausgehend von dem Objekt mit der Größten Höhe 
673 * Die Höhe wird für alle Elemente in einer Reihe ausgeführt*/
674utils.equalHeightPerRow  = function($groupList) {
675	
676	if ($groupList == undefined && $groupList.length < 1) {
677		return;
678	}
679	var rowcount = 0;
680	
681	$groupList.each(function(){
682	
683		var $$ = $(this);
684
685		$$.height("auto");
686		var hasNext = $$.next().length > 0;
687
688		if($$.prev().length > 0){
689			var isNextRow = $$.position().top !== $$.prev().position().top;
690			if(isNextRow){
691				utils._helper.equalHeightPerRow.doEqualHeight(rowcount);
692				rowcount++;
693			}
694			else if( !hasNext){					
695				utils._helper.equalHeightPerRow.setClasses($$,rowcount);			
696				utils._helper.equalHeightPerRow.doEqualHeight(rowcount);
697				rowcount++;
698			}
699		}      
700		if (hasNext) {
701			utils._helper.equalHeightPerRow.setClasses($$,rowcount);
702		}
703	});
704};
705
706utils._helper = {};
707		
708utils._helper.equalHeightPerRow = {};
709
710utils._helper.equalHeightPerRow.setClasses = function($element,rowcount) {
711	$element.addClass("equalheight");
712	$element.removeClass (function (index, css) {
713		return (css.match (/\group-\S+/g) || []).join(' ');
714	});
715
716	$element.addClass("group-" + rowcount);
717};
718	
719utils._helper.equalHeightPerRow.doEqualHeight = function(rowcount) {
720	equalHeight($(".equalheight.group-" + rowcount));
721};

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.