OpenLayers OpenLayers

Changeset 7311

Show
Ignore:
Timestamp:
06/05/08 16:37:40 (6 months ago)
Author:
tschaub
Message:

Adding a bit of flexibility to extend and applyDefaults. First argument can now be undefined. r=pspencer,elemoine (closes #1564)

Files:

Legend:

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

    r6748 r7311  
    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                } 
  • trunk/openlayers/lib/OpenLayers/Layer/KaMap.js

    r6748 r7311  
    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 
  • trunk/openlayers/lib/OpenLayers/Layer/MapServer.js

    r6418 r7311  
    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,  
  • trunk/openlayers/lib/OpenLayers/Layer/WFS.js

    r6495 r7311  
    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    },     
  • trunk/openlayers/lib/OpenLayers/Layer/WorldWind.js

    r6418 r7311  
    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    /** 
  • trunk/openlayers/lib/OpenLayers/Map.js

    r7190 r7311  
    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 
  • trunk/openlayers/lib/OpenLayers/Util.js

    r7299 r7311  
    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]; 
     
    523524 */ 
    524525OpenLayers.Util.applyDefaults = function (to, from) { 
    525  
     526    to = to || {}; 
    526527    /* 
    527528     * FF/Windows < 2.0.0.13 reports "Illegal operation on WrappedNative 
  • trunk/openlayers/tests/Util.html

    r7308 r7311  
    170170    function test_Util_applyDefaults(t) { 
    171171     
    172         t.plan(10); 
     172        t.plan(11); 
    173173         
    174174        var to = {  
     
    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 
     
    710716 
    711717    function tests_Util_extend(t) { 
    712         t.plan(6); 
     718        t.plan(7); 
    713719 
    714720        var source = { 
     
    737743             "undefined source properties don't clobber existing properties"); 
    738744        t.eq(window.property, undefined, "Property variable not clobbered."); 
     745         
     746        var destination; 
     747        var source = {rand: Math.random()}; 
     748        var ret = OpenLayers.Util.extend(destination, source); 
     749        t.eq(destination.rand, source.rand, "works with undefined destination"); 
     750         
    739751    } 
    740752