Improve getArgs to not use deprecated features, and add support to pass a

URL to the function to parse instead of the window.location. Patch by
Tim Schaub, Closes #378 


git-svn-id: http://svn.openlayers.org/trunk/openlayers@1906 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-11-18 15:01:17 +00:00
parent 57dc3a7f53
commit fb7b5fff56

View File

@@ -553,20 +553,31 @@ OpenLayers.Util.distVincenty=function(p1, p2) {
return d;
};
OpenLayers.Util.getArgs = function() {
var args = new Object();
var query = location.search.substring(1); // Get query string.
var pairs = query.split("&"); // Break at ampersand. //+pjl
for(var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('='); // Look for "name=value".
if (pos == -1) continue; // If not found, skip.
var argname = pairs[i].substring(0,pos); // Extract the name.
var value = pairs[i].substring(pos+1); // Extract the value.
args[argname] = unescape(value); // Store as a property.
/**
* @param {String} url Optional url used to extract the query string.
* If null, query string is taken from page location.
*
* @returns An object of key/value pairs from the query string.
* @type Object
*/
OpenLayers.Util.getArgs = function(url) {
if(url == null) {
var query = window.location.search.substring(1);
} else {
var query = (url.indexOf('?') == -1) ?
'' : url.substring(url.indexOf('?') + 1);
}
var args = new Object();
pairs = query.split(/[&;]/);
for(var i = 0; i < pairs.length; ++i) {
keyValue = pairs[i].split(/=/);
if(keyValue.length == 2) {
args[decodeURIComponent(keyValue[0])] =
decodeURIComponent(keyValue[1]);
}
}
return args;
}
return args; // Return the object.
};
/**
* @param {String} prefix String to prefix random id. If null, default