您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

URLProcessor.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright @ 2015 Atlassian Pty Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. var params = {};
  17. function getConfigParamsFromUrl() {
  18. if(!location.hash)
  19. return {};
  20. var hash = location.hash.substr(1);
  21. var result = {};
  22. hash.split("&").forEach(function(part) {
  23. var item = part.split("=");
  24. result[item[0]] = JSON.parse(
  25. decodeURIComponent(item[1]).replace(/\\&/, "&"));
  26. });
  27. return result;
  28. }
  29. params = getConfigParamsFromUrl();
  30. var URLProcessor = {
  31. setConfigParametersFromUrl: function () {
  32. for(var k in params)
  33. {
  34. if(typeof k !== "string" || k.indexOf("config.") === -1)
  35. continue;
  36. var v = params[k];
  37. var confKey = k.substr(7);
  38. if(config[confKey] && typeof config[confKey] !== typeof v)
  39. {
  40. console.warn("The type of " + k +
  41. " is wrong. That parameter won't be updated in config.js.");
  42. continue;
  43. }
  44. config[confKey] = v;
  45. }
  46. }
  47. };
  48. module.exports = URLProcessor;