OpenLayers OpenLayers

Changeset 1906

Show
Ignore:
Timestamp:
11/18/06 10:01:17 (2 years ago)
Author:
crschmidt
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Util.js

    r1721 r1906  
    553553    return d; 
    554554}; 
    555      
    556 OpenLayers.Util.getArgs = function() { 
     555 
     556/** 
     557 * @param {String} url Optional url used to extract the query string. 
     558 *                     If null, query string is taken from page location. 
     559 *  
     560 * @returns An object of key/value pairs from the query string. 
     561 * @type Object 
     562 */ 
     563OpenLayers.Util.getArgs = function(url) { 
     564    if(url == null) { 
     565        var query = window.location.search.substring(1); 
     566    } else { 
     567        var query = (url.indexOf('?') == -1) ? 
     568                        '' : url.substring(url.indexOf('?') + 1); 
     569    } 
    557570    var args = new Object(); 
    558     var query = location.search.substring(1);  // Get query string. 
    559     var pairs = query.split("&");              // Break at ampersand. //+pjl 
    560  
    561     for(var i = 0; i < pairs.length; i++) { 
    562         var pos = pairs[i].indexOf('=');       // Look for "name=value". 
    563         if (pos == -1) continue;               // If not found, skip. 
    564         var argname = pairs[i].substring(0,pos);  // Extract the name. 
    565         var value = pairs[i].substring(pos+1); // Extract the value. 
    566         args[argname] = unescape(value);          // Store as a property. 
    567     } 
    568     return args;                               // Return the object. 
    569 }; 
     571    pairs = query.split(/[&;]/); 
     572    for(var i = 0; i < pairs.length; ++i) { 
     573        keyValue = pairs[i].split(/=/); 
     574        if(keyValue.length == 2) { 
     575            args[decodeURIComponent(keyValue[0])] = 
     576                decodeURIComponent(keyValue[1]); 
     577        } 
     578    } 
     579    return args; 
     580
    570581 
    571582/**