選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

URLProcessor.js 1017B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var params = {};
  2. function getConfigParamsFromUrl() {
  3. if(!location.hash)
  4. return {};
  5. var hash = location.hash.substr(1);
  6. var result = {};
  7. hash.split("&").forEach(function(part) {
  8. var item = part.split("=");
  9. result[item[0]] = JSON.parse(
  10. decodeURIComponent(item[1]).replace(/\\&/, "&"));
  11. });
  12. return result;
  13. }
  14. params = getConfigParamsFromUrl();
  15. var URLProcessor = {
  16. setConfigParametersFromUrl: function () {
  17. for(var k in params)
  18. {
  19. if(typeof k !== "string" || k.indexOf("config.") === -1)
  20. continue;
  21. var v = params[k];
  22. var confKey = k.substr(7);
  23. if(config[confKey] && typeof config[confKey] !== typeof v)
  24. {
  25. console.warn("The type of " + k +
  26. " is wrong. That parameter won't be updated in config.js.");
  27. continue;
  28. }
  29. config[confKey] = v;
  30. }
  31. }
  32. };
  33. module.exports = URLProcessor;