Add baseUri to site model

This commit is contained in:
Régis Hanol
2018-03-24 02:43:19 +01:00
parent b1a799b526
commit f56a746d71
2 changed files with 14 additions and 8 deletions

View File

@ -81,6 +81,7 @@ const DiscourseURL = Ember.Object.extend({
const holderId = `#post_${postNumber}`; const holderId = `#post_${postNumber}`;
_transitioning = postNumber > 1; _transitioning = postNumber > 1;
Ember.run.schedule('afterRender', () => { Ember.run.schedule('afterRender', () => {
let elementId; let elementId;
let holder; 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 elementTop = lockon.elementTop();
const scrollTop = $(window).scrollTop(); const scrollTop = $(window).scrollTop();
const windowHeight = $(window).height() - offsetCalculator(); const windowHeight = $(window).height() - offsetCalculator();
@ -172,7 +173,7 @@ const DiscourseURL = Ember.Object.extend({
} }
const pathname = path.replace(/(https?\:)?\/\/[^\/]+/, ''); 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 // If we have a baseUri and an absolute URL, make sure the baseUri
// is the same. Otherwise we could be switching forums. // is the same. Otherwise we could be switching forums.
@ -217,18 +218,18 @@ const DiscourseURL = Ember.Object.extend({
} }
// handle prefixes // handle prefixes
if (path.match(/^\//)) { if (path.indexOf("/") === 0) {
let rootURL = (baseUri === undefined ? "/" : baseUri); const rootURL = (baseUri === undefined ? "/" : baseUri).replace(/\/$/, "");
rootURL = rootURL.replace(/\/$/, ''); path = path.replace(rootURL, "");
path = path.replace(rootURL, '');
} }
path = rewritePath(path); path = rewritePath(path);
if (this.navigatedToPost(oldPath, path, opts)) { return; } if (this.navigatedToPost(oldPath, path, opts)) { return; }
if (oldPath === path) { if (oldPath === path) {
// If navigating to the same path send an app event. Views can watch it // If navigating to the same path send an app event.
// and tell their controllers to refresh // Views can watch it and tell their controllers to refresh
this.appEvents.trigger('url:refresh'); this.appEvents.trigger('url:refresh');
} }

View File

@ -54,6 +54,11 @@ const Site = RestModel.extend({
return result; return result;
}, },
@computed
baseUri() {
return Discourse.baseUri;
},
// Returns it in the correct order, by setting // Returns it in the correct order, by setting
@computed @computed
categoriesList() { categoriesList() {