Skip to content

Instantly share code, notes, and snippets.

@eFrane
Created August 13, 2012 19:08
Show Gist options
  • Save eFrane/3343337 to your computer and use it in GitHub Desktop.
Save eFrane/3343337 to your computer and use it in GitHub Desktop.
jQuery CSS "router" (inspired by github.com/headjs/headjs)
$.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