OpenLayers OpenLayers

Ticket #1586: Popup.patch

File Popup.patch, 5.8 kB (added by sbenthall, 5 months ago)

patch to Popup.js, Anchored.js, and tests

  • 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, "", "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/Anchored.js

    old new  
    164164     */ 
    165165    calculateNewPx:function(px) { 
    166166        var newPx = px.offset(this.anchor.offset); 
     167         
     168        //use contentSize if size is not already set 
     169        var size = this.size || this.contentSize; 
    167170 
    168171        var top = (this.relativePosition.charAt(0) == 't'); 
    169         newPx.y += (top) ? -this.size.h : this.anchor.size.h; 
     172        newPx.y += (top) ? -size.h : this.anchor.size.h; 
    170173         
    171174        var left = (this.relativePosition.charAt(1) == 'l'); 
    172         newPx.x += (left) ? -this.size.w : this.anchor.size.w; 
     175        newPx.x += (left) ? -size.w : this.anchor.size.w; 
    173176 
    174177        return newPx;    
    175178    }, 
  • 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     */ 
     
    171177    *               an identifier will be automatically generated.  
    172178    * lonlat - {<OpenLayers.LonLat>}  The position on the map the popup will 
    173179    *                                 be shown. 
    174     * size - {<OpenLayers.Size>}      The size of the popup
     180    * contentSize - {<OpenLayers.Size>}      The size of the content
    175181    * contentHTML - {String}          The HTML content to display inside the  
    176182    *                                 popup. 
    177183    * closeBox - {Boolean}            Whether to display a close box inside 
    178184    *                                 the popup. 
    179185    * closeBoxCallback - {Function}   Function to be called on closeBox click. 
    180186    */ 
    181     initialize:function(id, lonlat, size, contentHTML, closeBox, closeBoxCallback) { 
     187    initialize:function(id, lonlat, contentSize, contentHTML, closeBox, closeBoxCallback) { 
    182188        if (id == null) { 
    183189            id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); 
    184190        } 
    185191 
    186192        this.id = id; 
    187193        this.lonlat = lonlat; 
    188         this.size = (size != null) ? size  
     194         
     195        this.contentSize = (contentSize != null) ? contentSize  
    189196                                  : new OpenLayers.Size( 
    190197                                                   OpenLayers.Popup.WIDTH, 
    191198                                                   OpenLayers.Popup.HEIGHT); 
     199         
    192200        if (contentHTML != null) {  
    193201             this.contentHTML = contentHTML; 
    194202        } 
     
    206214                                                    "hidden"); 
    207215 
    208216        var id = this.div.id + "_contentDiv"; 
    209         this.contentDiv = OpenLayers.Util.createDiv(id, null, this.size.clone(),  
     217        this.contentDiv = OpenLayers.Util.createDiv(id, null, this.contentSize.clone(),  
    210218                                                    null, "relative"); 
    211219        this.contentDiv.className = 'olPopupContent';                                             
    212220        this.groupDiv.appendChild(this.contentDiv); 
     
    298306        } 
    299307 
    300308        this.moveTo(px); 
    301         if (!this.autoSize) { 
    302             this.setSize(this.size); 
     309        if (!this.autoSize && !this.size) { 
     310            this.setSize(this.contentSize); 
    303311        } 
    304312        this.setBackgroundColor(); 
    305313        this.setOpacity(); 
     
    390398     * size - {<OpenLayers.Size>} the new size of the popup's contents div 
    391399     *     (in pixels). 
    392400     */ 
    393     setSize:function(size) {  
    394         this.size = size;  
    395  
    396         var contentSize = this.size.clone(); 
     401    setSize:function(contentSize) {  
     402        this.size = contentSize.clone();  
    397403         
    398404        // if our contentDiv has a css 'padding' set on it by a stylesheet, we  
    399405        //  must add that to the desired "size".  
     
    421427        // div itself bigger to take its own padding into effect. this makes  
    422428        // me want to shoot someone, but so it goes. 
    423429        if (OpenLayers.Util.getBrowserName() == "msie") { 
    424             contentSize.w += contentDivPadding.left + contentDivPadding.right; 
    425             contentSize.h += contentDivPadding.bottom + contentDivPadding.top; 
     430            this.contentSize.w += contentDivPadding.left + contentDivPadding.right; 
     431            this.contentSize.h += contentDivPadding.bottom + contentDivPadding.top; 
    426432        } 
    427433 
    428434        if (this.div != null) {