LightBox showing image outside window

UI Components for JSF
Post Reply
ciaporte
Posts: 7
Joined: 28 May 2015, 20:35

26 Apr 2017, 22:47

For some large images (2592x1936) p:lightBox showing image outside window (full hd monitor).
The problem is on LightBox.scaleImage function, check this piece of code:

Code: Select all

	if(imageWidth >= winWidth && ratio <= 1){
            imageWidth = winWidth * 0.75;
            imageHeight = imageWidth * ratio;
        } 
        else if(imageHeight >= winHeight){
            imageHeight = winHeight * 0.75;
            imageWidth = imageHeight / ratio;
        }
As the width of the image is larger than the screen, it enter on if, but this resizing only checks the width, so even after resizing it still gets higher than the screen.
A simple solution is remove the else, so it will check the height and adjust it.

Workaround:

Code: Select all

PrimeFaces.widget.LightBox.prototype.scaleImage = function(image) {
    var win = $(window),
    winWidth = win.width(),
    winHeight = win.height(),
    imageWidth = image.width(),
    imageHeight = image.height(),
    ratio = imageHeight / imageWidth;
    
    if(imageWidth >= winWidth && ratio <= 1){
        imageWidth = winWidth * 0.75;
        imageHeight = imageWidth * ratio;
    } 
    if(imageHeight >= winHeight){
        imageHeight = winHeight * 0.75;
        imageWidth = imageHeight / ratio;
    }
    
    image.css({
        'width':imageWidth + 'px'
        ,'height':imageHeight + 'px'
    })
};

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 53 guests