diff --git a/lib/OpenLayers/Popup.js b/lib/OpenLayers/Popup.js index 94c4eec041..c2ebd6945c 100644 --- a/lib/OpenLayers/Popup.js +++ b/lib/OpenLayers/Popup.js @@ -47,6 +47,12 @@ OpenLayers.Popup = OpenLayers.Class({ */ div: null, + /** + * Property: contentSize + * {} the width and height of the content. + */ + contentSize: null, + /** * Property: size * {} the width and height of the popup. @@ -171,24 +177,26 @@ OpenLayers.Popup = OpenLayers.Class({ * an identifier will be automatically generated. * lonlat - {} The position on the map the popup will * be shown. - * size - {} The size of the popup. + * contentSize - {} The size of the content. * contentHTML - {String} The HTML content to display inside the * popup. * closeBox - {Boolean} Whether to display a close box inside * the popup. * closeBoxCallback - {Function} Function to be called on closeBox click. */ - initialize:function(id, lonlat, size, contentHTML, closeBox, closeBoxCallback) { + initialize:function(id, lonlat, contentSize, contentHTML, closeBox, closeBoxCallback) { if (id == null) { id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); } this.id = id; this.lonlat = lonlat; - this.size = (size != null) ? size + + this.contentSize = (contentSize != null) ? contentSize : new OpenLayers.Size( OpenLayers.Popup.WIDTH, OpenLayers.Popup.HEIGHT); + if (contentHTML != null) { this.contentHTML = contentHTML; } @@ -206,7 +214,7 @@ OpenLayers.Popup = OpenLayers.Class({ "hidden"); var id = this.div.id + "_contentDiv"; - this.contentDiv = OpenLayers.Util.createDiv(id, null, this.size.clone(), + this.contentDiv = OpenLayers.Util.createDiv(id, null, this.contentSize.clone(), null, "relative"); this.contentDiv.className = 'olPopupContent'; this.groupDiv.appendChild(this.contentDiv); @@ -298,8 +306,8 @@ OpenLayers.Popup = OpenLayers.Class({ } this.moveTo(px); - if (!this.autoSize) { - this.setSize(this.size); + if (!this.autoSize && !this.size) { + this.setSize(this.contentSize); } this.setBackgroundColor(); this.setOpacity(); @@ -390,10 +398,8 @@ OpenLayers.Popup = OpenLayers.Class({ * size - {} the new size of the popup's contents div * (in pixels). */ - setSize:function(size) { - this.size = size; - - var contentSize = this.size.clone(); + setSize:function(contentSize) { + this.size = contentSize.clone(); // if our contentDiv has a css 'padding' set on it by a stylesheet, we // must add that to the desired "size". @@ -421,8 +427,8 @@ OpenLayers.Popup = OpenLayers.Class({ // div itself bigger to take its own padding into effect. this makes // me want to shoot someone, but so it goes. if (OpenLayers.Util.getBrowserName() == "msie") { - contentSize.w += contentDivPadding.left + contentDivPadding.right; - contentSize.h += contentDivPadding.bottom + contentDivPadding.top; + this.contentSize.w += contentDivPadding.left + contentDivPadding.right; + this.contentSize.h += contentDivPadding.bottom + contentDivPadding.top; } if (this.div != null) { diff --git a/lib/OpenLayers/Popup/Anchored.js b/lib/OpenLayers/Popup/Anchored.js index a452b9dc27..432d7c7b0d 100644 --- a/lib/OpenLayers/Popup/Anchored.js +++ b/lib/OpenLayers/Popup/Anchored.js @@ -164,12 +164,15 @@ OpenLayers.Popup.Anchored = */ calculateNewPx:function(px) { var newPx = px.offset(this.anchor.offset); + + //use contentSize if size is not already set + var size = this.size || this.contentSize; var top = (this.relativePosition.charAt(0) == 't'); - newPx.y += (top) ? -this.size.h : this.anchor.size.h; + newPx.y += (top) ? -size.h : this.anchor.size.h; var left = (this.relativePosition.charAt(1) == 'l'); - newPx.x += (left) ? -this.size.w : this.anchor.size.w; + newPx.x += (left) ? -size.w : this.anchor.size.w; return newPx; }, diff --git a/tests/Popup.html b/tests/Popup.html index 8f24b4715f..e12f0876eb 100644 --- a/tests/Popup.html +++ b/tests/Popup.html @@ -16,7 +16,7 @@ t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers.Popup"), "valid default popupid"); var firstID = popup.id; - t.ok(popup.size.equals(size), "good default popup.size"); + t.ok(popup.contentSize.equals(size), "good default popup.size"); t.eq(popup.contentHTML, "", "good default popup.contentHTML"); t.eq(popup.backgroundColor, OpenLayers.Popup.COLOR, "good default popup.backgroundColor"); t.eq(popup.opacity, OpenLayers.Popup.OPACITY, "good default popup.opacity"); @@ -54,7 +54,7 @@ t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" ); t.eq(popup.id, id, "popup.id set correctly"); t.ok(popup.lonlat.equals(ll), "popup.lonlat set correctly"); - t.ok(popup.size.equals(sz), "popup.size set correctly"); + t.ok(popup.contentSize.equals(sz), "popup.size set correctly"); t.eq(popup.contentHTML, content, "contentHTML porpoerty of set correctly"); // test that a browser event is registered on click on popup closebox