var _CUR_TABS = []; var _TABS_ON_PAGE = []; var _TAB_DIVS_ON_PAGE = []; Behaviour.register({ 'ul.tabstrip': { initialize: function() { initTabstrip(this); if(window.ontabschanged) window.ontabschanged(); } } }); function initTabstrip(tabstrip, namedAnchors) { var i, anchor, container, anchorName, li; var childAnchors = tabstrip.getElementsByTagName('a'); var base, curTab = null, curURL = window.location.href; var previousTab = null; var firstTab, foundATab = false; // Strip query string from current URL var curQuery = window.location.search; // Detect a current tab from the # link if(curURL.indexOf('#') == -1) { base = curURL.length - curQuery.length; } else { base = curURL.indexOf('#') - curQuery.length; curTab = curURL.substr(curURL.indexOf('#')+1); } // Get a stored current tab, used when Ajax-switching between pages if(_CUR_TABS[tabstrip.parentNode.id] && $(_CUR_TABS[tabstrip.parentNode.id]) ) { curTab = _CUR_TABS[tabstrip.parentNode.id]; } else { // Default to showing the first tab for(i=0;i 1 ) anchorName = tabNames.shift() + 'set'; while( anchorName ) { if( _TABS_ON_PAGE[anchorName] ) _TABS_ON_PAGE[anchorName].openTab( _TABS_ON_PAGE[anchorName].getElementsByTagName('a')[0] ); if( tabNames.length == 0 ) anchorName = null; else { anchorName = anchorName + tabNames.shift() + 'set'; } } } /* * Returns the form object that the given element is * inside; or null if it's not inside a form */ function findParentForm(el) { var ownerForm = el.parentNode, tn; while((tn = ownerForm.tagName.toLowerCase()) != "body" && tn != "form") { ownerForm = ownerForm.parentNode; } if(tn == "form") return ownerForm; else return null; } function tabstrip_showTab(evt) { if(this.tagName.toLowerCase() == "a") var el = this.parentNode; else el = this; _CUR_TABS[el.tabstrip.parentNode.id] = el.container.id; if(el.tabstrip.currentlyShowing && el.tabstrip.currentlyShowing.container && el.tabstrip.currentlyShowing != el) { el.tabstrip.currentlyShowing.container.style.display = 'none'; removeClass(el.tabstrip.currentlyShowing.container, 'current'); removeClass(el.tabstrip.currentlyShowing, 'current'); } var container = document.getElementById( el.container.id ); if( container && container.style.display == 'none' ) { container.style.display = 'block'; addClass( container, 'current' ); } // el.container.style.display = ''; addClass(el, 'current'); el.tabstrip.currentlyShowing = el; setHashLink(el.anchorName); if(evt != 'init') { if(window.ontabschanged) window.ontabschanged(); else if(window.onresize) window.onresize(); } return false; } /* * Redirect to the given hash link * It won't actually reload the page, but it will update the current URL */ function setHashLink(hashLink) { return; //temporarily disabled this var preserveScroll = preserveScrollPosition(hashLink); // Mac/IE5 cannot handle this if(navigator.userAgent.indexOf("Mac") > -1 && navigator.userAgent.indexOf("MSIE") > -1) return; if(window.location.href.indexOf('#') == -1) window.location.href += '#' + hashLink; else window.location.href = window.location.href.replace(/#.*$/, '#' + hashLink); if(typeof preserveScroll != 'undefined') restoreScrollPosition(preserveScroll); } /** * Preserve the scroll position prior to visiting the given hashlink. * Returns an object that you can pass to restoreScrollPosition */ function preserveScrollPosition(hashLink) { var el = document.getElementById(hashLink); var preserved = []; while(el) { preserved[preserved.length] = el; el.oldScroll = el.scrollTop; if(el.tagName && el.tagName.toLowerCase() == "body") break; el = el.parentNode; } return preserved; } /* * Restores the preserved scroll position */ function restoreScrollPosition(preserved) { var i; for(i=0;i