39 lines
1.5 KiB
JavaScript
39 lines
1.5 KiB
JavaScript
/**
|
|
* Shared by Main-Lobby, Main-Menu, Login, Create Room, Loading, …
|
|
* Resolves absolute paths from site root (e.g. /Game/..., /Main-Menu/...).
|
|
*/
|
|
(function (global) {
|
|
'use strict';
|
|
if (typeof global.appPath === 'function') return;
|
|
|
|
function sitePathPrefix() {
|
|
try {
|
|
var loc = global.location && global.location.pathname;
|
|
if (!loc) return '';
|
|
var m = loc.match(
|
|
/^(\/[^/]+)\/(?:Main-Lobby|Main-Menu|Login|Create(?:%20| )Room|Join(?:%20| )Room|Loading|Quiz-Battle|Game)(?:\/|$)/i
|
|
);
|
|
return m ? m[1] : '';
|
|
} catch (e) {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
global.appPath = function appPath(path) {
|
|
if (path == null || path === '') return '';
|
|
var p = String(path);
|
|
if (p.charAt(0) !== '/') p = '/' + p.replace(/^\/+/, '');
|
|
return sitePathPrefix() + p;
|
|
};
|
|
|
|
global.designLoginHref = function designLoginHref() { return appPath('/Login/'); };
|
|
global.designMainLobbyHref = function designMainLobbyHref() { return appPath('/Main-Lobby/'); };
|
|
global.designMainMenuHref = function designMainMenuHref() { return appPath('/Main-Menu/'); };
|
|
global.designCreateRoomHref = function designCreateRoomHref() { return appPath('/Create%20Room/'); };
|
|
global.designJoinRoomHref = function designJoinRoomHref() { return appPath('/Join%20Room/'); };
|
|
global.designLoadingHref = function designLoadingHref(query) {
|
|
var q = query ? String(query) : '';
|
|
return appPath('/Loading/') + (q ? (q.charAt(0) === '?' ? q : '?' + q) : '');
|
|
};
|
|
})(typeof window !== 'undefined' ? window : this);
|