Skip to content

Commit

Permalink
Add missing on ready for lazy loading of images
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraluiz committed Jan 25, 2016
1 parent 5724cd6 commit d7ae9e1
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions input/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,31 +205,32 @@ $("ul#bzoom").each(function(index, ul) {
});
});


// Lazy loading for images
var loadImage = function(self, imgSource) {
self.hide();
if (self.is("img")) {
self.attr("src", imgSource);
} else {
self.css("background-image", "url('" + imgSource + "')");
}
self.fadeIn("slow");
return self.removeClass("img-lazy").removeAttr("data-original");
};

var placeholder = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
$(".img-lazy").each(function() {
var self = $(this);
if (self.parent().is(":visible")) {
$(function() {
var loadImage = function(self, imgSource) {
self.hide();
if (self.is("img")) {
self.attr("src", placeholder);
self.attr("src", imgSource);
} else {
self.css("background-image", "url('" + imgSource + "')");
}
var imgSource = self.data("original");
return $("<img />").bind("load", function() {
return loadImage(self, imgSource);
}).attr("src", imgSource);
}
self.fadeIn("slow");
return self.removeClass("img-lazy").removeAttr("data-original");
};

var placeholder = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
$(".img-lazy").each(function() {
var self = $(this);
if (self.parent().is(":visible")) {
if (self.is("img")) {
self.attr("src", placeholder);
}
var imgSource = self.data("original");
return $("<img />").bind("load", function() {
return loadImage(self, imgSource);
}).attr("src", imgSource);
}
});
});


Expand Down

4 comments on commit d7ae9e1

@butenkor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lauraluiz not sure where do have document on ready event here?

@lauraluiz
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@butenkor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more shorthand... :) I think it is a bit confusing to use shorthand while other blocks in this file use different notation $(document).ready.

@lauraluiz
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just following the same way it is mostly used in this file.

Please sign in to comment.