diff options
Diffstat (limited to 'tree/public/assets/js/lib/_router.js')
| -rw-r--r-- | tree/public/assets/js/lib/_router.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tree/public/assets/js/lib/_router.js b/tree/public/assets/js/lib/_router.js new file mode 100644 index 0000000..248b532 --- /dev/null +++ b/tree/public/assets/js/lib/_router.js @@ -0,0 +1,82 @@ +var SiteRouter = Router.extend({ + + el: 'body', + routeByHash: false, + + routes: { + '/': 'home', + '/about': 'about', + '/press': 'press', + '/team': 'team', + '/festivals': 'festivals', + '/lectures': 'lectures', + }, + + 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 + }, + + experimentById: function(id){ + if (app.view && app.view.hide) { + app.view.hide() + } + app.view = app.views.experiments + app.views.experiments.show() + app.views.experiments.load(id) + }, + + projectById: function(id){ + if (app.view && app.view.hide) { + app.view.hide() + } + app.view = app.views.projects + app.views.projects.show() + app.views.projects.load(id) + } +}) + |
