Skip to content

Instantly share code, notes, and snippets.

@tkh44
Created July 10, 2012 18:05
Show Gist options
  • Save tkh44/3085196 to your computer and use it in GitHub Desktop.
Save tkh44/3085196 to your computer and use it in GitHub Desktop.
active page
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