Last active
November 23, 2023 09:52
-
-
Save nathanaelnsmith/efc1ce2dd0b78db11632d47727361319 to your computer and use it in GitHub Desktop.
ES6 module implementation of Paul Irish's DOM based routing
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
import Router from './DomBasedRouter' | |
let routes = { | |
'common': { | |
init() {} | |
} | |
} | |
let router = new Router(routes); | |
router.load(); |
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
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