Created
August 13, 2012 19:08
-
-
Save eFrane/3343337 to your computer and use it in GitHub Desktop.
jQuery CSS "router" (inspired by github.com/headjs/headjs)
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
$.each(location.pathname.split('/'), function(key, section) { | |
var id = section || (key === 0) ? "index" | |
: location.pathname.split('/')[key-1]; | |
var index = section.indexOf('.'); | |
if (index > 0) id = id.substring(0, index); | |
$('html').attr('id', id+'-page'); | |
// CSS classes must not begin with a number... | |
var numericModifier = (!isNaN(parseFloat(section)) && isFinite(section)) ? 'd' : ''; | |
if (section.length > 0) $('html').addClass(numericModifier + section + '-section'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment