Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

utils.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 path = window.location.pathname;
  11. var roomName;
  12. // determinde the room node from the url
  13. // TODO: just the roomnode or the whole bare jid?
  14. if (config.getroomnode && typeof config.getroomnode === 'function') {
  15. // custom function might be responsible for doing the pushstate
  16. roomName = config.getroomnode(path);
  17. } else {
  18. /* fall back to default strategy
  19. * this is making assumptions about how the URL->room mapping happens.
  20. * It currently assumes deployment at root, with a rewrite like the
  21. * following one (for nginx):
  22. location ~ ^/([a-zA-Z0-9]+)$ {
  23. rewrite ^/(.*)$ / break;
  24. }
  25. */
  26. if (path.length > 1) {
  27. roomName = path.substr(1).toLowerCase();
  28. }
  29. }
  30. return roomName;
  31. }
  32. /**
  33. * Parses the parameters from the URL and returns them as a JS object.
  34. * @param source {string} values - "hash"/"search" if "search" the parameters
  35. * will parsed from location.search otherwise from location.hash
  36. * @param dontParse if false or undefined some transformations
  37. * (for parsing the value as JSON) are going to be executed
  38. */
  39. // eslint-disable-next-line no-unused-vars
  40. function getConfigParamsFromUrl(source, dontParse) {
  41. var paramStr = (source === "search")? location.search : location.hash;
  42. if (!paramStr)
  43. return {};
  44. paramStr = paramStr.substr(1);
  45. var result = {};
  46. paramStr.split("&").forEach(function (part) {
  47. var item = part.split("=");
  48. var value;
  49. try {
  50. value = (dontParse)? item[1] : JSON.parse(
  51. decodeURIComponent(item[1]).replace(/\\&/, "&"));
  52. } catch (e) {
  53. console.warn("Failed to parse URL argument", e);
  54. if(window.onerror)
  55. window.onerror("Failed to parse URL argument", null, null,
  56. null, e);
  57. return;
  58. }
  59. result[item[0]] = value;
  60. });
  61. return result;
  62. }