Created
December 8, 2012 18:47
-
-
Save tjFogarty/4241319 to your computer and use it in GitHub Desktop.
Do things with the page name
This file contains 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
var Page = { | |
getPageName: function() { | |
var pageName = document.URL.split( '/' ).pop(); | |
if( !pageName ) { | |
pageName = $( 'ul.menu li:first-child a' ).attr( 'href' ); | |
} | |
return pageName; | |
}, | |
isMobile: function() { | |
if( $(window).width() < 767 ) { | |
return true; | |
} else { | |
return false; | |
} | |
}, | |
getPageType: function( pageName ) { | |
return pageName.split( '.' ).pop(); | |
}, | |
enableMobileNav: function( toggleButton, navigation ) { | |
toggleButton.on( 'click', function() { | |
navigation.slideToggle(); | |
}); | |
}, | |
getNavItems: function() { | |
var nav = [], | |
navAnchorTags = $( 'nav ul li a' ); | |
navAnchorTags.each( function() { | |
nav.push( $(this).text().toLowerCase() ); | |
}); | |
return nav; | |
}, | |
setActive: function( pageName ) { | |
$( 'a[href="' + pageName + '"]' ).addClass( 'active' ); | |
pageName = pageName.slice( 0, pageName.lastIndexOf('.') ); | |
$( 'body' ).addClass( pageName ); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment