From f56a746d71b3f29ab3355bcb8c79a4633e9762c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Sat, 24 Mar 2018 02:43:19 +0100 Subject: [PATCH] Add baseUri to site model --- app/assets/javascripts/discourse/lib/url.js.es6 | 17 +++++++++-------- .../javascripts/discourse/models/site.js.es6 | 5 +++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/url.js.es6 b/app/assets/javascripts/discourse/lib/url.js.es6 index 487b4467f9b..16acbbf2655 100644 --- a/app/assets/javascripts/discourse/lib/url.js.es6 +++ b/app/assets/javascripts/discourse/lib/url.js.es6 @@ -81,6 +81,7 @@ const DiscourseURL = Ember.Object.extend({ const holderId = `#post_${postNumber}`; _transitioning = postNumber > 1; + Ember.run.schedule('afterRender', () => { let elementId; let holder; @@ -107,7 +108,7 @@ const DiscourseURL = Ember.Object.extend({ } }); - if (holder.length > 0 && opts && opts.skipIfOnScreen){ + if (holder.length > 0 && opts && opts.skipIfOnScreen) { const elementTop = lockon.elementTop(); const scrollTop = $(window).scrollTop(); const windowHeight = $(window).height() - offsetCalculator(); @@ -172,7 +173,7 @@ const DiscourseURL = Ember.Object.extend({ } const pathname = path.replace(/(https?\:)?\/\/[^\/]+/, ''); - let baseUri = Discourse.BaseUri; + const baseUri = Discourse.BaseUri; // If we have a baseUri and an absolute URL, make sure the baseUri // is the same. Otherwise we could be switching forums. @@ -217,18 +218,18 @@ const DiscourseURL = Ember.Object.extend({ } // handle prefixes - if (path.match(/^\//)) { - let rootURL = (baseUri === undefined ? "/" : baseUri); - rootURL = rootURL.replace(/\/$/, ''); - path = path.replace(rootURL, ''); + if (path.indexOf("/") === 0) { + const rootURL = (baseUri === undefined ? "/" : baseUri).replace(/\/$/, ""); + path = path.replace(rootURL, ""); } path = rewritePath(path); + if (this.navigatedToPost(oldPath, path, opts)) { return; } if (oldPath === path) { - // If navigating to the same path send an app event. Views can watch it - // and tell their controllers to refresh + // If navigating to the same path send an app event. + // Views can watch it and tell their controllers to refresh this.appEvents.trigger('url:refresh'); } diff --git a/app/assets/javascripts/discourse/models/site.js.es6 b/app/assets/javascripts/discourse/models/site.js.es6 index 073f6b43f9b..c1e3889176c 100644 --- a/app/assets/javascripts/discourse/models/site.js.es6 +++ b/app/assets/javascripts/discourse/models/site.js.es6 @@ -54,6 +54,11 @@ const Site = RestModel.extend({ return result; }, + @computed + baseUri() { + return Discourse.baseUri; + }, + // Returns it in the correct order, by setting @computed categoriesList() {