@@ -20,6 +20,8 @@ var Lightbox = (function ($) {
20
20
var Default = {
21
21
title : '' ,
22
22
footer : '' ,
23
+ maxWidth : 9999 ,
24
+ maxHeight : 9999 ,
23
25
showArrows : true , //display the left / right arrows or not
24
26
wrapping : true , //if true, gallery loops infinitely
25
27
type : null , //force the lightbox into image / youtube mode. if null, or not image|youtube|vimeo; detect it
@@ -46,10 +48,8 @@ var Lightbox = (function ($) {
46
48
key : 'Default' ,
47
49
48
50
/**
49
-
50
- Class properties:
51
-
52
- _$element: null -> the <a> element currently being displayed
51
+ Class properties:
52
+ _$element: null -> the <a> element currently being displayed
53
53
_$modal: The bootstrap modal generated
54
54
_$modalDialog: The .modal-dialog
55
55
_$modalContent: The .modal-content
@@ -585,11 +585,19 @@ var Lightbox = (function ($) {
585
585
this . _wantedWidth = width ;
586
586
this . _wantedHeight = height ;
587
587
588
+ var imageAspecRatio = width / height ;
589
+
588
590
// if width > the available space, scale down the expected width and height
589
591
var widthBorderAndPadding = this . _padding . left + this . _padding . right + this . _border . left + this . _border . right ;
590
- var maxWidth = Math . min ( width + widthBorderAndPadding , this . _config . doc . body . clientWidth ) ;
592
+
593
+ // force 10px margin if window size > 575px
594
+ var addMargin = this . _config . doc . body . clientWidth > 575 ? 20 : 0 ;
595
+ var discountMargin = this . _config . doc . body . clientWidth > 575 ? 0 : 20 ;
596
+
597
+ var maxWidth = Math . min ( width + widthBorderAndPadding , this . _config . doc . body . clientWidth - addMargin , this . _config . maxWidth ) ;
598
+
591
599
if ( width + widthBorderAndPadding > maxWidth ) {
592
- height = ( maxWidth - widthBorderAndPadding ) / width * height ;
600
+ height = ( maxWidth - widthBorderAndPadding - discountMargin ) / imageAspecRatio ;
593
601
width = maxWidth ;
594
602
} else width = width + widthBorderAndPadding ;
595
603
@@ -607,15 +615,15 @@ var Lightbox = (function ($) {
607
615
//calculated each time as resizing the window can cause them to change due to Bootstraps fluid margins
608
616
var margins = parseFloat ( this . _$modalDialog . css ( 'margin-top' ) ) + parseFloat ( this . _$modalDialog . css ( 'margin-bottom' ) ) ;
609
617
610
- var maxHeight = Math . min ( height , $ ( window ) . height ( ) - borderPadding - margins - headerHeight - footerHeight ) ;
618
+ var maxHeight = Math . min ( height , $ ( window ) . height ( ) - borderPadding - margins - headerHeight - footerHeight , this . _config . maxHeight - borderPadding - headerHeight - footerHeight ) ;
619
+
611
620
if ( height > maxHeight ) {
612
621
// if height > the available height, scale down the width
613
- var factor = Math . min ( maxHeight / height , 1 ) ;
614
- width = Math . ceil ( factor * width ) ;
622
+ width = Math . ceil ( maxHeight * imageAspecRatio ) + widthBorderAndPadding ;
615
623
}
616
624
617
625
this . _$lightboxContainer . css ( 'height' , maxHeight ) ;
618
- this . _$modalDialog . css ( 'width ' , 'auto' ) . css ( 'maxWidth' , width ) ;
626
+ this . _$modalDialog . css ( 'flex ' , 1 ) . css ( 'maxWidth' , width ) ;
619
627
620
628
var modal = this . _$modal . data ( 'bs.modal' ) ;
621
629
if ( modal ) {
0 commit comments