Adding registerImageListener() function that sits around and waits until images load in our popups... and when they do, it calls updateSize() so that the popup is sized correctly. thanks for the sharp review cr5 (Closes #1469)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@7887 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -590,15 +590,75 @@ OpenLayers.Popup = OpenLayers.Class({
|
||||
if ((this.contentDiv != null) &&
|
||||
(this.contentHTML != null) &&
|
||||
(this.contentHTML != this.contentDiv.innerHTML)) {
|
||||
|
||||
this.contentDiv.innerHTML = this.contentHTML;
|
||||
}
|
||||
|
||||
if (this.autoSize) {
|
||||
|
||||
//if popup has images, listen for when they finish
|
||||
// loading and resize accordingly
|
||||
this.registerImageListeners();
|
||||
|
||||
if (this.autoSize) {
|
||||
this.updateSize();
|
||||
}
|
||||
//auto size the popup to its current contents
|
||||
this.updateSize();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: registerImageListeners
|
||||
* Called when an image contained by the popup loaded. this function
|
||||
* updates the popup size, then unregisters the image load listener.
|
||||
*/
|
||||
registerImageListeners: function() {
|
||||
|
||||
// As the images load, this function will call updateSize() to
|
||||
// resize the popup to fit the content div (which presumably is now
|
||||
// bigger than when the image was not loaded).
|
||||
//
|
||||
// If the 'panMapIfOutOfView' property is set, we will pan the newly
|
||||
// resized popup back into view.
|
||||
//
|
||||
// Note that this function, when called, will have 'popup' and
|
||||
// 'img' properties in the context.
|
||||
//
|
||||
var onImgLoad = function() {
|
||||
|
||||
this.popup.updateSize();
|
||||
|
||||
if ( this.popup.visible() && this.popup.panMapIfOutOfView ) {
|
||||
this.popup.panIntoView();
|
||||
}
|
||||
|
||||
OpenLayers.Event.stopObserving(
|
||||
this.img, "load", this.img._onImageLoad
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
//cycle through the images and if their size is 0x0, that means that
|
||||
// they haven't been loaded yet, so we attach the listener, which
|
||||
// will fire when the images finish loading and will resize the
|
||||
// popup accordingly to its new size.
|
||||
var images = this.contentDiv.getElementsByTagName("img");
|
||||
for (var i = 0, len = images.length; i < len; i++) {
|
||||
var img = images[i];
|
||||
if (img.width == 0 || img.height == 0) {
|
||||
|
||||
var context = {
|
||||
'popup': this,
|
||||
'img': img
|
||||
};
|
||||
|
||||
//expando this function to the image itself before registering
|
||||
// it. This way we can easily and properly unregister it.
|
||||
img._onImgLoad = OpenLayers.Function.bind(onImgLoad, context);
|
||||
|
||||
OpenLayers.Event.observe(img, 'load', img._onImgLoad);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: getSafeContentSize
|
||||
|
||||
Reference in New Issue
Block a user