if (!(window.initialTab)) {var initialTab;} var doStoreTab = typeof(doStoreTab) != 'undefined' ? doStoreTab : false; EventDispenser = Class.create(); EventDispenser.prototype = { initialize: function(list) { this.list = list; this.activateTabObserver = this.activateTab.bindAsEventListener(this); $$(this.list + " li").each(function(item) { //Add observer Event.observe(item, 'click', this.activateTabObserver, false); //Show only initialTab content if (item.id == initialTab) { $(item.id).addClassName("active"); var activeTabSpike = Builder.node('div',{className:'activeTabSpike'}); $(item.id).appendChild(activeTabSpike); if ($(item.id+'_content')) {$(item.id+'_content').style.display="block";} } else { if ($(item.id+'_content')) {$(item.id+'_content').style.display="none";} } if ($('tabsContent')) {$('tabsContent').style.display="block";} }.bind(this)); }, activateTab: function(event, what) { // Take the tab from either the event or a specified var: if (what!=undefined) { var tab = what; } else { var tab = (Event.element(event).parentNode.id); } // Apply active class + show/hide active tab_content for each tab, or follow link if tab_content not found $$(this.list + " li").each(function(item) { if (item.id == tab){ //If not already active: if (!(item.hasClassName("active") && $(item.id+'_content').visible()) ) { item.addClassName("active"); // Add active tab spike if not present: if (!item.down('div.activeTabSpike')){ var activeTabSpike = Builder.node('div',{className:'activeTabSpike'}); item.appendChild(activeTabSpike); } if ( $(item.id+'_content') ) { var tmp = new Effect.Appear($(item.id+'_content'), {duration:0.4}); console.debug('doStoreTab: ' + doStoreTab); if (doStoreTab) storeTab(item.id); //Update the cookie } else { var tabLink = $(item.id).getElementsByTagName("A")[0].href; if (tabLink!=='' && tabLink!==null && tabLink!==undefined && tabLink!='javascript:void(0)') { if ($('tabsContent')) {$('tabsContent').innerHTML='Loading...';} document.location.href=tabLink; } } } } else { $(item.id).removeClassName("active"); // Remove active tab spike: if ($(item.id).getElementsBySelector('div.activeTabSpike')[0]) { $(item.id).getElementsBySelector('div.activeTabSpike')[0].remove(); } //If new tab_content doesn't exist, don't fade current content (e.g. pers. panel before login) if ( $(tab+'_content') ) { if ($(item.id+'_content')) { tmp = new Effect.Fade($(item.id+'_content'), {duration:0.2}); } } } }.bind(this)); if (event!=='' && event!==null) { //Stops default link action, but allows initial load event to continue. Event.stop(event); } } } function storeTab(tab) { console.debug('Storing '+ tab +' tab'); var tabName = $('tabs').id; if (tabName!=='' && tabName!==null) { eraseCookie(tabName); setCookie(tabName,tab,1); } } function getStoredTab() { return getCookie($('tabs').id); } document.observe("dom:loaded", function() { // If initial value not set, try to find stored tab. if (!initialTab || initialTab=='') { initialTab = initialTab ? initialTab : window.initialTab ? window.initialTab : getStoredTab(); doStoreTab=true; } // No stored tab found, set first child tab as initialTab. if (!initialTab || initialTab === '') initialTab = $('tabs').down('ul').firstDescendant().id; //console.info('Initial tab set: ' + initialTab); var tabsBar = new EventDispenser('#tabs'); $$('a.changeTab').each(function(link){ Event.observe(link, 'click', function(event){ tabsBar.activateTab(event, link.rel); }) }); });