2016-03-28 21:19:32 +00:00
|
|
|
/* global config */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines some utility methods that are used before the other JS files are
|
|
|
|
* loaded.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds and returns the room name.
|
|
|
|
*/
|
2016-10-03 16:12:04 +00:00
|
|
|
function getRoomName () { // eslint-disable-line no-unused-vars
|
2017-02-05 02:29:24 +00:00
|
|
|
var getroomnode = config.getroomnode;
|
2016-03-28 21:19:32 +00:00
|
|
|
var path = window.location.pathname;
|
|
|
|
var roomName;
|
|
|
|
|
2017-02-05 02:29:24 +00:00
|
|
|
// Determine the room node from the URL.
|
|
|
|
if (getroomnode && typeof getroomnode === 'function') {
|
2016-03-28 21:19:32 +00:00
|
|
|
// custom function might be responsible for doing the pushstate
|
2017-02-05 02:29:24 +00:00
|
|
|
roomName = getroomnode.call(config, path);
|
2016-03-28 21:19:32 +00:00
|
|
|
} else {
|
2017-02-05 02:29:24 +00:00
|
|
|
// Fall back to the default strategy of making assumptions about how the
|
|
|
|
// URL maps to the room (name). It currently assumes a deployment in
|
|
|
|
// which the last non-directory component of the path (name) is the
|
|
|
|
// room.
|
|
|
|
roomName
|
|
|
|
= path.substring(path.lastIndexOf('/') + 1).toLowerCase()
|
|
|
|
|| undefined;
|
2016-03-28 21:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return roomName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-13 21:11:44 +00:00
|
|
|
* Parses the parameters from the URL and returns them as a JS object.
|
|
|
|
* @param source {string} values - "hash"/"search" if "search" the parameters
|
|
|
|
* will parsed from location.search otherwise from location.hash
|
|
|
|
* @param dontParse if false or undefined some transformations
|
|
|
|
* (for parsing the value as JSON) are going to be executed
|
2016-03-28 21:19:32 +00:00
|
|
|
*/
|
2016-10-03 16:12:04 +00:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2016-06-13 21:11:44 +00:00
|
|
|
function getConfigParamsFromUrl(source, dontParse) {
|
|
|
|
var paramStr = (source === "search")? location.search : location.hash;
|
|
|
|
if (!paramStr)
|
2016-03-28 21:19:32 +00:00
|
|
|
return {};
|
2016-06-13 21:11:44 +00:00
|
|
|
paramStr = paramStr.substr(1);
|
2016-03-28 21:19:32 +00:00
|
|
|
var result = {};
|
2016-06-13 21:11:44 +00:00
|
|
|
paramStr.split("&").forEach(function (part) {
|
2016-03-28 21:19:32 +00:00
|
|
|
var item = part.split("=");
|
2016-06-13 21:11:44 +00:00
|
|
|
var value;
|
|
|
|
try {
|
|
|
|
value = (dontParse)? item[1] : JSON.parse(
|
|
|
|
decodeURIComponent(item[1]).replace(/\\&/, "&"));
|
|
|
|
} catch (e) {
|
|
|
|
console.warn("Failed to parse URL argument", e);
|
|
|
|
if(window.onerror)
|
|
|
|
window.onerror("Failed to parse URL argument", null, null,
|
|
|
|
null, e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
result[item[0]] = value;
|
2016-03-28 21:19:32 +00:00
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|