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.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* global $, $iq, config */
  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 k in params)
  19. {
  20. if(typeof k !== "string" || k.indexOf("config.") === -1)
  21. continue;
  22. var v = params[k];
  23. var confKey = k.substr(7);
  24. if(config[confKey] && typeof config[confKey] !== typeof v)
  25. {
  26. console.warn("The type of " + k +
  27. " is wrong. That parameter won't be updated in config.js.");
  28. continue;
  29. }
  30. config[confKey] = v;
  31. }
  32. }
  33. };
  34. module.exports = URLProcessor;