Fix for non auto-size popups that were progressively expanding each time they were opened. a little investigation showed us that there was some unfortunate ambiguity with the 'size' property, which was alternatively being used as 'size' and 'contentSize'. cheers to seb for an elegant solution r=cr5,me (Closes #1586)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@7647 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2008-07-31 20:40:00 +00:00
parent a2905538d8
commit c953579eb9
3 changed files with 25 additions and 16 deletions

View File

@@ -47,6 +47,12 @@ OpenLayers.Popup = OpenLayers.Class({
*/
div: null,
/**
* Property: contentSize
* {<OpenLayers.Size>} the width and height of the content.
*/
contentSize: null,
/**
* Property: size
* {<OpenLayers.Size>} the width and height of the popup.
@@ -171,24 +177,26 @@ OpenLayers.Popup = OpenLayers.Class({
* an identifier will be automatically generated.
* lonlat - {<OpenLayers.LonLat>} The position on the map the popup will
* be shown.
* size - {<OpenLayers.Size>} The size of the popup.
* contentSize - {<OpenLayers.Size>} 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 - {<OpenLayers.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) {

View File

@@ -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;
},

View File

@@ -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