Skip to content
This repository has been archived by the owner on May 22, 2020. It is now read-only.

Wait for Image loaded to calc height #122

Closed
ximex opened this issue Jul 9, 2015 · 5 comments
Closed

Wait for Image loaded to calc height #122

ximex opened this issue Jul 9, 2015 · 5 comments

Comments

@ximex
Copy link

ximex commented Jul 9, 2015

Admidio/admidio#67

ekko-lightbox.js Line 315ff

preloadImage: function(src, onLoadShowImage) {
  var img,
    _this = this;
  img = new Image();
  if ((onLoadShowImage == null) || onLoadShowImage === true) {
    img.onload = function() {
      var image;
      image = $('<img />');
      image.attr('src', img.src);
      image.addClass('img-responsive');
      _this.lightbox_body.html(image);
      if (_this.modal_arrows) {
        _this.modal_arrows.css('display', 'block');
      }
      // Start Fix
      image.load(function() {
        _this.resize(img.width);
      });
      // End Fix
      return _this.options.onContentLoaded.call(_this);
    };
    img.onerror = function() {
      return _this.error('Failed to load image: ' + src);
    };
  }
  img.src = src;
  return img;
}
@AuspeXeu
Copy link
Contributor

@ximex can you file a PR for that change?

@ximex
Copy link
Author

ximex commented Aug 17, 2015

#126

@AuspeXeu
Copy link
Contributor

👍

@ashleydw
Copy link
Owner

Can anyone explain why the original img.onload fails to handle this? This is a load inside an onload

@ximex
Copy link
Author

ximex commented Aug 18, 2015

@ashleydw look carefully:
it's a image.load() in a img.onload()! (img != image)

the problem is that chrome and safari execute _this.resize() before the image is really completed loaded. and so the resize will lead to in 0x0 px.
if we wait for the jquery/domevent that the image is loaded it works.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants