Skip to content

Instantly share code, notes, and snippets.

@efazati
Created September 10, 2012 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efazati/3689645 to your computer and use it in GitHub Desktop.
Save efazati/3689645 to your computer and use it in GitHub Desktop.
router
router = {};
router.hashchange = {
"requstables": [],
'add': function (regex, requstable) {
router.hashchange.requstables.push({'regex': regex, 'requstable': requstable});
},
'handler': function () {
for (var i = 0; i < router.hashchange.requstables.length; i++) {
var r = router.hashchange.requstables[i];
var m = location.hash.match(r['regex']);
if (m) {
for (var ut = 0; ut < router.active_url_type.length; ut++) {
r['requstable'](m);
}
}
}
},
'init': function () {
router.active_url_type = [0, 2];
$(window).hashchange(router.hashchange.handler);
}
};
// init
router.hashchange.init();
$(window).hashchange();
router.hashchange.add(/^$/, function(){});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment