build/joosy.js in joosy-1.2.0.alpha.64 vs build/joosy.js in joosy-1.2.0.alpha.65

- old
+ new

@@ -1957,21 +1957,24 @@ this.responder = responder; if (respond == null) { respond = true; } if (!history.pushState) { + this.config.prefix = this.config.hashSuffix; this.config.html5 = false; } + if (!this.config.html5) { + this.config.prefix = this.config.hashSuffix; + } (_base = this.config).prefix || (_base.prefix = ''); if (this.config.html5) { this.config.prefix = ('/' + this.config.prefix + '/').replace(/\/{2,}/g, '/'); - } - if (this.config.html5) { this.listener = this.bind('popstate pushstate', function() { return _this.respond(_this.canonizeLocation()); }); } else { + this.config.prefix = this.config.prefix.replace(/^\#?\/?/, '').replace(/\/?$/, ''); $(window).bind('hashchange.JoosyRouter', function() { return _this.respond(_this.canonizeLocation()); }); } if (respond) { @@ -1995,34 +1998,27 @@ if (options == null) { options = {}; } path = to; if (this.config.html5) { - if (path[0] === '/') { - path = path.substr(1); + if (this.config.prefix && path[0] === '/' && !path.match(RegExp("^" + (this.config.prefix.replace(/\/$/, '')) + "(/|$)"))) { + path = path.replace(/^\//, this.config.prefix); } - path = this.config.prefix + path; - } else { - if (path[0] === '#') { - path = path.substr(1); - } - if (this.config.prefix && !path.startsWith(this.config.prefix)) { - path = this.config.prefix + path; - } - } - if (this.config.html5) { history.pushState({}, '', path); this.trigger('pushstate'); } else { + if (this.config.prefix && !path.match(RegExp("^#?/?" + this.config.prefix + "(/|$)"))) { + path = path.replace(/^\#?\/?/, "" + this.config.prefix + "/"); + } location.hash = path; } }; Router.canonizeLocation = function() { if (this.config.html5) { - return location.pathname.replace(RegExp("^" + (RegExp.escape(this.config.prefix)) + "?"), '/') + location.search; + return location.pathname.replace(RegExp("^(" + this.config.prefix + "?)?/?"), '/') + location.search; } else { - return location.hash.replace(RegExp("^\\#(" + this.config.prefix + ")?\\/?"), '/'); + return location.hash.replace(RegExp("^#?/?(" + this.config.prefix + "(/|$))?"), '/'); } }; Router.compileRoute = function(path, to, as) { var matcher, params, result;