summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author“Ryder <“r@okfoc.us”>2016-04-14 11:45:39 -0400
committer“Ryder <“r@okfoc.us”>2016-04-14 11:45:39 -0400
commita52067b7b00377051f138fdd259e0a4f71ffe0f1 (patch)
tree28f9c5b2468442af06af54cd0bf0ec7973baea51
parent3798bc1899e1f28ee5d1b47fd413f7db2ea3fe9c (diff)
parent7b36e03782d9fa7f437b96af09145dc063951cf4 (diff)
Merge branch 'master' of https://github.com/okfocus/portfolio
-rw-r--r--public/assets/js/vendor/Router.js110
1 files changed, 57 insertions, 53 deletions
diff --git a/public/assets/js/vendor/Router.js b/public/assets/js/vendor/Router.js
index 3b0d939..c4115dc 100644
--- a/public/assets/js/vendor/Router.js
+++ b/public/assets/js/vendor/Router.js
@@ -15,68 +15,72 @@ var Router = View.extend({
}
},
- route: function(){
- var path = this.routeByHash ? window.location.hash.substr(0) : window.location.pathname
+ route: function(){
+ var path = this.routeByHash ? window.location.hash.substr(0) : window.location.pathname
path = path || "/"
- this.originalPath = path
- this.parseRoute(path)
- },
-
- parseRoute: function(pathname){
+ this.originalPath = path
+ this.parseRoute(path)
+ },
+
+ parseRoute: function(pathname){
pathname = pathname.replace(/^#/, "")
- if (pathname[0] !== "/") { pathname = "/" + pathname }
+ if (pathname[0] !== "/") { pathname = "/" + pathname }
- var routes = this.routes,
- path = pathname.split("/");
+ var routes = this.routes,
+ path = pathname.split("/");
- for (var i = 0; i < path.length; i++) {
- if (! path[i].length) {
- path[i] = null
- }
- }
+ for (var i = 0; i < path.length; i++) {
+ if (! path[i].length) {
+ path[i] = null
+ }
+ }
- if (pathname in routes) {
- this[this.routes[pathname]]()
- return
- }
-
- if (path[path.length-1] == null) {
- path.pop()
- }
+ if (pathname in routes) {
+ this[this.routes[pathname]]()
+ 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]](path[2])
- return
- }
- else if (routePath[2] == path[2]) {
- if (routePath[3] && path[3]) {
- if (routePath[3].indexOf(":") !== -1) {
- this[this.routes[route]](path[3])
- return
- }
- else if (routePath[3] == path[3]) {
- this[this.routes[route]]()
- return
- }
- }
- else if (! routePath[3] && ! path[3]) {
- this[this.routes[route]]()
- return
- }
- }
- else if (! routePath[2] && (! path[2].length || ! path[2])) {
- this[this.routes[route]]()
- return
- }
- }
- }
+ 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]](path[2])
+ return
+ }
+ else if (routePath[2] == path[2]) {
+ if (routePath[3] && path[3]) {
+ if (routePath[3].indexOf(":") !== -1) {
+ this[this.routes[route]](path[3])
+ return
+ }
+ else if (routePath[3] == path[3]) {
+ this[this.routes[route]]()
+ return
+ }
+ }
+ else if (! routePath[3] && ! path[3]) {
+ this[this.routes[route]]()
+ return
+ }
+ }
+ else if (! routePath[2] && (! path[2].length || ! path[2])) {
+ this[this.routes[route]]()
+ return
+ }
+ }
+ else if (routePath[1].indexOf(":") !== -1 && path.length < 3) {
+ this[this.routes[route]](path[1])
+ return
+ }
+ }
// Redirect to root on 404
window.location = '/'
- }
+ }
})