From de485fbe85dc15d416ed08a51d6561fc8db0e078 Mon Sep 17 00:00:00 2001 From: arno Date: Sat, 25 Jul 2009 18:35:07 +0200 Subject: [PATCH 1/1] fixes: sometimes, popup with images do not autosize correctly --- js/syp.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/js/syp.js b/js/syp.js index d83b1fe..032a6ac 100644 --- a/js/syp.js +++ b/js/syp.js @@ -228,3 +228,35 @@ if (OpenLayers.Lang[SypStrings.language]) { OpenLayers.Console.userError = function(error) { SYP.Utils.displayUserMessage(error, "error"); } + +// sometimes, especially when cache is clear, firefox does not compute +// correctly popup size. That's because at the end of getRenderedDimensions, +// dimensions of image is not known. So, we work around that problem by setting +// image width and image height. That way, dimensions of image are set in +// innerHTML, and are therefore known in getRenderedDimensions +OpenLayers.Popup.Anchored.prototype.registerImageListeners = function() { + var onImgLoad = function() { + this.img.width = this.img.width; + this.img.height = this.img.height; + this.popup.updateSize(); + OpenLayers.Event.stopObserving( + this.img, "load", this.img._onImageLoad + ); + }; + + 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 + }; + + img._onImgLoad = OpenLayers.Function.bind(onImgLoad, context); + + OpenLayers.Event.observe(img, 'load', img._onImgLoad); + } + } +} -- 2.39.5