Skip to content

Instantly share code, notes, and snippets.

@nathanaelnsmith
Last active November 23, 2023 09:52
Show Gist options
  • Save nathanaelnsmith/efc1ce2dd0b78db11632d47727361319 to your computer and use it in GitHub Desktop.
Save nathanaelnsmith/efc1ce2dd0b78db11632d47727361319 to your computer and use it in GitHub Desktop.
ES6 module implementation of Paul Irish's DOM based routing
import Router from './DomBasedRouter'
let routes = {
'common': {
init() {}
}
}
let router = new Router(routes);
router.load();
export default (routes) => {
return {
fire (func,funcname, args){
funcname = (funcname === undefined) ? 'init' : funcname;
if (func !== '' && routes[func] && typeof routes[func][funcname] == 'function'){
routes[func][funcname](args);
}
},
load() {
var bodyId = document.body.id;
let Router = this;
// hit up common first.
Router.fire('common');
// do all the classes too.
$.each(document.body.className.split(/\s+/),function(i,classnm){
Router.fire(classnm);
Router.fire(classnm,bodyId);
});
Router.fire('common','finalize');
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment