From cdc5e97431ee5381013015af5c959b569fd8e12a Mon Sep 17 00:00:00 2001 From: Semirke Date: Mon, 4 Aug 2014 10:42:16 +0200 Subject: [PATCH] Added image resize to screen support New config vars: - resizeToImg: if true, resizes div to content image. Only allowed if content == "image". - resizeToMaxScreen: resize to be this ratio to screen. 0 disables it. 0..1 allowed (1=100%). --- jquery.bpopup.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/jquery.bpopup.js b/jquery.bpopup.js index 363911b..09bb0a4 100644 --- a/jquery.bpopup.js +++ b/jquery.bpopup.js @@ -170,15 +170,59 @@ //Eksperimental function recenter(content){ + if(o.resizeToImg){ + if(o.content != "image") + { + alert('You cannot use "resizeToImg" on not images content.'); + } + // Create new offscreen image to test + var theImage = new Image(); + theImage.src = content.attr("src"); + + // Get accurate measurements from that. + var imageWidth = theImage.width; + var imageHeight = theImage.height; + + if(o.resizeToMaxScreen > 0){ + if(imageWidth > $(window).width() * o.resizeToMaxScreen) + { + var sw = $(window).width() * o.resizeToMaxScreen; + var r=0; + + r = sw / imageWidth; + + imageWidth=sw; + imageHeight *= r; + } + + if(imageHeight > $(window).height() * o.resizeToMaxScreen) + { + var sw = $(window).height() * o.resizeToMaxScreen; + var r=0; + + r = sw / imageHeight; + + imageHeight=sw; + imageWidth *= r; + } + } + + content.css({width: imageWidth, height: imageHeight}); + $popup.css({width: imageWidth, height: imageHeight}); + + } var _width = content.width(), _height = content.height(), css = {}; + o.contentContainer.css({height:_height,width:_width}); + if (_height >= $popup.height()){ css.height = $popup.height(); } if(_width >= $popup.width()){ css.width = $popup.width(); } + height = $popup.outerHeight(true) , width = $popup.outerWidth(true); @@ -350,6 +394,8 @@ , opacity: 0.7 , position: ['auto', 'auto'] // x, y, , positionStyle: 'absolute'// absolute or fixed + , resizeToImg: false + , resizeToMaxScreen: 1 // Allow image to be (0..1)*100% of screen; 0: disable , scrollBar: true , speed: 250 // open & close speed , transition: 'fadeIn' //transitions: fadeIn, slideDown, slideIn, slideBack