OpenLayers OpenLayers

Ticket #1564: util.patch

File util.patch, 6.6 kB (added by tschaub, 7 months ago)

flexible extend and applyDefaults

  • tests/Util.html

    old new  
    169169 
    170170    function test_Util_applyDefaults(t) { 
    171171     
    172         t.plan(10); 
     172        t.plan(11); 
    173173         
    174174        var to = {  
    175175            'a': "abra", 
     
    198198        t.eq( ret["c"], "press", "key present in from and not ret successfully copied to ret"); 
    199199        t.eq(to.toString(), "works", "correctly applies custom toString"); 
    200200        t.eq(to.n, null, "correctly preserves null"); 
     201         
     202        var to; 
     203        var from = {rand: Math.random()}; 
     204         
     205        var ret = OpenLayers.Util.applyDefaults(to, from); 
     206        t.eq(ret.rand, from.rand, "works with undefined to"); 
    201207    } 
    202208 
    203209    function test_Util_getParameterString(t) { 
     
    693699    } 
    694700 
    695701    function tests_Util_extend(t) { 
    696         t.plan(6); 
     702        t.plan(7); 
    697703 
    698704        var source = { 
    699705            num: Math.random(), 
     
    720726        t.eq(destination.nada, "untouched", 
    721727             "undefined source properties don't clobber existing properties"); 
    722728        t.eq(window.property, undefined, "Property variable not clobbered."); 
     729         
     730        var destination; 
     731        var source = {rand: Math.random()}; 
     732        var ret = OpenLayers.Util.extend(destination, source); 
     733        t.eq(destination.rand, source.rand, "works with undefined destination"); 
     734         
    723735    } 
    724736     
    725737    function test_XX_Util_Try(t) { 
  • lib/OpenLayers/Format/KML.js

    old new  
    550550                if (inlineStyleNode) { 
    551551                    var inlineStyle= this.parseStyle(inlineStyleNode); 
    552552                    if (inlineStyle) { 
    553                         feature.style = OpenLayers.Util.extend({},  
    554                                             feature.style); 
    555                         OpenLayers.Util.extend(feature.style, inlineStyle); 
     553                        feature.style = OpenLayers.Util.extend( 
     554                            feature.style, inlineStyle 
     555                        ); 
    556556                    } 
    557557                } 
    558558 
  • lib/OpenLayers/Map.js

    old new  
    13351335     *    false. 
    13361336     */ 
    13371337    pan: function(dx, dy, options) { 
    1338         // this should be pushed to applyDefaults and extend 
    1339         if (!options) { 
    1340             options = {}; 
    1341         } 
    1342         OpenLayers.Util.applyDefaults(options, { 
     1338        options = OpenLayers.Util.applyDefaults(options, { 
    13431339            animate: true, 
    13441340            dragging: false 
    13451341        }); 
  • lib/OpenLayers/Util.js

    old new  
    4949 * {Object} The destination object. 
    5050 */ 
    5151OpenLayers.Util.extend = function(destination, source) { 
    52     if(destination && source) { 
     52    destination = destination || {}; 
     53    if(source) { 
    5354        for(var property in source) { 
    5455            var value = source[property]; 
    5556            if(value !== undefined) { 
     
    521522 *     in place and returned by this function. 
    522523 */ 
    523524OpenLayers.Util.applyDefaults = function (to, from) { 
    524  
     525    to = to || {}; 
    525526    /* 
    526527     * FF/Windows < 2.0.0.13 reports "Illegal operation on WrappedNative 
    527528     * prototype object" when calling hawOwnProperty if the source object is an 
  • lib/OpenLayers/Layer/MapServer.js

    old new  
    4242        newArguments.push(name, url, params, options); 
    4343        OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); 
    4444 
    45         if (arguments.length > 0) { 
    46             OpenLayers.Util.applyDefaults( 
    47                            this.params, 
    48                            this.DEFAULT_PARAMS 
    49                            ); 
    50         } 
     45        this.params = OpenLayers.Util.applyDefaults( 
     46            this.params, this.DEFAULT_PARAMS 
     47        ); 
    5148 
    5249        // unless explicitly set in options, if the layer is transparent,  
    5350        // it will be an overlay 
  • lib/OpenLayers/Layer/WorldWind.js

    old new  
    5454        var newArguments = []; 
    5555        newArguments.push(name, url, params, options); 
    5656        OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); 
    57         this.params = (params ? params : {}); 
    58         if (params) { 
    59             OpenLayers.Util.applyDefaults( 
    60                            this.params,  
    61                            this.DEFAULT_PARAMS 
    62                            ); 
    63         } 
     57        this.params = OpenLayers.Util.applyDefaults( 
     58            this.params, this.DEFAULT_PARAMS 
     59        ); 
    6460    }, 
    6561    /** 
    6662     * Method: addTile 
  • lib/OpenLayers/Layer/KaMap.js

    old new  
    6464        var newArguments = []; 
    6565        newArguments.push(name, url, params, options); 
    6666        OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); 
    67         this.params = (params ? params : {}); 
    68         if (params) { 
    69             OpenLayers.Util.applyDefaults( 
    70                            this.params,  
    71                            this.DEFAULT_PARAMS 
    72                            ); 
    73         } 
     67        this.params = OpenLayers.Util.applyDefaults( 
     68            this.params, this.DEFAULT_PARAMS 
     69        ); 
    7470    }, 
    7571 
    7672    /** 
  • lib/OpenLayers/Layer/WFS.js

    old new  
    138138            this.options.geometry_column = "the_geom"; 
    139139        }     
    140140         
    141         this.params = params; 
    142         OpenLayers.Util.applyDefaults( 
    143                        this.params,  
    144                        OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS) 
    145                        ); 
     141        this.params = OpenLayers.Util.applyDefaults( 
     142            params,  
     143            OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS) 
     144        ); 
    146145        this.url = url; 
    147146    },     
    148147