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.
45 lines
1.2 KiB
45 lines
1.2 KiB
|
4 years ago
|
|
||
|
|
window.common = (function () {
|
||
|
|
var common = {};
|
||
|
|
|
||
|
|
common.getFragment = function getFragment() {
|
||
|
|
if (window.location.hash.indexOf("#") === 0) {
|
||
|
|
return parseQueryString(window.location.hash.substr(1));
|
||
|
|
} else {
|
||
|
|
return {};
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
function parseQueryString(queryString) {
|
||
|
|
var data = {},
|
||
|
|
pairs, pair, separatorIndex, escapedKey, escapedValue, key, value;
|
||
|
|
|
||
|
|
if (queryString === null) {
|
||
|
|
return data;
|
||
|
|
}
|
||
|
|
|
||
|
|
pairs = queryString.split("&");
|
||
|
|
|
||
|
|
for (var i = 0; i < pairs.length; i++) {
|
||
|
|
pair = pairs[i];
|
||
|
|
separatorIndex = pair.indexOf("=");
|
||
|
|
|
||
|
|
if (separatorIndex === -1) {
|
||
|
|
escapedKey = pair;
|
||
|
|
escapedValue = null;
|
||
|
|
} else {
|
||
|
|
escapedKey = pair.substr(0, separatorIndex);
|
||
|
|
escapedValue = pair.substr(separatorIndex + 1);
|
||
|
|
}
|
||
|
|
|
||
|
|
key = decodeURIComponent(escapedKey);
|
||
|
|
value = decodeURIComponent(escapedValue);
|
||
|
|
|
||
|
|
data[key] = value;
|
||
|
|
}
|
||
|
|
|
||
|
|
return data;
|
||
|
|
}
|
||
|
|
|
||
|
|
return common;
|
||
|
|
})();
|