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:
@@ -552,21 +552,32 @@ OpenLayers.Util.distVincenty=function(p1, p2) {
|
|||||||
var d = s.toFixed(3)/1000; // round to 1mm precision
|
var d = s.toFixed(3)/1000; // round to 1mm precision
|
||||||
return d;
|
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".
|
* @param {String} url Optional url used to extract the query string.
|
||||||
if (pos == -1) continue; // If not found, skip.
|
* If null, query string is taken from page location.
|
||||||
var argname = pairs[i].substring(0,pos); // Extract the name.
|
*
|
||||||
var value = pairs[i].substring(pos+1); // Extract the value.
|
* @returns An object of key/value pairs from the query string.
|
||||||
args[argname] = unescape(value); // Store as a property.
|
* @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);
|
||||||
}
|
}
|
||||||
return args; // Return the object.
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {String} prefix String to prefix random id. If null, default
|
* @param {String} prefix String to prefix random id. If null, default
|
||||||
|
|||||||
Reference in New Issue
Block a user