/** * DekaBank JavaScript * Copyright (c) 2009, namics (deutschland) gmbh. All rights reserved. * Code licensed under the MIT License: * http://www.opensource.org/licenses/mit-license.php */ var DEKA = { // Key definitions key_tab: 9, key_enter: 13, key_esc: 27, key_space: 32, key_pageup: 33, key_pagedown: 34, key_end: 35, key_home: 36, key_left: 37, key_up: 38, key_right: 39, key_down: 40, key_minus: 86, key_plus: 93, key_add: 132, key_substract: 140, volume: Array(), aGlossaryTime: Array(), swfParams: { allowScriptAccess:'sameDomain', menu:'false', quality:'high', salign:'lt', scale:'noScale', wmode:'transparent' }, // Initialize init: function() { // Show items that are only available with JavaScript, add class "small" | "wide" if there's (not) enough room DEKA.addClassToBody(); // Show page functions if available DEKA.showPageFunctions(); // Setup for accordion menus DEKA.accordionInit(); // Init tablists DEKA.tablistInit(); // Set event listeners to input elements with default text $( 'input.hasDefault' ).blur( DEKA.inputDefaults ).focus( DEKA.inputDefaults ).click( DEKA.inputDefaults ); // Set event listeners to market buttons $( '.marketbuttons button' ).bind( 'mouseover mouseout focus blur', DEKA.marketHover ).click( DEKA.marketClick ); // Set event listener on contact form select $( 'select.ctype' ).bind( 'focus blur change', DEKA.onContactTypeChange ); $( 'button.downloadbuttonmarker' ).bind('click', DEKA.checkDownloadTicked ); // Set focus on glossary item DEKA.setGlossaryFocus(); // Add abbr element in IE 6-7 document.createElement('abbr'); // Ignore annoying tooltips for alt text in IE $( 'img' ).not( '[title]' ).attr( 'title', '' ); // Add pseudo hover to buttons DEKA.initIEButtonHover(); // Add proprietary way to add rounded corners if ( typeof isVML !== 'undefined' ) { // Add rounded corners DEKA.ieRoundedCorner(); } // Configure lightbox DEKA.configLightbox(); // Embed audioplayers via swf-object DEKA.addAudioPlayers(); // Load glossary items DEKA.setInfoListeners(); DEKA.loadGlossaryTerms(); // Init foldout linklists DEKA.foldOutInit(); DEKA.goToSelect(); $('a.expand').click(function(){ var href = $( this ).attr("href"); $(href).slideToggle("slow"); return false; }); $('#content a.switchTab').click(function(event){ var $item = $(event.target); var hash = $item.attr('href').replace(/#t/, "#ti"); DEKA.tabClick(null, $(hash)); }); }, // Show items that are only available with JavaScript addClassToBody: function() { var aClass = $( 'body' ).attr( 'class' ).match( /(home|podcasts|search)/i ); var sAddClass = ( aClass ) ? aClass[1] : ''; $( 'body' ).attr( 'class', 'js ' + sAddClass ); }, // Show page functions: print, tell-a-friend, bookmark showPageFunctions: function() { // Print button if ( typeof window.print !== 'undefined' ) { $( '#button-print' ).click( function() { window.print(); } ).parent().removeClass( 'inactive' ); } // Bookmark button if ( window.external && typeof window.external.AddFavorite !== 'undefined' ) { $( '#button-bookmark' ).click( function(){ window.external.AddFavorite( location.href, document.title ); } ).parent( 'li' ).removeClass( 'inactive' ); } $( '#sfunktionen button' ).click( function() { this.blur(); } ); }, // Accordion setup accordionInit: function() { var acc = $( '.accordion' ); var oButton = $( 'button.control' ); oButton.attr( DEKA.nTabindex(), '0' ).each( function (i) { $( this ).attr( 'aria-controls', this.id.replace(/(button-)(.*)/, "acc-$2") ); } ); if ( acc[0] && acc[0].addEventListener ) { acc.each( function ( i ) { // Add event listeners for decent browsers acc[i].addEventListener( 'click', DEKA.accordionClick, true ); acc[i].addEventListener( 'keydown', DEKA.accordionClick, false ); }); } // Add event listener for IE else if ( acc[0] && acc[0].attachEvent ) { oButton.bind( 'click', DEKA.accordionClick ).keydown( DEKA.accordionClick ); } }, // Click on accordion control element accordionClick: function( e ) { // Normalize event object if ( typeof e.type !== 'undefined' ) { var event = e || window.event; } else { return false; } // Set variables var oKey = new DEKA.KeyObject( event ); // Fix for WebKit, traverse to parent button element if ( oKey.oTarget.nodeName.toLowerCase() === 'span' ) { oKey.oTarget = oKey.oTarget.parentNode; } var jqTarget = $( oKey.oTarget ); var sType = event.type, nodeName = oKey.oTarget.nodeName.toLowerCase(); // Do something when the target is a control button if ( nodeName === 'button' && jqTarget.hasClass( 'control' ) && ( sType === 'keydown' || sType === 'click' ) ) { // Click is triggered on mouseclick, enter or space key if ( sType === 'click' ) { // Open accordion panel jqTarget.toggleClass('aOpen').next().slideToggle('fast', function(){ // Set aria-expanded attribute true | false DEKA.ariaExpandToggle( jqTarget ); }); // Update screenreader buffer DEKA.updateBuffer(); // Prevent event bubbling DEKA.stopPropagation(event); return false; } // An arrow key was pressed without the alt-key else if ( oKey.bArrowKeys ) { // Catch all siblings before and after button var prev = jqTarget.prevAll( 'button.control' ), next = jqTarget.nextAll( 'button.control' ), oFocus; // Reference to the correct arrays of objects var fwd = ( oKey.iKey === DEKA.key_left || oKey.iKey === DEKA.key_up ) ? prev : next; var rev = ( oKey.iKey === DEKA.key_left || oKey.iKey === DEKA.key_up ) ? next : prev; // Get the element to set focus on var oFocus = ( fwd.length ) ? fwd[0] : ( rev.length ) ? rev[ rev.length - 1 ] : jqTarget; // Set focus oFocus.focus(); // Prevent event bubbling DEKA.stopPropagation(event); return false; } // Home or end key is pressed else if ( oKey.iKey === DEKA.key_home || oKey.iKey === DEKA.key_end ) { // Get all button children in the right order var children = $( this ).children( 'button.control' ); // Get the element to set focus on var oFocus = ( oKey.iKey === DEKA.key_home ) ? children[0] : children[ children.length - 1 ]; oFocus.focus(); // Prevent event bubbling DEKA.stopPropagation(event); return false; } } // Ctrl-Up within a panel moves focus to header else if ( sType === 'keydown' && oKey.bCtrlKey && oKey.iKey === DEKA.key_up ) { jqTarget.parents( '.acontent' ).prev().focus(); // Prevent event bubbling DEKA.stopPropagation(event); return false; } // Return if event happened on an irrelevant element or wrong key was pressed else { return; } }, // Set aria-expanded attribute ariaExpandToggle: function( jqObj ) { jqObj.next().attr( 'aria-expanded', jqObj.hasClass( 'aOpen' ) ).toggleClass( 'aOpen' ).find( 'div.glossary' ).hide(); }, // tablistInit: function() { var tabs = $( '.tabs' ); var oAnchor = $( '.tablist a' ); oAnchor.each( function (i) { $( this ).attr( 'aria-controls', this.href.replace(/.*(#)(.*)/, "$2") ).attr( 'href', this.href.replace(/.*(#tab-)(.*)/, '#t-' + "$2" ) ); } ).not( '.aOpen' ).attr( DEKA.nTabindex(), '-1' ); if ( tabs[0] && tabs[0].addEventListener ) { tabs.each( function ( i ) { // Add event listeners for decent browsers tabs[i].addEventListener( 'click', DEKA.tabClick, true ); tabs[i].addEventListener( 'keydown', DEKA.tabClick, false ); }); } // Add event listener for IE else if ( tabs[0] && tabs[0].attachEvent ) { oAnchor.bind( 'click', DEKA.tabClick ).keydown( DEKA.tabClick ); } // Set state if hash is present var iframe = document.getElementById( 'jquery-history-iframe' ); if ( location.hash !== '' || ( iframe && iframe.location.hash !== '' ) ) { sHref = ( iframe ) ? iframe.location.hash : location.hash; sHref = $( sHref.replace( /(#t-)(.*)/, "#ti-$2" ) ); DEKA.tabClick( '', sHref ); } }, // Click on a tab tabClick: function( e, obj ) { // Normalize event object if ( e && typeof e.type !== 'undefined' ) { var event = e || window.event; } else if ( !obj ) { return false; } // Set variables var oKey = ( event ) ? new DEKA.KeyObject( event ) : obj, jqTarget = ( obj ) ? obj : $( oKey.oTarget ), sType = ( obj ) ? 'click' : event.type, sId = jqTarget.attr( 'id' ); o = ( sId ) ? document.getElementById( sId ) : null; nodeName = ( o && o.nodeName ) ? o.nodeName.toLowerCase() : ''; if ( nodeName === 'a' && jqTarget.parent().parent().hasClass( 'tablist' ) && ( sType === 'keydown' || sType === 'click' ) ) { // Do something when the target isn't the anchor if (sType === 'click' && !jqTarget.hasClass('open')) { // Close tab panel var openTab = jqTarget.parent().siblings().find('a.open'), sOpenHref = openTab.attr('aria-controls'), sHref = jqTarget.attr('aria-controls'); openTab.removeClass('open clicked').attr(DEKA.nTabindex(), '-1'); $('#' + sOpenHref).removeClass('open').attr('aria-expanded', 'false').find( 'div.glossary' ).hide(); // Open tab panel var clicked = (event && event.type === 'click') ? ' clicked' : ''; jqTarget.addClass('open' + clicked).attr(DEKA.nTabindex(), '0'); $('#' + sHref).addClass('open').attr('aria-expanded', 'true'); // Set hash sHref = sHref.replace(/(tab\-)(.*)/, "t-$2"); DEKA.setHash( sHref ); // Set focus jqTarget.focus(); // Update screenreader buffer DEKA.updateBuffer(); // Prevent event bubbling DEKA.stopPropagation(event); return false; } // Move open tab with arrow keys else if (oKey.bArrowKeys) { // Catch all tabs before and after current tab var prev = jqTarget.parent().prevAll('li').find('a'), next = jqTarget.parent().nextAll('li').find('a'), oFocus; // Reference to the correct arrays of objects var fwd = (oKey.iKey === DEKA.key_left || oKey.iKey === DEKA.key_up) ? prev : next; var rev = (oKey.iKey === DEKA.key_left || oKey.iKey === DEKA.key_up) ? next : prev; // Get the element to set focus on var oFocus = (fwd.length) ? fwd[0] : (rev.length) ? rev[rev.length - 1] : jqTarget; DEKA.tabClick(event, $(oFocus)); // Prevent event bubbling DEKA.stopPropagation(event); return false; } } // Ctrl-Up within a panel moves focus to header else if ( sType === 'keydown' && oKey.bCtrlKey && oKey.iKey === DEKA.key_up ) { jqTarget.parents( '.tabs' ).find( '.tablist a.open' ).focus(); // Prevent event bubbling DEKA.stopPropagation( event ); return false; } // Return if event happened on an irrelevant element or wrong key was pressed else { return; } }, // Hover for market buttons on home page marketHover: function( e ) { if (isBadIE) { var obj = $(this); if (typeof e.type !== 'undefined') { var event = e || window.event; } if (event.type === 'mouseover' || event.type === 'focus') { obj.parent().addClass('hover'); } else { obj.parent().removeClass('hover'); } } }, // Click on a market button on home page: change image URL marketClick: function( e ) { var obj = $( this ); // Get image object var oImg = obj.parent().parent().siblings( '.marketgraph' ); oImg = oImg.children(); // Normalize event object if ( typeof e.type !== 'undefined' ) { var event = e || window.event; } if ( event.type === 'click' ) { obj.focus(); // Focus on button obj.parent().siblings().removeClass( 'hover clicked' ); // Remove highlight from other buttons obj.parent().addClass( 'hover clicked' ); // Set highlight on clicked button var val = obj.attr( 'class' ).replace( /\s(hover)/, '' ); // get the value from the class because IE6 doesn't get val() var param = ( val === 'rics' ) ? 'tabChart4=' : 'detailChart='; // set params var src = oImg.attr( 'src' ).replace( /(tabChart4|detailChart)\=.*/, param + val ); ( val === 'rics' ) ? oImg.css('width','190px') : oImg.css('width','180px'); oImg.attr( 'src', src ); // Replace image } }, // Select type change in contact form onContactTypeChange: function( e ) { // Normalize event object if ( typeof e.type !== 'undefined' ) { var event = e || window.event; } var obj = $( this ); var sVal = obj.find( ':selected' ).val(); var oContext = obj.parents( 'form' ); switch ( sVal ) { case '1': // Complaint oContext.find( 'fieldset.complaint' ).slideDown( 'fast' ); oContext.find( 'p.ombud' ).slideUp( 'fast' ); oContext.find( '#birthd_area' ).slideDown( 'fast' ); DEKA.updateBuffer(); break; case '6': // Ombudsmann oContext.find( 'p.ombud' ).slideDown( 'fast' ); oContext.find( 'fieldset.complaint' ).slideUp( 'fast' ); oContext.find( '#birthd_area' ).slideUp( 'fast' ); DEKA.updateBuffer(); break; default: oContext.find( 'p.ombud' ).slideUp( 'fast' ); oContext.find( 'fieldset.complaint' ).slideUp( 'fast' ); DEKA.updateBuffer(); break; } }, // Set focus on glossary items setGlossaryFocus: function() { var oTable = $( 'table.glossary' ); if ( oTable.length > 0 ) { if ( location.hash !== '' ) { $( location.hash ).addClass( 'focus' ); } if ( isBadIE ) { oTable.find( 'td' ).bind( 'mouseover mouseout focus blur click', DEKA.setGlossaryIEClass ); } } }, setGlossaryIEClass: function( e ) { // Normalize event object if (typeof e.type !== 'undefined') { var event = e || window.event; } if ( event.type === 'click' ) { $( this ).toggleClass( 'focus' ).parent().siblings().find( 'td' ).removeClass( 'focus' ); } else { $( this ).toggleClass( 'hover', event.type === 'mouseover' || event.type === 'focus' ); } }, // Toggle between input field defaults and selected input text inputDefaults: function( e ) { // Normalize event object if ( typeof e.type !== 'undefined' ) { var event = e || window.event; } else { return false; } // Get default value from hidden input element var sDefaultValue = $( '#' + this.id + '-default' ).val(); // If field is empty on blur, fill with default value if ( event.type === 'blur' && $( this ).val() === '' ) { $( this ).val( sDefaultValue ).addClass( 'default' ); return true; } // field is clicked on else if ( event.type === 'click' && $( this ).val() === sDefaultValue ) { $( this ).val( '' ).removeClass( 'default' ); return false; } // Field receives focus else if ( event.type === 'focus' ) { $( this ).select(); return true; } }, // Add :hover and :focus for buttons on IE initIEButtonHover: function() { if ( isBadIE ) { $( 'button' ).bind( 'mouseover focus', function() { $( this ).addClass('hover'); }).bind( 'mouseout blur', function() { $( this ).removeClass('hover'); }); } }, addAudioPlayers: function(){ if ( typeof swfobject !== 'undefined' ) { $('#content a.media-audio').each( function( i ) { var sId = $( this ).attr( 'id' ); var flashvars = { mediadata: $(this).attr('href'), autoplay: false, controlsbg: false // false = hide background }; var attributes = { id: sId }; swfobject.embedSWF( '/media/flash/DekaAudioPlayer.swf', sId, '205', '33', '9.0.124', '/media/expressInstall.swf', flashvars, DEKA.swfParams, attributes ); }); } }, // Rounded tab corners for IE ieRoundedCorner: function() { $( '.tablist li' ).each( function(i) { var obj = $( this ); // Create two containers var borderRadiusLeft = document.createElement( 'span' ), borderRadiusRight = document.createElement( 'span' ); borderRadiusLeft.className = 'borderRadiusLeft'; borderRadiusRight.className = 'borderRadiusRight'; obj.append( borderRadiusLeft ).append( borderRadiusRight ); } ); }, /**************************** * Glossary layer functions * ****************************/ // Dynamically load glossary terms loadGlossaryTerms: function() { $( 'a.glossary' ).each( function( i ) { var obj = $( this ), sHref = obj.attr( 'href' ), sId = '#g' + (i + 1); // Load glossary terms $.get( sHref, 'id=' + (i + 1), function( data ) { if ( data ) { obj.after( data ).attr( 'href', sId ); var oTarget = $( sId ); // Bind events obj.bind( 'mouseenter focus click', { target: oTarget, id: sId }, DEKA.displayGlossaryTerms ) .bind( 'blur mouseleave', { target: oTarget, id: sId }, DEKA.setGlossaryTimer ) .attr( 'aria-controls', sId ); } }); }); }, // Set the event listeners for the form info icons setInfoListeners: function() { $( 'a.info' ).each( function( i ) { var obj = $( this ), sId = obj.attr( 'href' ), oTarget = $( sId ); // Bind events obj.bind( 'mouseenter focus click', { target: oTarget, id: sId }, DEKA.displayGlossaryTerms ) .bind( 'blur mouseleave', { target: oTarget, id: sId }, DEKA.setGlossaryTimer ) .attr( 'aria-controls', sId ); }); }, // Show glossary term boxes displayGlossaryTerms: function( event ) { var oTarget = event.data.target, obj = $( this ); DEKA.clearGlossaryTimer( DEKA.aGlossaryTime[ event.data.id ] ); // Position the element aPosition = obj.position(); iMarginTop = obj.css( 'margin-top' ); iMarginTop = ( iMarginTop === 'auto' ) ? 0 : parseInt( iMarginTop ); aParentPos = ( obj.hasClass( 'info' ) ) ? obj.parent().position() : { 'top': 0, 'left': 0 }; if ( obj.attr( 'id' ) === '' ) { aPosition.top = parseInt( aPosition.top ) + 3 + parseInt( aParentPos.top ) + iMarginTop; aPosition.left = parseInt( aPosition.left + obj.width() ) + 12 + parseInt( aParentPos.left ); oTarget.css( { 'left': aPosition.left, 'top': aPosition.top } ); } // Fade-in of glossary box oTarget.fadeIn( 'fast' ) .bind( 'mouseenter focus', { target: oTarget, id: event.data.id }, DEKA.displayGlossaryTerms ) .bind( 'blur mouseleave', { target: oTarget, id: event.data.id }, DEKA.setGlossaryTimer ); if ( obj.attr( 'id' ) === '' && event.type === 'click' ) { return false; } }, // Set timeout setGlossaryTimer: function( event ) { // Clear old timeout DEKA.clearGlossaryTimer( DEKA.aGlossaryTime[ event.data.id ] ); // Set new timeout DEKA.aGlossaryTime[ event.data.id ] = setTimeout( function() { DEKA.hideGlossaryTerms( event.data.target ); }, 1200 ); }, // Clear glossary timeout variable clearGlossaryTimer: function( timeout ) { clearTimeout( timeout ); }, // Fade-out of glossary box hideGlossaryTerms: function( oTarget ) { var sId = oTarget.attr( 'id' ); // Fade-out oTarget.fadeOut( 'slow' ); }, /**************************** * General helper functions * ****************************/ stopPropagation: function ( event ) { if (event) { // Prevent scrolling if (event.stopPropagation) event.stopPropagation(); if (event.preventDefault) event.preventDefault(); event.cancelBubble = true; event.returnValue = false; return false; } }, // Create an object with all event properties KeyObject: function( event ) { var obj = { iKey: event.keyCode, bCtrlKey: event.ctrlKey, bAltKey: event.altKey, bShiftKey: event.shiftKey, bArrowKeys: (!event.altKey && (event.keyCode === DEKA.key_down || event.keyCode === DEKA.key_up || event.keyCode === DEKA.key_left || event.keyCode === DEKA.key_right)), bEnter: (!event.altKey && event.keyCode === DEKA.key_enter), oTarget: DEKA.getTarget( event ) } return obj; }, // Normalize tabindex attribute nTabindex: function() { return ( document.body && document.body.tabIndex === 0 ) ? 'tabIndex' : 'tabindex'; }, // Force screen reader buffer update updateBuffer: function() { if ( $( '#bufferUpdater' ).length === 0 ) { $( '#page' ).append( '
' ); } $( '#bufferUpdater' ).val( Math.random() ); }, // Return the event target element, not a text node getTarget: function( event, resolveTextNode ) { if (!event) return false; var t = event.target || event.srcElement; return t; }, // Set URI hash setHash: function( sHref ) { // Write hash if ( typeof window.location.hash !== 'undefined' ) { window.location.hash = sHref; } else { location.hash = sHref; } // Update IE<8 History if ( isBadIE ) { var iframe = $( '#jquery-history-iframe' ); if ( iframe.length === 0 ) { $('