Created
September 10, 2012 08:25
-
-
Save efazati/3689645 to your computer and use it in GitHub Desktop.
router
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
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