mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 03:32:00 +09:00
Add Rhymix.getBaseUrl() and remove internal cache variable "baseurl"
This commit is contained in:
parent
341df211ee
commit
1568cb3790
1 changed files with 21 additions and 9 deletions
|
|
@ -9,7 +9,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Rhymix = {
|
const Rhymix = {
|
||||||
baseurl: null,
|
|
||||||
addedDocument: [],
|
addedDocument: [],
|
||||||
langCodes: {},
|
langCodes: {},
|
||||||
loadedPopupMenus: [],
|
loadedPopupMenus: [],
|
||||||
|
|
@ -18,7 +17,8 @@ const Rhymix = {
|
||||||
pendingDebugData: [],
|
pendingDebugData: [],
|
||||||
showAjaxErrors: ['ALL'],
|
showAjaxErrors: ['ALL'],
|
||||||
unloading: false,
|
unloading: false,
|
||||||
modal: {}
|
modal: {},
|
||||||
|
state: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -106,7 +106,7 @@ Rhymix.getLangType = function() {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
Rhymix.setLangType = function(lang_type) {
|
Rhymix.setLangType = function(lang_type) {
|
||||||
const baseurl = this.URI(default_url).pathname();
|
const baseurl = this.getBaseUrl();
|
||||||
if (baseurl !== '/') {
|
if (baseurl !== '/') {
|
||||||
this.cookie.remove('lang_type', { path: '/' });
|
this.cookie.remove('lang_type', { path: '/' });
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +142,19 @@ Rhymix.getRewriteLevel = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default URL
|
* Get the base URL relative to the current origin
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
Rhymix.getBaseUrl = function() {
|
||||||
|
if (!this.state.baseUrl) {
|
||||||
|
this.state.baseUrl = this.URI(default_url).pathname();
|
||||||
|
}
|
||||||
|
return this.state.baseUrl;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the full default URL
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
@ -227,20 +239,20 @@ Rhymix.isSameHost = function(url) {
|
||||||
if (url.match(/^\w+:[^\/]*$/) || url.match(/^(https?:)?\/\/[^\/]*[^a-z0-9\/.:_-]/i)) {
|
if (url.match(/^\w+:[^\/]*$/) || url.match(/^(https?:)?\/\/[^\/]*[^a-z0-9\/.:_-]/i)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!this.baseurl) {
|
if (!this.state.partialOrigin) {
|
||||||
this.baseurl = this.URI(window.request_uri).normalizePort().normalizeHostname().normalizePathname();
|
let uri = this.URI(window.request_uri).normalizePort().normalizeHostname().normalizePathname();
|
||||||
this.baseurl = this.baseurl.hostname() + this.baseurl.directory();
|
this.state.partialOrigin = uri.hostname() + uri.directory();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
let target_url = this.URI(url).normalizePort().normalizeHostname().normalizePathname();
|
let target_url = this.URI(url).normalizePort().normalizeHostname().normalizePathname();
|
||||||
if (target_url.is("urn")) {
|
if (target_url.is('urn')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!target_url.hostname()) {
|
if (!target_url.hostname()) {
|
||||||
target_url = target_url.absoluteTo(window.request_uri);
|
target_url = target_url.absoluteTo(window.request_uri);
|
||||||
}
|
}
|
||||||
target_url = target_url.hostname() + target_url.directory();
|
target_url = target_url.hostname() + target_url.directory();
|
||||||
return target_url.indexOf(this.baseurl) === 0;
|
return target_url.indexOf(this.state.partialOrigin) === 0;
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue