OpenLayers OpenLayers

Ticket #1586: sizing.patch

File sizing.patch, 11.3 kB (added by euzuro, 4 months ago)

updated version of this patch

  • tests/Popup.html

    old new  
    1616        t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers.Popup"), 
    1717             "valid default popupid"); 
    1818        var firstID = popup.id; 
    19         t.ok(popup.size.equals(size), "good default popup.size"); 
     19        t.ok(popup.contentSize.equals(size), "good default popup.size"); 
    2020        t.eq(popup.contentHTML, null, "good default popup.contentHTML"); 
    2121        t.eq(popup.backgroundColor, OpenLayers.Popup.COLOR, "good default popup.backgroundColor"); 
    2222        t.eq(popup.opacity, OpenLayers.Popup.OPACITY, "good default popup.opacity"); 
     
    5454        t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" ); 
    5555        t.eq(popup.id, id, "popup.id set correctly"); 
    5656        t.ok(popup.lonlat.equals(ll), "popup.lonlat set correctly"); 
    57         t.ok(popup.size.equals(sz), "popup.size set correctly"); 
     57        t.ok(popup.contentSize.equals(sz), "popup.size set correctly"); 
    5858        t.eq(popup.contentHTML, content, "contentHTML porpoerty of set correctly"); 
    5959 
    6060        // test that a browser event is registered on click on popup closebox 
  • lib/OpenLayers/Popup/FramedCloud.js

    old new  
    203203     * Parameters: 
    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  
    209209     *     a 'size' (<OpenLayers.Size>) and 'offset' (<OpenLayers.Pixel>)  
     
    211211     * closeBox - {Boolean} 
    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 
    217217        this.imageSrc = OpenLayers.Util.getImagesLocation() + 'cloud-popup-relative.png'; 
  • lib/OpenLayers/Popup/Framed.js

    old new  
    8585     * Parameters: 
    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  
    9191     *     a 'size' (<OpenLayers.Size>) and 'offset' (<OpenLayers.Pixel>)  
     
    9393     * closeBox - {Boolean} 
    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 
    9999        OpenLayers.Popup.Anchored.prototype.initialize.apply(this, arguments); 
     
    188188     *     of the popup has changed. 
    189189     *  
    190190     * Parameters: 
    191      * size - {<OpenLayers.Size>} 
     191     * contentSize - {<OpenLayers.Size>} the new size for the popup's  
     192     *     contents div (in pixels). 
    192193     */ 
    193     setSize:function(size) {  
     194    setSize:function(contentSize) {  
    194195        OpenLayers.Popup.Anchored.prototype.setSize.apply(this, arguments); 
    195196 
    196197        this.updateBlocks(); 
     
    296297            this.createBlocks(); 
    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++) { 
    302303     
  • lib/OpenLayers/Popup/AnchoredBubble.js

    old new  
    2828     * Parameters: 
    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  
    3434     *     a 'size' (<OpenLayers.Size>) and 'offset' (<OpenLayers.Pixel>)  
     
    3636     * closeBox - {Boolean} 
    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         
    4242        this.padding = new OpenLayers.Bounds( 
     
    8181     * APIMethod: setSize 
    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 
    8990        this.setRicoCorners(); 
  • lib/OpenLayers/Popup/Anchored.js

    old new  
    3535    * Parameters: 
    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>  
    4141    *     and 'offset' <OpenLayers.Pixel> (generally an <OpenLayers.Icon>). 
    4242    * closeBox - {Boolean} 
    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 
    5152        this.anchor = (anchor != null) ? anchor  
     
    108109     * APIMethod: setSize 
    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 
    116118        if ((this.lonlat) && (this.map)) { 
     
    164166     */ 
    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;    
    175180    }, 
  • lib/OpenLayers/Popup.js

    old new  
    4848    div: null, 
    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. 
    5359     */ 
     
    183189    *               an identifier will be automatically generated.  
    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. 
    189195    * closeBox - {Boolean}            Whether to display a close box inside 
    190196    *                                 the 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 + "_"); 
    196202        } 
    197203 
    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, 
    203210                                                   OpenLayers.Popup.HEIGHT); 
     
    218225                                                    "hidden"); 
    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; 
    224231        this.groupDiv.appendChild(this.contentDiv); 
     
    310317        } 
    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(); 
    317324        this.setOpacity(); 
     
    399406     * Used to adjust the size of the popup.  
    400407     * 
    401408     * Parameters: 
    402      * size - {<OpenLayers.Size>} the new size of the popup's contents div 
    403      *     (in pixels). 
     409     * contentSize - {<OpenLayers.Size>} the new size for the popup's  
     410     *     contents div (in pixels). 
    404411     */ 
    405     setSize:function(size) {  
    406         this.size = size;  
    407  
    408         var contentSize = this.size.clone(); 
     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  
    411416        //  must add that to the desired "size".  
     
    433438        // div itself bigger to take its own padding into effect. this makes  
    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 
    440447        if (this.div != null) {