From 840cdf39595c6b8a29d2c91447d9fb8a91582a59 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 30 Nov 2015 16:14:29 -0500 Subject: ui changes --- .../platforms/ios/www/js/lib/view/Router.js | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 StoneIsland/platforms/ios/www/js/lib/view/Router.js (limited to 'StoneIsland/platforms/ios/www/js/lib/view/Router.js') diff --git a/StoneIsland/platforms/ios/www/js/lib/view/Router.js b/StoneIsland/platforms/ios/www/js/lib/view/Router.js new file mode 100644 index 00000000..a8ec331f --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/view/Router.js @@ -0,0 +1,75 @@ +var Router = View.extend({ + + routeByHash: false, + + go: function(url){ + this.parseRoute(url) + }, + + 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){ + + pathname = pathname.replace(/^#/, "") + + if (pathname[0] !== "/") { pathname = "/" + pathname } + + var routes = this.routes, + 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]]() + 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 + } + } + } + + if (is_mobile) { + window.location.href = "/" + } + } + +}) -- cgit v1.2.3-70-g09d2