Content deleted Content added
Mike Dillon (talk | contribs) No edit summary |
Mike Dillon (talk | contribs) comments |
||
Line 1:
/* <pre><nowiki> */
// function getParameterMap(url): Parses a URL and extracts the query string parameters;
// if no URL is provided, uses the current URL. Caches parsed parameters between invocations.
var getParameterMap = (function () {
// URL parameters cache: key=url, value=paramMap
var
return function (url) {
// If no URL is passed in, use the current page's URL
if (!url) url = ___location.href;▼
if (
}
// If the parameters for this URL have already been parsed, return them
var params = {};▼
if (urlParamMaps[url]) return urlParamMaps[url];
var search = url.split("?")[1];▼
// Set up a new map for the parameters to be parsed
// Split the URL from the query string
▲ var search = url.split("?", 2)[1];
if (search) {
// Split query string on "&"
var kvs = search.split("&");
for (var i in kvs) {
// Split each key-value pair on the equals sign
var kv = kvs[i].split("=", 2);
var key = kv[0];
var value = unescape(kv[1]);
if
paramMap[key] = [];
}
paramMap[key].push(value);
}
}
// Cache the paramMap to avoid parsing for all parameter requests
return paramMap;
};
})();
// function getParameterValues(key, url): Extracts the list of values for a particular key
// from the given URL; if no URL is provided, uses the current URL.
// Returns null if the parameter was not in the URL.
function getParameterValues(key, url) {
return getParameterMap(url)[key];
}
// function getParameterValues(key, url): Extracts the values for a particular key
// from the given URL; if no URL is provided, uses the current URL.
// If there is more than one value for the given key, the first value is returned.
// Returns null if the parameter was not in the URL.
function getParameter(key, url) {
var values = getParameterValues(key, url);
Line 40 ⟶ 63:
}
// function getParameterNames(url): Extracts the list of parameter names
// from the given URL; if no URL is provided, uses the current URL.
function getParameterNames(url) {
var names = [];
|