diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-11-15 13:52:28 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-11-15 13:52:28 -0500 |
| commit | a4ce7bf7a9e8d472b0523e74510a4ff4c394fa3f (patch) | |
| tree | 2cfeb32ec4f11793498e99e69879ad8aac17c754 /public/assets/js/lib/_router.js | |
| parent | 94ade9321a971e81c383e14186bf4c776bd304fc (diff) | |
links view
Diffstat (limited to 'public/assets/js/lib/_router.js')
| -rw-r--r-- | public/assets/js/lib/_router.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/public/assets/js/lib/_router.js b/public/assets/js/lib/_router.js new file mode 100644 index 0000000..69640f4 --- /dev/null +++ b/public/assets/js/lib/_router.js @@ -0,0 +1,60 @@ +var SiteRouter = Router.extend({ + + el: 'body', + routeByHash: false, + + routes: { + '/': 'home', + }, + + initialize: function(){ + var fn + for (var route in this.routes) { + fn = this.routes[route] + if (! this[fn]) { + this[fn] = this.default_view(fn) + } + } + }, + + initial_route: null, + launch: function(){ + if (this.initial_route) { + this.parseRoute( this.initial_route ) + } + else { + this.route() + } + this.initial_route = null + }, + + go: function(url){ + if (app.view && app.view.hide) { + app.view.hide() + } + this.pushState(url) + this.parseRoute(url) + }, + + default_view: function(name){ + var fn = function(){ + if (app.view != app.login && app.view != app.signin) { + app.last_view = app.view + } + if (app.view && app.view.hide) { + app.view.hide() + } + if (name.match(/\./)) { + var n = name.split(".") + app.view = app.views[n[0]][n[1]] + } + else { + app.view = app.views[name] + } + app.view.show() + }.bind(this) + return fn + }, + +}) + |
