Skip to content

Commit e445452

Browse files
RafaPolitashleydw
authored andcommitted
Fix aspect ratio issues, add max-width/max-height options. (ashleydw#274)
* Fixed aspect ratio issues for all sizes. Forced 10px margin when window size > 575px to keep a congruent display. Removed 15px margin for scroll. * Added HTML examples and created build. * Upped version.
1 parent 6bb8dac commit e445452

10 files changed

+90
-75
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
# Node
55
node_modules
66
.DS_Store
7+
8+
# Bower
9+
bower_components
10+

dist/ekko-lightbox.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ekko-lightbox.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ var Lightbox = (function ($) {
2020
var Default = {
2121
title: '',
2222
footer: '',
23+
maxWidth: 9999,
24+
maxHeight: 9999,
2325
showArrows: true, //display the left / right arrows or not
2426
wrapping: true, //if true, gallery loops infinitely
2527
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 ($) {
4648
key: 'Default',
4749

4850
/**
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
5353
_$modal: The bootstrap modal generated
5454
_$modalDialog: The .modal-dialog
5555
_$modalContent: The .modal-content
@@ -585,11 +585,19 @@ var Lightbox = (function ($) {
585585
this._wantedWidth = width;
586586
this._wantedHeight = height;
587587

588+
var imageAspecRatio = width / height;
589+
588590
// if width > the available space, scale down the expected width and height
589591
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+
591599
if (width + widthBorderAndPadding > maxWidth) {
592-
height = (maxWidth - widthBorderAndPadding) / width * height;
600+
height = (maxWidth - widthBorderAndPadding - discountMargin) / imageAspecRatio;
593601
width = maxWidth;
594602
} else width = width + widthBorderAndPadding;
595603

@@ -607,15 +615,15 @@ var Lightbox = (function ($) {
607615
//calculated each time as resizing the window can cause them to change due to Bootstraps fluid margins
608616
var margins = parseFloat(this._$modalDialog.css('margin-top')) + parseFloat(this._$modalDialog.css('margin-bottom'));
609617

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+
611620
if (height > maxHeight) {
612621
// 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;
615623
}
616624

617625
this._$lightboxContainer.css('height', maxHeight);
618-
this._$modalDialog.css('width', 'auto').css('maxWidth', width);
626+
this._$modalDialog.css('flex', 1).css('maxWidth', width);
619627

620628
var modal = this._$modal.data('bs.modal');
621629
if (modal) {

dist/ekko-lightbox.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)