X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=js%2Fsyp.js;h=a7586ca7d0fedc4232f1a85318f4bcc19dbba159;hp=c3613873523bb999d0e220a896c81de7d7127475;hb=726e61ea5e917d98fa8b58bbad46811304e23ff3;hpb=0fb779168df5af03f2a74b6bf1766d5a1c0f1a7e diff --git a/js/syp.js b/js/syp.js index c361387..a7586ca 100644 --- a/js/syp.js +++ b/js/syp.js @@ -241,11 +241,12 @@ var SYP = { }, showBigImage: function (href) { - try { - document.getElementById('bigimg_container').style.display = "table"; - } catch(e) { + if (OpenLayers.Util.getBrowserName() == "msie") { document.getElementById('bigimg_container').style.display = "block"; + } else { + document.getElementById('bigimg_container').style.display = "table"; } + var maxHeight = document.body.clientHeight * 0.9; var maxWidth = document.body.clientWidth * 0.9; document.getElementById('bigimg').style.height = ""; @@ -253,10 +254,6 @@ var SYP = { document.getElementById('bigimg').style.maxHeight = maxHeight + "px"; document.getElementById('bigimg').style.maxWidth = maxWidth + "px"; document.getElementById('bigimg').onload = function () { - var icon = document.getElementById('bigimg_close'); - icon.style.top = this.offsetTop; - icon.style.left = this.offsetLeft + this.clientWidth - icon.clientWidth; - var heightRatio = this.clientHeight / parseInt(this.style.maxHeight); var widthRatio = this.clientWidth / parseInt(this.style.maxWidth); if (heightRatio > 1 || widthRatio > 1) { @@ -267,6 +264,10 @@ var SYP = { } } + var icon = document.getElementById('bigimg_close'); + icon.style.top = this.offsetTop; + icon.style.left = this.offsetLeft + this.clientWidth - icon.clientWidth; + }; document.getElementById('bigimg').src = href; }, @@ -400,32 +401,87 @@ OpenLayers.Console.userError = function(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); - } - } +// dimensions of image is not known. Then, popup size is too small for its +// content. We work around the problem by checking that computed size is at +// least as big as content. To achieve that, we need to override +// OpenLayers.Popup.Anchored.prototype.updateSize to modify it slightly. +OpenLayers.Popup.Anchored.prototype.updateSize = function() { + // determine actual render dimensions of the contents by putting its + // contents into a fake contentDiv (for the CSS) and then measuring it + var preparedHTML = "