common.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 
  2. window.common = (function () {
  3. var common = {};
  4. common.getFragment = function getFragment() {
  5. if (window.location.hash.indexOf("#") === 0) {
  6. return parseQueryString(window.location.hash.substr(1));
  7. } else {
  8. return {};
  9. }
  10. };
  11. function parseQueryString(queryString) {
  12. var data = {},
  13. pairs, pair, separatorIndex, escapedKey, escapedValue, key, value;
  14. if (queryString === null) {
  15. return data;
  16. }
  17. pairs = queryString.split("&");
  18. for (var i = 0; i < pairs.length; i++) {
  19. pair = pairs[i];
  20. separatorIndex = pair.indexOf("=");
  21. if (separatorIndex === -1) {
  22. escapedKey = pair;
  23. escapedValue = null;
  24. } else {
  25. escapedKey = pair.substr(0, separatorIndex);
  26. escapedValue = pair.substr(separatorIndex + 1);
  27. }
  28. key = decodeURIComponent(escapedKey);
  29. value = decodeURIComponent(escapedValue);
  30. data[key] = value;
  31. }
  32. return data;
  33. }
  34. return common;
  35. })();