/* //////////////////////////////////////////////////////////////// // // UI JavaScript Funktionen // // Weblication CMS // erstellt durch Scholl Communications AG, 77694 Kehl, www.scholl.de // erstellt mit Weblication Content Management System, www.weblication.de // //////////////////////////////////////////////////////////////// */ devicePixelRatio = window.devicePixelRatio || 1; hdLimitDpr = 2; jQuery(document).ready(function(){ wUiTmp = {}; wCssClassesToAddGlobal = typeof(wCssClassesToAddGlobal) != 'undefined' ? wCssClassesToAddGlobal : {}; wCssEventsToAddGlobal = typeof(wCssEventsToAddGlobal) != 'undefined' ? wCssEventsToAddGlobal : {}; wCssJQuery = typeof(wCssJQuery) != 'undefined' ? wCssJQuery : {}; wCssDOM = typeof(wCssDOM) != 'undefined' ? wCssDOM : {}; wMediaqueriesToAddGlobal = typeof(wMediaqueriesToAddGlobal) != 'undefined' ? wMediaqueriesToAddGlobal : {}; var htmlAdditionalClasses = ''; if(/mobile/i.test(navigator.userAgent)) htmlAdditionalClasses += ' mobile'; if(/iPad/i.test(navigator.userAgent)) htmlAdditionalClasses += ' ipad'; if(/iPhone/i.test(navigator.userAgent)) htmlAdditionalClasses += ' iphone'; if(/iPod/i.test(navigator.userAgent)) htmlAdditionalClasses += ' ipod'; if(/(iPod|iPhone|iPad)/i.test(navigator.userAgent)){ htmlAdditionalClasses += ' ios'; if(/CriOs/i.test(navigator.userAgent)){ htmlAdditionalClasses += ' crios'; } else if(/Safari/i.test(navigator.userAgent)){ htmlAdditionalClasses += ' saios'; } } htmlAdditionalClasses += (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch ? ' touch' : ' no-touch'); if(document.documentElement){ if(document.documentElement.getAttribute('lang')) htmlAdditionalClasses += ' lang-' + document.documentElement.getAttribute('lang'); document.documentElement.className = (document.documentElement.className.replace('no-js', '') + ' js' + htmlAdditionalClasses).replace(/^\s+/, ''); } if(typeof(wEditor) == 'undefined'){ document.documentElement.className = document.documentElement.className.replace('weditor', '') + ' no-weditor'; } else{ document.documentElement.className = document.documentElement.className.replace('no-weditor', '') + ' weditor'; } if(document.cookie.indexOf('websitezoom=l') != -1){ document.body.className = document.body.className + ' zoom-l'; } for(var addClassSelector in wCssClassesToAddGlobal){ jQuery(addClassSelector).each(function(index){ var classesToAdd = wCssClassesToAddGlobal[addClassSelector]; for(var i = 0, arrayLength = classesToAdd.length; i < arrayLength; i++){ var classData = classesToAdd[i].split('='); if(classData.length == 2){ var selector = jQuery.trim(classData[0]); if(selector == '.'){ jQuery(this).addClass(jQuery.trim(classData[1])); } else if(selector == 'parent'){ jQuery(this).parent().addClass(jQuery.trim(classData[1])); } else{ jQuery(this).find(selector).addClass(jQuery.trim(classData[1])); } } else{ jQuery(this).addClass(jQuery.trim(classData[0])); } } }); } jQuery('*[data-w-addclasses]').each(function(index){ var classesToAdd = jQuery(this).data('w-addclasses').split(','); jQuery(this).removeAttr('data-w-addclasses'); for(var i = 0, arrayLength = classesToAdd.length; i < arrayLength; i++){ var classData = classesToAdd[i].split('='); var selector = jQuery.trim(classData[0]); if(selector == '.'){ jQuery(this).addClass(jQuery.trim(classData[1])); } else{ jQuery(this).find(selector).addClass(jQuery.trim(classData[1])); } } }); for(var addEventSelector in wCssEventsToAddGlobal){ jQuery(addEventSelector).each(function(index){ var eventsToAdd = wCssEventsToAddGlobal[addEventSelector]; for(var i = 0, arrayLength = eventsToAdd.length; i < arrayLength; i++){ var eventData = eventsToAdd[i].split('='); if(eventData.length == 2){ var eventType = jQuery.trim(eventData[0]).replace(/^on/, ''); var eventFunction = jQuery.trim(eventData[1]); jQuery(this).bind(eventType, (new Function('event', eventFunction + '(this, event.originalEvent);'))); } } }); } for(var wCssJQueryEntry in wCssJQuery){ jQuery(wCssJQueryEntry).each(function(index){ eval(wCssJQuery[wCssJQueryEntry]['jQuery']); }); } for(var wCssDOMEntry in wCssDOM){ jQuery(wCssDOMEntry).each(function(index){ domActions = {'prependto' : 'prependTo', 'appendto' : 'appendTo', 'insertbefore' : 'insertBefore', 'insertafter' : 'insertAfter'}; if(/^(\w+)\(/.test(wCssDOM[wCssDOMEntry]['path'])){ eval('jQuery(this).' + domActions[wCssDOM[wCssDOMEntry]['action'].toLowerCase()] + '(jQuery(this).' + wCssDOM[wCssDOMEntry]['path'] + ');'); } else{ if(wCssDOM[wCssDOMEntry]['action'] == 'prependto'){ jQuery(this).prependTo(wCssDOM[wCssDOMEntry]['path']); } else if(wCssDOM[wCssDOMEntry]['action'] == 'appendto'){ jQuery(this).appendTo(wCssDOM[wCssDOMEntry]['path']); } else if(wCssDOM[wCssDOMEntry]['action'] == 'insertbefore'){ jQuery(this).insertBefore(wCssDOM[wCssDOMEntry]['path']); } else if(wCssDOM[wCssDOMEntry]['action'] == 'insertafter'){ jQuery(this).insertAfter(wCssDOM[wCssDOMEntry]['path']); } } }); } jQuery('body').append('
'); for(var wMediaqueryToAddGlobal in wMediaqueriesToAddGlobal){ jQuery('#wMediaqueriesTmp').append('
'); } jQuery('label').each(function(index){ var nameFor = jQuery(this).attr('for'); if(nameFor && nameFor != ''){ var currentForm = jQuery(this).closest('form'); var elementFor = currentForm.get(0).elements[nameFor]; if(elementFor && typeof(elementFor.getAttribute('placeholder')) == 'string' && (elementFor.className.indexOf('wglIsInvalid') == -1 || elementFor.value == '')){ if(typeof(elementFor.placeholder) != 'undefined'){ jQuery(this).css({'display' : 'none'}); } } } }); jQuery(window).load(function(){ jQuery("img[data-src2x]:not(.wglLazyLoadInit)").each(function(){ var currentImg = jQuery(this); if(devicePixelRatio >= hdLimitDpr && typeof(currentImg.attr('data-src2x')) != 'undefined' && currentImg.attr('width') < currentImg.width() * 2){ currentImg.attr('src', currentImg.data('src2x')); } }); }); jQuery(window).bind('load resize scroll', function(){ var winScrollTop = jQuery(window).scrollTop(); var winHeight = jQuery(window).height(); jQuery('img.wglLazyLoadInit').each(function(index){ var currentImg = jQuery(this); var offsetTop = parseInt(currentImg.offset().top); if(offsetTop < winScrollTop + winHeight){ if(devicePixelRatio >= hdLimitDpr && typeof(currentImg.attr('data-src2x')) != 'undefined' && currentImg.attr('width') < currentImg.width() * 2){ currentImg.attr('src', currentImg.data('src2x')); } else if(typeof(currentImg.attr('data-src')) != 'undefined'){ currentImg.attr('src', currentImg.data('src')); } currentImg.removeClass('wglLazyLoadInit'); } }); }); jQuery(window).bind('load resize', function(){ jQuery('#wMediaqueriesTmp > div').each(function(index){ if(window.getComputedStyle){ var computedStyle = window.getComputedStyle(jQuery(this).get(0)); var fontFamily = computedStyle.fontFamily.replace(/"/g, ''); var lastMediaQuery = jQuery(this).data('lastmediaquery') || ''; if(fontFamily != lastMediaQuery){ //console.log(fontFamily + ' != ' + lastMediaQuery + ' :' + fontFamily.indexOf('mediaquery_')); if(fontFamily.indexOf('mediaquery_') == 0){ eval('if(typeof(' + fontFamily + '_onactivate) == \'function\'){' + fontFamily + '_onactivate();}'); } else if(lastMediaQuery.indexOf('mediaquery_') == 0){ eval('if(typeof(' + lastMediaQuery + '_ondeactivate) == \'function\'){' + lastMediaQuery + '_ondeactivate();}'); } jQuery(this).data('lastmediaquery', fontFamily); } } }); }); jQuery(window).bind('load resize', function(){ jQuery('.wglExpandToHeighestChild').each(function(index){ var currentElement = jQuery(this); var maxHeight = 0; currentElement.children('*').each(function(index){ if(jQuery(this).outerHeight(true) > maxHeight){ maxHeight = jQuery(this).outerHeight(true); } }); currentElement.css('height', String(maxHeight) + 'px'); }); jQuery('.wglAdjustHeightMax').each(function(index){ var currentElement = jQuery(this); var offsetLeft = 0; var maxHeight = 0; var adjust = true; var positionCol = 0; var childsToAdapt = new Array(); var numberChilds = 0; currentElement.children('*').each(function(index){ var className = jQuery(this).attr('class') || ''; if(className.toLowerCase().indexOf('clear') == -1 && className.toLowerCase().indexOf('editor') == -1){ numberChilds++; } }); currentElement.children('*').each(function(index){ var className = jQuery(this).attr('class') || ''; if(className.toLowerCase().indexOf('clear') == -1 && className.toLowerCase().indexOf('editor') == -1){ if(jQuery(this).data('wHasSetHeightToAjustHeightMax') == '1'){ jQuery(this).css({'height' : ''}); } offsetLeft = jQuery(this).get(0).offsetLeft - jQuery(this).get(0).parentNode.offsetLeft; if(index > 0 && offsetLeft == 0){ if(positionCol == 1){ childsToAdapt = new Array(); maxHeight = 0; } positionCol = 0; } positionCol++; if(numberChilds - index == 1){ maxHeight = jQuery(this).outerHeight() > maxHeight ? jQuery(this).outerHeight() : maxHeight; childsToAdapt.push(jQuery(this)); } //console.log(index + ', ' + positionCol + ', ' + numberChilds + ', ' + index + ', ' + childsToAdapt.length); //console.log(maxHeight); if(childsToAdapt.length > 1 && (index > 0 && positionCol == 1 || numberChilds - index == 1)){ for(i = 0; i < childsToAdapt.length; i++){ childToAdapt = childsToAdapt[i]; var className = childToAdapt.attr('class') || ''; if(className.toLowerCase().indexOf('clear') == -1 && className.toLowerCase().indexOf('editor') == -1 ){ childToAdapt.css({'height' : maxHeight}); childToAdapt.data('wHasSetHeightToAjustHeightMax', '1'); } } childsToAdapt = new Array(); maxHeight = 0; } maxHeight = jQuery(this).outerHeight() > maxHeight ? jQuery(this).outerHeight() : maxHeight; childsToAdapt.push(jQuery(this)); } }); }); }); jQuery('.wglAddScrollTop').each(function(index){ var currentElement = jQuery(this); if(currentElement.context.tagName.toLowerCase() == 'body'){ currentElement.append('
200){ jQuery('#scrollTop').fadeIn(); } else{ jQuery('#scrollTop').fadeOut(); } }); }); jQuery('.wglAddFontResizer').each(function(index){ var currentElement = jQuery(this); currentElement.prepend('
AA'); } }); } jQuery('.wglClickable').css({'cursor': 'pointer'}); jQuery(window).bind('load', function(){ jQuery('.wglOverflowXTouch').each(function(index){ var currentElement = jQuery(this); var widthOuter = currentElement.width(); var widthInner = currentElement.children('*').outerWidth(); if(widthInner <= widthOuter){ return false; } else{ var lastElementInner = currentElement.children('*').children('*:last'); var offsetRightLastElementInner = lastElementInner.get(0).offsetLeft + lastElementInner.outerWidth() + parseInt(lastElementInner.css('margin-right')); currentElement.children('*').children('*').each(function(index){ jQuery(this).css('width', jQuery(this).width()); }); lastElementInner.parent().css({'width' : String(offsetRightLastElementInner) + 'px'}) } jQuery(this).find('img').attr('unselectable', 'on'); jQuery('body').bind('touchstart mousedown', function(event){ if(jQuery(event.target).closest(currentElement).length != 0){ event.preventDefault(); } }); jQuery('body').bind("touchmove mousemove", function(event){ if(jQuery('body').data('wtouchelement')){ var mouseXDiff = (event.originalEvent.touches ? event.originalEvent.touches[0].pageX : event.pageX) - jQuery('body').data('wtouchmousex'); var mouseYDiff = (event.originalEvent.touches ? event.originalEvent.touches[0].pageY : event.pageY) - jQuery('body').data('wtouchmousey'); jQuery('body').data('wtouchmousex', event.originalEvent.touches ? event.originalEvent.touches[0].pageX : event.pageX); jQuery('body').data('wtouchmousey', event.originalEvent.touches ? event.originalEvent.touches[0].pageY : event.pageY); jQuery('body').data('wtouchlastdiffx', mouseXDiff); jQuery('body').data('wtouchlastdiffy', mouseYDiff); var milliseconds = (new Date()).getTime(); var timeDiff = milliseconds - jQuery('body').data('timestamplast'); jQuery('body').data('timestampbefore', jQuery('body').data('timestamplast')); jQuery('body').data('timestamplast', milliseconds); var speedX = Math.round(100 * (mouseXDiff > 0 ? mouseXDiff : -mouseXDiff) / timeDiff) + 1; jQuery('body').data('wtouchspeedX', speedX); var touchDiffX = jQuery('body').data('wtouchmousex') - jQuery('body').data('wtouchstartmousex'); jQuery('body').data('wtouchdiffx', touchDiffX); var widthOuter = parseInt(jQuery('body').data('wtouchelement').width()); var left = parseInt(jQuery('body').data('wtouchelement').children('*').css('margin-left')); left = isNaN(left) ? 0 : left; var right = parseInt(jQuery('body').data('wtouchelement').width()) - parseInt(jQuery('body').data('wtouchelement').children('*').css('margin-left')) - jQuery('body').data('wtouchelement').children('*').width(); right = isNaN(right) ? 0 : right; if(left > 32){ jQuery('body').data('wtouchelement').children('*').animate({'margin-left' : 0}); jQuery('body').removeData('wtouchelement'); return false; } else if(right > 32){ jQuery('body').data('wtouchelement').children('*').animate({'margin-left' : String(parseInt(jQuery('body').data('wtouchelement').width()) - parseInt(jQuery('body').data('wtouchelement').children('*').width())) + 'px'}); jQuery('body').removeData('wtouchelement'); return false; } if(jQuery('body').data('wtouchelement').data('wtouchstartmarginleft') + touchDiffX < 0){ jQuery('body').data('wtouchelement').children('*').css({'margin-left' : String(jQuery('body').data('wtouchelement').data('wtouchstartmarginleft') + touchDiffX) + 'px'}); } else{ jQuery('body').data('wtouchelement').children('*').css({'margin-left' : String(jQuery('body').data('wtouchelement').data('wtouchstartmarginleft') + touchDiffX) + 'px'}); } } }); jQuery(this).bind('touchstart mousedown', function(event){ jQuery(this).children('*').stop(); jQuery('body').data('wtouchelement', jQuery(this)); jQuery(this).data('wtouchstartmarginleft', parseInt(jQuery(this).children('*').css('margin-left'))); jQuery(this).data('wtouchstartmargintop', parseInt(jQuery(this).children('*').css('margin-top'))); jQuery('body').data('wtouchstartmousex', event.originalEvent.touches ? event.originalEvent.touches[0].pageX : event.pageX); jQuery('body').data('wtouchstartmousey', event.originalEvent.touches ? event.originalEvent.touches[0].pageY : event.pageY); }); jQuery('body').bind("touchend mouseup", function(event){ if(jQuery('body').data('wtouchelement')){ var milliseconds = (new Date()).getTime(); var timeDiff = milliseconds - jQuery('body').data('timestamplast'); var touchDiffX = jQuery('body').data('wtouchdiffx'); var lastDiffX = jQuery('body').data('wtouchlastdiffx'); var lastDiffXn = lastDiffX >= 0 ? lastDiffX : -lastDiffX; if(lastDiffXn > 1){ var speedX = (Math.round((lastDiffXn > 0 ? lastDiffXn : -lastDiffXn) / timeDiff) + 1) * 5; if(speedX > 200){ speedX = 200; } var movingWidth = Math.round(touchDiffX * 2 * (1 + speedX / 100)); if(jQuery('body').data('wtouchdiffx') < 0){ var right = parseInt(jQuery('body').data('wtouchelement').width()) - parseInt(jQuery('body').data('wtouchelement').children('*').css('margin-left')) - jQuery('body').data('wtouchelement').children('*').width(); if(movingWidth < right){ movingWidth = right; } var duration = (movingWidth > 0 ? movingWidth : -movingWidth) * 1.5 + Math.round(100 / speedX); jQuery('body').data('wtouchelement').children('*').animate({'margin-left' : '+=' + String(movingWidth)}, {'duration' : duration, 'easing' : 'wEaseOutScroll'}); } else{ var left = parseInt(jQuery('body').data('wtouchelement').children('*').css('margin-left')); if(-movingWidth < left){ movingWidth = -left; } var duration = (movingWidth > 0 ? movingWidth : -movingWidth) * 1.5 + Math.round(100 / speedX); jQuery('body').data('wtouchelement').children('*').animate({'margin-left' : '+=' + String(movingWidth)}, {'duration' : duration, 'easing' : 'wEaseOutScroll'}); } } jQuery('body').removeData('wtouchelement'); } }); }); }); }); jQuery.extend(jQuery.easing, { wEaseOutScroll: function(x, t, b, c, d){ return (t == d) ? b + c : b + c * (-Math.pow(1.5, -20 * t / d) + 1); } });