summaryrefslogtreecommitdiff
path: root/public/assets/js/vendor/view/router.js
diff options
context:
space:
mode:
authorjulian laplace <julescarbon@gmail.com>2022-10-26 17:05:14 +0200
committerjulian laplace <julescarbon@gmail.com>2022-10-26 17:05:14 +0200
commitdd72ab05da17309fd5ee6005cdc1fae686b5fa9e (patch)
tree9edc695fffa73a85d94e571f44c7d4c97de71654 /public/assets/js/vendor/view/router.js
parent3de2a5872fd0481568e918a1ea798b3f75ace610 (diff)
filter by keyword, thread, or username
Diffstat (limited to 'public/assets/js/vendor/view/router.js')
-rw-r--r--public/assets/js/vendor/view/router.js117
1 files changed, 59 insertions, 58 deletions
diff --git a/public/assets/js/vendor/view/router.js b/public/assets/js/vendor/view/router.js
index 3b0d939..0f977e0 100644
--- a/public/assets/js/vendor/view/router.js
+++ b/public/assets/js/vendor/view/router.js
@@ -1,82 +1,83 @@
var Router = View.extend({
+ routeByHash: false,
- routeByHash: false,
+ go: function (url) {
+ this.parseRoute(url);
+ },
- go: function(url){
- this.parseRoute(url)
- },
-
- pushState: function(url){
- if (this.routeByHash) {
- window.location.hash = url
- }
- else if (window.history) {
- window.history.pushState(null, null, url)
- }
- },
+ pushState: function (url) {
+ if (this.routeByHash) {
+ window.location.hash = url;
+ } else if (window.history) {
+ window.history.pushState(null, null, url);
+ }
+ },
- route: function(){
- var path = this.routeByHash ? window.location.hash.substr(0) : window.location.pathname
- path = path || "/"
- this.originalPath = path
- this.parseRoute(path)
+ 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 }
+
+ parseRoute: function (pathname) {
+ pathname = pathname.replace(/^#/, "");
+
+ if (pathname[0] !== "/") {
+ pathname = "/" + pathname;
+ }
var routes = this.routes,
- path = pathname.split("/");
+ path = pathname.split("/");
for (var i = 0; i < path.length; i++) {
- if (! path[i].length) {
- path[i] = null
+ if (!path[i].length) {
+ path[i] = null;
}
}
- if (pathname in routes) {
- this[this.routes[pathname]]()
- return
+ if (pathname in routes) {
+ this[this.routes[pathname]]();
+ return;
}
-
- if (path[path.length-1] == null) {
- path.pop()
+
+ if (path[path.length - 1] == null) {
+ path.pop();
}
for (var route in routes) {
- var routePath = route.split("/")
+ 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[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
+ 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[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[2] && (!path[2].length || !path[2])) {
+ this[this.routes[route]]();
+ return;
}
}
}
- // Redirect to root on 404
- window.location = '/'
- }
-
-})
+ // Redirect to root on 404
+ window.location = "/";
+ },
+});