Skip to content

Commit

Permalink
load the image in the directive to fix #5
Browse files Browse the repository at this point in the history
  • Loading branch information
compact committed Oct 27, 2014
1 parent 654ad1f commit 063fc0d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
24 changes: 12 additions & 12 deletions dist/angular-bootstrap-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ angular.module('bootstrapLightbox').service('ImageLoader', function ($q) {
deferred.reject();
}

deferred.resolve();
deferred.resolve(image);
};

// when the image fails to load
Expand Down Expand Up @@ -348,7 +348,7 @@ angular.module('bootstrapLightbox').provider('Lightbox', function () {
* parent elements within the modal.
*/
angular.module('bootstrapLightbox').directive('lightboxSrc', function ($window,
Lightbox) {
ImageLoader, Lightbox) {
/**
* Calculate the dimensions to display the image. The max dimensions
* override the min dimensions if they conflict.
Expand Down Expand Up @@ -418,7 +418,7 @@ angular.module('bootstrapLightbox').directive('lightboxSrc', function ($window,

return {
'link': function (scope, element, attrs) {
// resize the image and the containing modal
// resize the img element and the containing modal
var resize = function () {
// get the window dimensions
var windowWidth = $window.innerWidth;
Expand Down Expand Up @@ -484,17 +484,17 @@ angular.module('bootstrapLightbox').directive('lightboxSrc', function ($window,
// http://stackoverflow.com/questions/5775469/whats-the-valid-way-to-include-an-image-with-no-src
element[0].src = '//:0';

var image = new Image();
image.src = src;
ImageLoader.load(src).then(function (image) {
// these variables must be set before resize(), as they are used in it
imageWidth = image.naturalWidth;
imageHeight = image.naturalHeight;

// these variables must be set before resize(), as they are used in it
imageWidth = image.naturalWidth;
imageHeight = image.naturalHeight;
// resize the img element and the containing modal
resize();

resize();

// show the image
element[0].src = src;
// show the image
element[0].src = src;
});
});

// resize the image and modal whenever the window gets resized
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-bootstrap-lightbox.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/image-loader-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ angular.module('bootstrapLightbox').service('ImageLoader', function ($q) {
deferred.reject();
}

deferred.resolve();
deferred.resolve(image);
};

// when the image fails to load
Expand Down
22 changes: 11 additions & 11 deletions src/lightbox-src-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* parent elements within the modal.
*/
angular.module('bootstrapLightbox').directive('lightboxSrc', function ($window,
Lightbox) {
ImageLoader, Lightbox) {
/**
* Calculate the dimensions to display the image. The max dimensions
* override the min dimensions if they conflict.
Expand Down Expand Up @@ -74,7 +74,7 @@ angular.module('bootstrapLightbox').directive('lightboxSrc', function ($window,

return {
'link': function (scope, element, attrs) {
// resize the image and the containing modal
// resize the img element and the containing modal
var resize = function () {
// get the window dimensions
var windowWidth = $window.innerWidth;
Expand Down Expand Up @@ -140,17 +140,17 @@ angular.module('bootstrapLightbox').directive('lightboxSrc', function ($window,
// http://stackoverflow.com/questions/5775469/whats-the-valid-way-to-include-an-image-with-no-src
element[0].src = '//:0';

var image = new Image();
image.src = src;
ImageLoader.load(src).then(function (image) {
// these variables must be set before resize(), as they are used in it
imageWidth = image.naturalWidth;
imageHeight = image.naturalHeight;

// these variables must be set before resize(), as they are used in it
imageWidth = image.naturalWidth;
imageHeight = image.naturalHeight;
// resize the img element and the containing modal
resize();

resize();

// show the image
element[0].src = src;
// show the image
element[0].src = src;
});
});

// resize the image and modal whenever the window gets resized
Expand Down

0 comments on commit 063fc0d

Please sign in to comment.