Skip to content

Instantly share code, notes, and snippets.

@kyo-ago
Created Apr 23, 2010
Embed
What would you like to do?
url dispatcher
var dispatcher = function (path, func) {
if (func) return dispatcher.path_func.push([path, func]);
$.each(dispatcher.path_func, function () {
if (path.match(this[0])) return this[1]();
});
};
dispatcher.path_func = [];
setTimeout(function () { dispatcher(location.pathname); }, 0);
dispatcher('.', function () {
// 全URLで使う内容
});
dispatcher('/hoge', function () {
// /hogeで使う内容
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment