var Router = (function () {
var Router = function () {};
Router.prototype.add = function (path, callback) {
this.routes = this.routes || [];
this.routes.push({
path: new RegExp(path.replace(/\//g, "\\/").replace(/:(\w*)/g,"(\\w*)"))
, callback: callback
});
};
Router.prototype.process = function () {
var route
, params;
for (route in this.routes) {
params = window.location.pathname.match(route.path);
if (params) {
route.callback(params);
return;
}
}
};
return Router;
})();
Router = new Router();
Router.add('/blog/:id', blogCallback);
function blogCallback () {
alert('OK');
}
$(document).ready(function(){
Router.process();
});
Комментариев нет:
Отправить комментарий