diff options
| author | yo mama <pepper@scannerjammer.com> | 2014-12-04 19:50:41 -0800 |
|---|---|---|
| committer | yo mama <pepper@scannerjammer.com> | 2014-12-04 19:50:41 -0800 |
| commit | 213f2d5cd258d6ddedd47b169b5e3e2482bc3583 (patch) | |
| tree | f362cc3db1bf2108e03c021ad677e09914808212 /Router.js | |
| parent | 8fee508e5fbfdf35386ec82a5ec7860df20626d6 (diff) | |
made it make some sense
Diffstat (limited to 'Router.js')
| -rw-r--r-- | Router.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Router.js b/Router.js new file mode 100644 index 0000000..28905b2 --- /dev/null +++ b/Router.js @@ -0,0 +1,61 @@ +var Router = View.extend({ + + route: function(){ + + this.originalPath = window.location.pathname + + var routes = is_mobile ? this.mobileRoutes : this.routes, + pathname = window.location.pathname, + path = pathname.split("/"); + + for (var i = 0; i < path.length; i++) { + if (! path[i].length) { + path[i] = null + } + } + + if (pathname in routes) { + this[this.routes[pathname]](null) + return + } + + if (path[path.length-1] == null) { + path.pop() + } + + for (var route in routes) { + var routePath = route.split("/") + if (routePath[1] == path[1]) { + if (routePath[2] && routePath[2].indexOf(":") !== -1 && path[2] && (path[3] === routePath[3]) ) { + this[this.routes[route]](null, path[2]) + return + } + else if (routePath[2] == path[2]) { + if (routePath[3] && path[3]) { + if (routePath[3].indexOf(":") !== -1) { + this[this.routes[route]](null, path[3]) + return + } + else if (routePath[3] == path[3]) { + this[this.routes[route]](null) + return + } + } + else if (! routePath[3] && ! path[3]) { + this[this.routes[route]](null) + return + } + } + else if (! routePath[2] && (! path[2].length || ! path[2])) { + this[this.routes[route]](null) + return + } + } + } + + if (is_mobile) { + window.location.href = "/" + } + } + +}) |
