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.

URLProcessor.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* global $, $iq, config, interfaceConfig */
  2. var params = {};
  3. function getConfigParamsFromUrl() {
  4. if(!location.hash)
  5. return {};
  6. var hash = location.hash.substr(1);
  7. var result = {};
  8. hash.split("&").forEach(function(part) {
  9. var item = part.split("=");
  10. result[item[0]] = JSON.parse(
  11. decodeURIComponent(item[1]).replace(/\\&/, "&"));
  12. });
  13. return result;
  14. }
  15. params = getConfigParamsFromUrl();
  16. var URLProcessor = {
  17. setConfigParametersFromUrl: function () {
  18. for(var key in params) {
  19. if(typeof key !== "string")
  20. continue;
  21. var confObj = null, confKey;
  22. if (key.indexOf("config.") === 0) {
  23. confObj = config;
  24. confKey = key.substr("config.".length);
  25. } else if (key.indexOf("interfaceConfig.") === 0) {
  26. confObj = interfaceConfig;
  27. confKey = key.substr("interfaceConfig.".length);
  28. }
  29. if (!confObj)
  30. continue;
  31. var value = params[key];
  32. if (confObj[confKey] && typeof confObj[confKey] !== typeof value)
  33. {
  34. console.warn("The type of " + key +
  35. " is wrong. That parameter won't be updated in config.js.");
  36. continue;
  37. }
  38. confObj[confKey] = value;
  39. }
  40. }
  41. };
  42. module.exports = URLProcessor;