Permalink
Browse files

Merge pull request #31 from xixixao/fixcenterimage

Fixes centering of lightbox when no image present
  • Loading branch information...
jbutz committed Feb 27, 2013
2 parents b3f4197 + e22cc61 commit c19d452690e81b56b68a531939e076144b4a898e
Showing with 32 additions and 30 deletions.
  1. +32 −30 js/bootstrap-lightbox.js
View
@@ -202,41 +202,43 @@
that.h = that.$element.height();
that.w = that.$element.width();
-
+
if(that.options.resizeToFit)
{
-
- resizedOffs = 10;
$img = that.$element.find('.lightbox-content').find('img:first');
- // Save original filesize
- if(!$img.data('osizew')) $img.data('osizew', $img.width());
- if(!$img.data('osizeh')) $img.data('osizeh', $img.height());
-
- var osizew = $img.data('osizew');
- var osizeh = $img.data('osizeh');
-
- // Resize for window dimension < than image
- // Reset previous
- $img.css('max-width', 'none');
- $img.css('max-height', 'none');
-
-
- var wOffs = 50; // STYLE ?
- var hOffs = 40; // STYLE ?
- if(that.$element.find('.lightbox-header').length > 0)
+ if ($img.length)
{
- wOffs += 40;
- hOffs += 10;
- }
- if (that.$element.find('.lightbox-footer').length > 0) {
- hOffs += that.$element.find('.lightbox-footer').height();
- hOffs += 10;
+ resizedOffs = 10;
+ // Save original filesize
+ if(!$img.data('osizew')) $img.data('osizew', $img.width());
+ if(!$img.data('osizeh')) $img.data('osizeh', $img.height());
+
+ var osizew = $img.data('osizew');
+ var osizeh = $img.data('osizeh');
+
+ // Resize for window dimension < than image
+ // Reset previous
+ $img.css('max-width', 'none');
+ $img.css('max-height', 'none');
+
+
+ var wOffs = 50; // STYLE ?
+ var hOffs = 40; // STYLE ?
+ if(that.$element.find('.lightbox-header').length > 0)
+ {
+ wOffs += 40;
+ hOffs += 10;
+ }
+ if (that.$element.find('.lightbox-footer').length > 0) {
+ hOffs += that.$element.find('.lightbox-footer').height();
+ hOffs += 10;
+ }
+ $img.css('max-width', $(window).width() - wOffs);
+ $img.css('max-height', $(window).height() - hOffs);
+
+ that.w = $img.width();
+ that.h = $img.height();
}
- $img.css('max-width', $(window).width() - wOffs);
- $img.css('max-height', $(window).height() - hOffs);
-
- that.w = $img.width();
- that.h = $img.height();
}
that.$element.css({

0 comments on commit c19d452

Please sign in to comment.