mirror of
https://github.com/discourse/discourse.git
synced 2025-05-26 06:01:43 +08:00
Merge pull request #637 from wojciechka/master
Putting rootURL in JavaScript using Discourse::base_uri and erb
This commit is contained in:
@ -22,10 +22,8 @@ Discourse = Ember.Application.createWithMixins({
|
|||||||
// The highest seen post number by topic
|
// The highest seen post number by topic
|
||||||
highestSeenByTopic: {},
|
highestSeenByTopic: {},
|
||||||
|
|
||||||
rootURL: '/',
|
|
||||||
|
|
||||||
getURL: function(url) {
|
getURL: function(url) {
|
||||||
var u = this.get('rootURL');
|
var u = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
|
||||||
if (u[u.length-1] === '/') {
|
if (u[u.length-1] === '/') {
|
||||||
u = u.substring(0, u.length-1);
|
u = u.substring(0, u.length-1);
|
||||||
}
|
}
|
||||||
|
@ -13,14 +13,6 @@ Discourse.URL = {
|
|||||||
// Used for matching a /more URL
|
// Used for matching a /more URL
|
||||||
MORE_REGEXP: /\/more$/,
|
MORE_REGEXP: /\/more$/,
|
||||||
|
|
||||||
/**
|
|
||||||
Will be pre-pended to path upon state change
|
|
||||||
|
|
||||||
@property rootURL
|
|
||||||
@default '/'
|
|
||||||
*/
|
|
||||||
rootURL: '/',
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@private
|
@private
|
||||||
|
|
||||||
@ -73,7 +65,8 @@ Discourse.URL = {
|
|||||||
If the URL is absolute, remove rootURL
|
If the URL is absolute, remove rootURL
|
||||||
*/
|
*/
|
||||||
if (path.match(/^\//)) {
|
if (path.match(/^\//)) {
|
||||||
var rootURL = this.rootURL.replace(/\/$/, '');
|
var rootURL = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
|
||||||
|
rootURL = rootURL.replace(/\/$/, '');
|
||||||
path = path.replace(rootURL, '');
|
path = path.replace(rootURL, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,14 +35,6 @@ Ember.DiscourseLocation = Ember.Object.extend({
|
|||||||
set(this, 'history', window.history);
|
set(this, 'history', window.history);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
Will be pre-pended to path upon state change
|
|
||||||
|
|
||||||
@property rootURL
|
|
||||||
@default '/'
|
|
||||||
*/
|
|
||||||
rootURL: '/',
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@private
|
@private
|
||||||
|
|
||||||
@ -51,7 +43,7 @@ Ember.DiscourseLocation = Ember.Object.extend({
|
|||||||
@method getURL
|
@method getURL
|
||||||
*/
|
*/
|
||||||
getURL: function() {
|
getURL: function() {
|
||||||
var rootURL = get(this, 'rootURL'),
|
var rootURL = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri),
|
||||||
url = get(this, 'location').pathname;
|
url = get(this, 'location').pathname;
|
||||||
|
|
||||||
rootURL = rootURL.replace(/\/$/, '');
|
rootURL = rootURL.replace(/\/$/, '');
|
||||||
@ -154,7 +146,7 @@ Ember.DiscourseLocation = Ember.Object.extend({
|
|||||||
var currentState = self.get('currentState');
|
var currentState = self.get('currentState');
|
||||||
if (currentState) {
|
if (currentState) {
|
||||||
var url = e.state.path,
|
var url = e.state.path,
|
||||||
rootURL = get(self, 'rootURL');
|
rootURL = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
|
||||||
|
|
||||||
rootURL = rootURL.replace(/\/$/, '');
|
rootURL = rootURL.replace(/\/$/, '');
|
||||||
url = url.replace(rootURL, '');
|
url = url.replace(rootURL, '');
|
||||||
@ -176,7 +168,7 @@ Ember.DiscourseLocation = Ember.Object.extend({
|
|||||||
@param url {String}
|
@param url {String}
|
||||||
*/
|
*/
|
||||||
formatURL: function(url) {
|
formatURL: function(url) {
|
||||||
var rootURL = get(this, 'rootURL');
|
var rootURL = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
|
||||||
|
|
||||||
if (url !== '') {
|
if (url !== '') {
|
||||||
rootURL = rootURL.replace(/\/$/, '');
|
rootURL = rootURL.replace(/\/$/, '');
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
<script>
|
<script>
|
||||||
Discourse.CDN = '<%= Rails.configuration.action_controller.asset_host %>';
|
Discourse.CDN = '<%= Rails.configuration.action_controller.asset_host %>';
|
||||||
Discourse.BaseUrl = '<%= RailsMultisite::ConnectionManagement.current_hostname %>';
|
Discourse.BaseUrl = '<%= RailsMultisite::ConnectionManagement.current_hostname %>';
|
||||||
|
Discourse.BaseUri = '<%= Discourse::base_uri "/" %>';
|
||||||
Discourse.Environment = '<%= Rails.env %>';
|
Discourse.Environment = '<%= Rails.env %>';
|
||||||
Discourse.Router.map(function() {
|
Discourse.Router.map(function() {
|
||||||
return Discourse.routeBuilder.call(this);
|
return Discourse.routeBuilder.call(this);
|
||||||
|
@ -18,11 +18,11 @@ module Discourse
|
|||||||
RailsMultisite::ConnectionManagement.current_hostname
|
RailsMultisite::ConnectionManagement.current_hostname
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.base_uri
|
def self.base_uri default_value=""
|
||||||
if !ActionController::Base.config.relative_url_root.blank?
|
if !ActionController::Base.config.relative_url_root.blank?
|
||||||
return ActionController::Base.config.relative_url_root
|
return ActionController::Base.config.relative_url_root
|
||||||
else
|
else
|
||||||
return ""
|
return default_value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user