Created
July 10, 2012 18:05
-
-
Save tkh44/3085196 to your computer and use it in GitHub Desktop.
active page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _setActivePageStyle(activeLinkEl) { | |
//If the active link is not an 'a' element, find it and use it. | |
if(activeLinkEl.tagName !== 'A') { | |
activeLinkEl = SELECT.query('a', activeLinkEl, true); | |
} | |
//show hidden active element by expanding it's parent category | |
if(activeLinkEl.parentNode.getAttribute('role') === 'page') { | |
var parentCategory = DOM.getAncestorByClassName(activeLinkEl, 'category'); | |
if(DOM.hasClass(parentCategory, 'collapsed')) { | |
DOM.replaceClass(parentCategory, 'collapsed', 'expanded'); | |
} | |
} | |
//Make sure we do not apply the active class twice so that animation(css3) goes smoothly | |
if (activeLinkEl === elements.activePage) { | |
return true; | |
} | |
clearActivePageStyle(); | |
//we have to set a timeout in order to properly animate when a hidden page is shown | |
window.setTimeout(function() { | |
DOM.addClass(activeLinkEl.parentNode, 'activePage'); | |
}, 1); | |
elements.activePage = activeLinkEl; | |
//saftey check to make sure the active link is in the viewport | |
if (!elementInViewport(activeLinkEl)) { | |
activeLinkEl.scrollIntoView(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment