You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 () {
  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 hash parameters from the URL and returns them as a JS object.
  34. */
  35. function getConfigParamsFromUrl() {
  36. if (!location.hash)
  37. return {};
  38. var hash = location.hash.substr(1);
  39. var result = {};
  40. hash.split("&").forEach(function (part) {
  41. var item = part.split("=");
  42. result[item[0]] = JSON.parse(
  43. decodeURIComponent(item[1]).replace(/\\&/, "&"));
  44. });
  45. return result;
  46. }