From 9760bc2ea7181617ed8a351b53af36558d22dd25 Mon Sep 17 00:00:00 2001 From: Pedro Pereira Date: Wed, 25 Mar 2015 16:49:21 +0800 Subject: [PATCH 1/2] Fetch image original either from data, or a set attribute - Support for microformats --- jquery.lazyload.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/jquery.lazyload.js b/jquery.lazyload.js index 26fab660..1fef1ddb 100644 --- a/jquery.lazyload.js +++ b/jquery.lazyload.js @@ -26,6 +26,7 @@ effect : "show", container : window, data_attribute : "original", + attribute : "contentUrl", skip_invisible : false, appear : null, load : null, @@ -57,6 +58,10 @@ } + function getOriginal($e) { + return $e.attr("data-" + settings.data_attribute) || $e.attr(settings.attribute); + } + if(options) { /* Maintain BC for a couple of versions. */ if (undefined !== options.failurelimit) { @@ -98,6 +103,8 @@ /* When appear is triggered load original image. */ $self.one("appear", function() { if (!this.loaded) { + var original = getOriginal($self); + if (settings.appear) { var elements_left = elements.length; settings.appear.call(self, elements_left, settings); @@ -105,7 +112,6 @@ $("") .bind("load", function() { - var original = $self.attr("data-" + settings.data_attribute); $self.hide(); if ($self.is("img")) { $self.attr("src", original); @@ -127,7 +133,7 @@ settings.load.call(self, elements_left, settings); } }) - .attr("src", $self.attr("data-" + settings.data_attribute)); + .attr("src", original); } }); From 5d3e2e4bb11addcf5592974a55fb5a4f1404e8df Mon Sep 17 00:00:00 2001 From: Pedro Pereira Date: Wed, 25 Mar 2015 18:14:14 +0800 Subject: [PATCH 2/2] Update README --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 1be45d8e..818788ea 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,17 @@ $("img.lazy").lazyload(); This causes all images of class lazy to be lazy loaded. +If you have adopted microformats ([schema.org](https://schema.org/ImageObject)'s example): +``` + +``` + +then in your code do: + +``` +$("img.lazy").lazyload({attribute: "contentUrl"}); +``` + More information on [Lazy Load](http://www.appelsiini.net/projects/lazyload) project page. ## Install