Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

utils.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* global config */
  2. /**
  3. * Defines some utility methods that are used before the other JS files are
  4. * loaded.
  5. */
  6. /**
  7. * Builds and returns the room name.
  8. */
  9. function getRoomName () { // eslint-disable-line no-unused-vars
  10. var getroomnode = config.getroomnode;
  11. var path = window.location.pathname;
  12. var roomName;
  13. // Determine the room node from the URL.
  14. if (getroomnode && typeof getroomnode === 'function') {
  15. // custom function might be responsible for doing the pushstate
  16. roomName = getroomnode.call(config, path);
  17. } else {
  18. // Fall back to the default strategy of making assumptions about how the
  19. // URL maps to the room (name). It currently assumes a deployment in
  20. // which the last non-directory component of the path (name) is the
  21. // room.
  22. roomName
  23. = path.substring(path.lastIndexOf('/') + 1).toLowerCase()
  24. || undefined;
  25. }
  26. return roomName;
  27. }
  28. /**
  29. * Parses the parameters from the URL and returns them as a JS object.
  30. * @param source {string} values - "hash"/"search" if "search" the parameters
  31. * will parsed from location.search otherwise from location.hash
  32. * @param dontParse if false or undefined some transformations
  33. * (for parsing the value as JSON) are going to be executed
  34. */
  35. // eslint-disable-next-line no-unused-vars
  36. function getConfigParamsFromUrl(source, dontParse) {
  37. var paramStr = (source === "search")? location.search : location.hash;
  38. if (!paramStr)
  39. return {};
  40. paramStr = paramStr.substr(1);
  41. var result = {};
  42. paramStr.split("&").forEach(function (part) {
  43. var item = part.split("=");
  44. var value;
  45. try {
  46. value = (dontParse)? item[1] : JSON.parse(
  47. decodeURIComponent(item[1]).replace(/\\&/, "&"));
  48. } catch (e) {
  49. console.warn("Failed to parse URL argument", e);
  50. if(window.onerror)
  51. window.onerror("Failed to parse URL argument", null, null,
  52. null, e);
  53. return;
  54. }
  55. result[item[0]] = value;
  56. });
  57. return result;
  58. }