OpenLayers OpenLayers
Show
Ignore:
Timestamp:
08/29/08 12:28:20 (3 months ago)
Author:
euzuro
Message:

Fixing the sizing issues with the popups -- all this time, the 'size' parameter we were passing in to init a popup has been the *content* size, not the actual size of the popup. This confusion has stemmed from the fact that we weren't ever differentiating between the two. Now we are. Rename that parameter 'contentSize' in all the constructors. NOTE that this does not *break* API, it is merely renaming a variable. As such, no one should see any difference... other than the fact that autosized popups now stay their correct size when opened and closed repeatedly. Big thanks to jpulles for finding this bug and filing an accurate, informative, and detailed bug report. Thanks to ahocevar and crschmidt for reviewing. (Closes #1586)

Files:

Legend:

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

    r7887 r7897  
    4949 
    5050    /**  
     51     * Property: contentSize  
     52     * {<OpenLayers.Size>} the width and height of the content. 
     53     */ 
     54    contentSize: null,     
     55 
     56    /**  
    5157     * Property: size  
    5258     * {<OpenLayers.Size>} the width and height of the popup. 
     
    184190    * lonlat - {<OpenLayers.LonLat>}  The position on the map the popup will 
    185191    *                                 be shown. 
    186     * size - {<OpenLayers.Size>}      The size of the popup
     192    * contentSize - {<OpenLayers.Size>} The size of the content
    187193    * contentHTML - {String}          An HTML string to display inside the    
    188194    *                                 popup. 
     
    191197    * closeBoxCallback - {Function}   Function to be called on closeBox click. 
    192198    */ 
    193     initialize:function(id, lonlat, size, contentHTML, closeBox, closeBoxCallback) { 
     199    initialize:function(id, lonlat, contentSize, contentHTML, closeBox, closeBoxCallback) { 
    194200        if (id == null) { 
    195201            id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); 
     
    198204        this.id = id; 
    199205        this.lonlat = lonlat; 
    200         this.size = (size != null) ? size  
     206 
     207        this.contentSize = (contentSize != null) ? contentSize  
    201208                                  : new OpenLayers.Size( 
    202209                                                   OpenLayers.Popup.WIDTH, 
     
    219226 
    220227        var id = this.div.id + "_contentDiv"; 
    221         this.contentDiv = OpenLayers.Util.createDiv(id, null, this.size.clone(),  
     228        this.contentDiv = OpenLayers.Util.createDiv(id, null, this.contentSize.clone(),  
    222229                                                    null, "relative"); 
    223230        this.contentDiv.className = this.contentDisplayClass; 
     
    311318 
    312319        this.moveTo(px); 
    313         if (!this.autoSize) { 
    314             this.setSize(this.size); 
     320        if (!this.autoSize && !this.size) { 
     321            this.setSize(this.contentSize); 
    315322        } 
    316323        this.setBackgroundColor(); 
     
    400407     * 
    401408     * Parameters: 
    402      * size - {<OpenLayers.Size>} the new size of the popup's contents div 
    403      *     (in pixels). 
    404      */ 
    405     setSize:function(size) {  
    406         this.size = size;  
    407  
    408         var contentSize = this.size.clone(); 
     409     * contentSize - {<OpenLayers.Size>} the new size for the popup's  
     410     *     contents div (in pixels). 
     411     */ 
     412    setSize:function(contentSize) {  
     413        this.size = contentSize.clone();  
    409414         
    410415        // if our contentDiv has a css 'padding' set on it by a stylesheet, we  
     
    434439        // me want to shoot someone, but so it goes. 
    435440        if (OpenLayers.Util.getBrowserName() == "msie") { 
    436             contentSize.w += contentDivPadding.left + contentDivPadding.right; 
    437             contentSize.h += contentDivPadding.bottom + contentDivPadding.top; 
     441            this.contentSize.w +=  
     442                contentDivPadding.left + contentDivPadding.right; 
     443            this.contentSize.h +=  
     444                contentDivPadding.bottom + contentDivPadding.top; 
    438445        } 
    439446 
  • trunk/openlayers/lib/OpenLayers/Popup/Anchored.js

    r7656 r7897  
    3636    * id - {String} 
    3737    * lonlat - {<OpenLayers.LonLat>} 
    38     * size - {<OpenLayers.Size>} 
     38    * contentSize - {<OpenLayers.Size>} 
    3939    * contentHTML - {String} 
    4040    * anchor - {Object} Object which must expose a 'size' <OpenLayers.Size>  
     
    4343    * closeBoxCallback - {Function} Function to be called on closeBox click. 
    4444    */ 
    45     initialize:function(id, lonlat, size, contentHTML, anchor, closeBox, 
     45    initialize:function(id, lonlat, contentSize, contentHTML, anchor, closeBox, 
    4646                        closeBoxCallback) { 
    47         var newArguments = new Array(id, lonlat, size, contentHTML, closeBox, 
    48                                      closeBoxCallback); 
     47        var newArguments = [ 
     48            id, lonlat, contentSize, contentHTML, closeBox, closeBoxCallback 
     49        ]; 
    4950        OpenLayers.Popup.prototype.initialize.apply(this, newArguments); 
    5051 
     
    109110     *  
    110111     * Parameters: 
    111      * size - {<OpenLayers.Size>} 
     112     * contentSize - {<OpenLayers.Size>} the new size for the popup's  
     113     *     contents div (in pixels). 
    112114     */ 
    113     setSize:function(size) {  
     115    setSize:function(contentSize) {  
    114116        OpenLayers.Popup.prototype.setSize.apply(this, arguments); 
    115117 
     
    165167    calculateNewPx:function(px) { 
    166168        var newPx = px.offset(this.anchor.offset); 
     169         
     170        //use contentSize if size is not already set 
     171        var size = this.size || this.contentSize; 
    167172 
    168173        var top = (this.relativePosition.charAt(0) == 't'); 
    169         newPx.y += (top) ? -this.size.h : this.anchor.size.h; 
     174        newPx.y += (top) ? -size.h : this.anchor.size.h; 
    170175         
    171176        var left = (this.relativePosition.charAt(1) == 'l'); 
    172         newPx.x += (left) ? -this.size.w : this.anchor.size.w; 
     177        newPx.x += (left) ? -size.w : this.anchor.size.w; 
    173178 
    174179        return newPx;    
  • trunk/openlayers/lib/OpenLayers/Popup/AnchoredBubble.js

    r6718 r7897  
    2929     * id - {String} 
    3030     * lonlat - {<OpenLayers.LonLat>} 
    31      * size - {<OpenLayers.Size>} 
     31     * contentSize - {<OpenLayers.Size>} 
    3232     * contentHTML - {String} 
    3333     * anchor - {Object} Object to which we'll anchor the popup. Must expose  
     
    3737     * closeBoxCallback - {Function} Function to be called on closeBox click. 
    3838     */ 
    39     initialize:function(id, lonlat, size, contentHTML, anchor, closeBox, 
     39    initialize:function(id, lonlat, contentSize, contentHTML, anchor, closeBox, 
    4040                        closeBoxCallback) { 
    4141         
     
    8282     *  
    8383     * Parameters: 
    84      * size - {<OpenLayers.Size>} 
     84     * contentSize - {<OpenLayers.Size>} the new size for the popup's  
     85     *     contents div (in pixels). 
    8586     */ 
    86     setSize:function(size) {  
     87    setSize:function(contentSize) {  
    8788        OpenLayers.Popup.Anchored.prototype.setSize.apply(this, arguments); 
    8889 
  • trunk/openlayers/lib/OpenLayers/Popup/Framed.js

    r6800 r7897  
    8686     * id - {String} 
    8787     * lonlat - {<OpenLayers.LonLat>} 
    88      * size - {<OpenLayers.Size>} 
     88     * contentSize - {<OpenLayers.Size>} 
    8989     * contentHTML - {String} 
    9090     * anchor - {Object} Object to which we'll anchor the popup. Must expose  
     
    9494     * closeBoxCallback - {Function} Function to be called on closeBox click. 
    9595     */ 
    96     initialize:function(id, lonlat, size, contentHTML, anchor, closeBox,  
     96    initialize:function(id, lonlat, contentSize, contentHTML, anchor, closeBox,  
    9797                        closeBoxCallback) { 
    9898 
     
    189189     *  
    190190     * Parameters: 
    191      * size - {<OpenLayers.Size>} 
    192      */ 
    193     setSize:function(size) {  
     191     * contentSize - {<OpenLayers.Size>} the new size for the popup's  
     192     *     contents div (in pixels). 
     193     */ 
     194    setSize:function(contentSize) {  
    194195        OpenLayers.Popup.Anchored.prototype.setSize.apply(this, arguments); 
    195196 
     
    297298        } 
    298299         
    299         if (this.relativePosition) { 
     300        if (this.size && this.relativePosition) { 
    300301            var position = this.positionBlocks[this.relativePosition]; 
    301302            for (var i = 0; i < position.blocks.length; i++) { 
  • trunk/openlayers/lib/OpenLayers/Popup/FramedCloud.js

    r7684 r7897  
    204204     * id - {String} 
    205205     * lonlat - {<OpenLayers.LonLat>} 
    206      * size - {<OpenLayers.Size>} 
     206     * contentSize - {<OpenLayers.Size>} 
    207207     * contentHTML - {String} 
    208208     * anchor - {Object} Object to which we'll anchor the popup. Must expose  
     
    212212     * closeBoxCallback - {Function} Function to be called on closeBox click. 
    213213     */ 
    214     initialize:function(id, lonlat, size, contentHTML, anchor, closeBox,  
     214    initialize:function(id, lonlat, contentSize, contentHTML, anchor, closeBox,  
    215215                        closeBoxCallback) { 
    216216