Skip to content

Instantly share code, notes, and snippets.

@kyo-ago
Created April 23, 2010 03:12
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 kyo-ago/376127 to your computer and use it in GitHub Desktop.
Save kyo-ago/376127 to your computer and use it in GitHub Desktop.
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