From aa5fc0ac8261f4d86c9ab0b0ea65774b8bb50b22 Mon Sep 17 00:00:00 2001 From: Eisbehr Date: Tue, 2 Aug 2016 14:24:04 +0200 Subject: [PATCH] 1.7.2 - fixed possible problems with jQuery 3's new async ready state - added 'main' field to package.json - changed '.error()' to '.trigger("error")' - new 'picture' plugin - new 'vimeo' plugin - added cross domain / CORS hedaers to 'iframe' plugin - corrected error response of 'youtube' plugin --- README.md | 8 +- bower.json | 2 +- jquery.lazy.js | 20 ++- jquery.lazy.min.js | 4 +- jquery.lazy.plugins.js | 197 ++++++++++++++++++++++++++++- jquery.lazy.plugins.min.js | 2 +- package.json | 2 +- plugins/README.md | 50 +++++++- plugins/jquery.lazy.iframe.js | 4 +- plugins/jquery.lazy.iframe.min.js | 4 +- plugins/jquery.lazy.picture.js | 157 +++++++++++++++++++++++ plugins/jquery.lazy.picture.min.js | 2 + plugins/jquery.lazy.vimeo.js | 30 +++++ plugins/jquery.lazy.vimeo.min.js | 2 + plugins/jquery.lazy.youtube.js | 4 +- plugins/jquery.lazy.youtube.min.js | 4 +- 16 files changed, 467 insertions(+), 25 deletions(-) create mode 100644 plugins/jquery.lazy.picture.js create mode 100644 plugins/jquery.lazy.picture.min.js create mode 100644 plugins/jquery.lazy.vimeo.js create mode 100644 plugins/jquery.lazy.vimeo.min.js diff --git a/README.md b/README.md index 0086a0e..7a202b7 100644 --- a/README.md +++ b/README.md @@ -57,12 +57,12 @@ Some examples below: Lazy and all plugins are available over [cdnjs](http://cdnjs.com) and [jsDelivr](http://jsdelivr.com) CDN and can directly included to every page. ```HTML - - + + - - + + ``` #### Self-Hosted diff --git a/bower.json b/bower.json index 557a331..b1a7434 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "jquery-lazy", "description": "Lazy is a fast, feature-rich and lightweight delayed content loading plugin for jQuery and Zepto. It's designed to speed up page loading times and decrease traffic to your users by only loading the content in view. You can use Lazy in all vertical and horizontal scroll ways. It supports images in 'img' tags and backgrounds, supplied with css like 'background-image', by default. On those elements Lazy can set an default image or a placeholder while loading and supports retina displays as well. But Lazy is even able to load any other content you want by plugins and custom loaders.", - "version": "1.7.1", + "version": "1.7.2", "main": "jquery.lazy.min.js", "license": [ "MIT", diff --git a/jquery.lazy.js b/jquery.lazy.js index 1935d5c..0678c93 100644 --- a/jquery.lazy.js +++ b/jquery.lazy.js @@ -1,5 +1,5 @@ /*! - * jQuery & Zepto Lazy - v1.7.1 + * jQuery & Zepto Lazy - v1.7.2 * http://jquery.eisbehr.de/lazy/ * * Copyright 2012 - 2016, Daniel 'Eisbehr' Kern @@ -25,7 +25,13 @@ * unique plugin instance id counter * @type {number} */ - lazyInstanceId = 0; + lazyInstanceId = 0, + + /** + * helper to register window load for jQuery 3 + * @type {boolean} + */ + windowLoaded = false; /** * make lazy available to jquery - and make it a bit more case-insensitive :) @@ -409,7 +415,7 @@ element.off(_error); errorCallback(); } - })) element.error(); + })) element.trigger(_error); } // handle images @@ -601,8 +607,8 @@ return false; } - // if event driven don't wait for page loading - if( config.bind == "event" ) + // if event driven or window is already loaded don't wait for page loading + if( config.bind == "event" || windowLoaded ) _initialize(); // otherwise load initial items and start lazy after page load @@ -787,4 +793,8 @@ onError : undefined, onFinishedAll : undefined }; + + // register window load event globally to prevent not loading elements + // since jQuery 3.X ready state is fully async and may be executed after 'load' + $(window).on("load", function() { windowLoaded = true; }); })(window); \ No newline at end of file diff --git a/jquery.lazy.min.js b/jquery.lazy.min.js index ef3d712..76c9b8b 100644 --- a/jquery.lazy.min.js +++ b/jquery.lazy.min.js @@ -1,2 +1,2 @@ -/*! jQuery Lazy 1.7.1 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2016 Daniel 'Eisbehr' Kern */ -!function(t,e){"use strict";function r(r,a,i,o,l){function u(){B=t.devicePixelRatio>1,c(i),a.delay>=0&&setTimeout(function(){f(!0)},a.delay),(a.delay<0||a.combined)&&(o.e=g(a.throttle,function(t){"resize"===t.type&&(z=w=-1),f(t.all)}),o.a=function(t){c(t),i.push.apply(i,t)},o.g=function(){return i=n(i).filter(function(){return!n(this).data(a.loadedName)})},f(),n(a.appendScroll).on("scroll."+l+" resize."+l,o.e))}function c(t){var i=a.defaultImage,o=a.placeholder,l=a.imageBase,u=a.srcsetAttribute,c=a.loaderAttribute,f=a._f||{};t=n(t).filter(function(){var t=n(this),r=h(this);return!t.data(a.handledName)&&(t.attr(a.attribute)||t.attr(u)||t.attr(c)||f[r]!=e)}).data("plugin_"+a.name,r);for(var s=0,d=t.length;d>s;s++){var A=n(t[s]),m=h(t[s]),g=A.attr(a.imageBaseAttribute)||l;m==I&&g&&A.attr(u)&&A.attr(u,b(A.attr(u),g)),f[m]==e||A.attr(c)||A.attr(c,f[m]),m==I&&i&&!A.attr(N)?A.attr(N,i):m==I||!o||A.css(C)&&"none"!=A.css(C)||A.css(C,"url('"+o+"')")}}function f(t){if(!i.length)return void(a.autoDestroy&&r.destroy());for(var e=!1,o=a.imageBase||"",l=a.srcsetAttribute,u=a.handledName,c=0,f=i.length;f>c;c++)(function(r){if(t||d(r)){var i=n(r),c=h(r),f=i.attr(a.attribute),A=i.attr(a.imageBaseAttribute)||o,m=i.attr(a.loaderAttribute);i.data(u)||a.visibleOnly&&!i.is(":visible")||!((f||i.attr(l))&&(c==I&&(A+f!=i.attr(N)||i.attr(l)!=i.attr(E))||c!=I&&A+f!=i.css(C))||m)||(e=!0,i.data(u,!0),s(i,c,A,m))}})(i[c]);e&&(i=n(i).filter(function(){return!n(this).data(u)}))}function s(t,e,r,i){++y;var o=function(){p("onError",t),v(),o=n.noop};p("beforeLoad",t);var l=a.attribute,u=a.srcsetAttribute,c=a.sizesAttribute,f=a.retinaAttribute,s=a.removeAttribute,d=a.loadedName,A=t.attr(f);if(i){var m=function(){s&&t.removeAttr(a.loaderAttribute),t.data(d,!0),p(L,t),setTimeout(v,1),m=n.noop};t.off(D).one(D,o).one(T,m),p(i,t,function(e){e?(t.off(T),m()):(t.off(D),o())})||t.error()}else{var h=n(new Image);h.one(D,o).one(T,function(){t.hide(),e==I?t.attr(F,h.attr(F)).attr(E,h.attr(E)).attr(N,h.attr(N)):t.css(C,"url('"+h.attr(N)+"')"),t[a.effect](a.effectTime),s&&(t.removeAttr(l+" "+u+" "+f+" "+a.imageBaseAttribute),c!==F&&t.removeAttr(c)),t.data(d,!0),p(L,t),h.remove(),v()});var b=(B&&A?A:t.attr(l))||"";h.attr(F,t.attr(c)).attr(E,t.attr(u)).attr(N,b?r+b:null),h.complete&&h.load()}}function d(t){var e=t.getBoundingClientRect(),r=a.scrollDirection,n=a.threshold,i=m()+n>e.top&&-ne.left&&-n=0?z:z=n(t).width()}function m(){return w>=0?w:w=n(t).height()}function h(t){return t.tagName.toLowerCase()}function b(t,e){if(e){var r=t.split(",");t="";for(var a=0,n=r.length;n>a;a++)t+=e+r[a].trim()+(a!==n-1?",":"")}return t}function g(t,e){var n,i=0;return function(o,l){function u(){i=+new Date,e.call(r,o)}var c=+new Date-i;n&&clearTimeout(n),c>t||!a.enableThrottle||l?u():n=setTimeout(u,t-c)}}function v(){--y,i.length||y||p("onFinishedAll")}function p(t,e,n){return(t=a[t])?(t.apply(r,[].slice.call(arguments,1)),!0):!1}var y=0,z=-1,w=-1,B=!1,L="afterLoad",T="load",D="error",I="img",N="src",E="srcset",F="sizes",C="background-image";"event"==a.bind?u():n(t).on(T+"."+l,u)}function a(a,o){var l=this,u=n.extend({},l.config,o),c={},f=u.name+"-"+ ++i;return l.config=function(t,r){return r===e?u[t]:(u[t]=r,l)},l.addItems=function(t){return c.a&&c.a("string"===n.type(t)?n(t):t),l},l.getItems=function(){return c.g?c.g():{}},l.update=function(t){return c.e&&c.e({},!t),l},l.loadAll=function(){return c.e&&c.e({all:!0},!0),l},l.destroy=function(){return n(u.appendScroll).off("."+f,c.e),n(t).off("."+f),c={},e},r(l,u,a,c,f),u.chainable?a:l}var n=t.jQuery||t.Zepto,i=0;n.fn.Lazy=n.fn.lazy=function(t){return new a(this,t)},n.Lazy=n.lazy=function(t,r,i){if(n.isFunction(r)&&(i=r,r=[]),n.isFunction(i)){t=n.isArray(t)?t:[t],r=n.isArray(r)?r:[r];for(var o=a.prototype.config,l=o._f||(o._f={}),u=0,c=t.length;c>u;u++)(o[t[u]]===e||n.isFunction(o[t[u]]))&&(o[t[u]]=i);for(var f=0,s=r.length;s>f;f++)l[r[f]]=t[0]}},a.prototype.config={name:"lazy",chainable:!0,autoDestroy:!0,bind:"load",threshold:500,appendScroll:t,scrollDirection:"both",defaultImage:"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",delay:-1,attribute:"data-src",srcsetAttribute:"data-srcset",sizesAttribute:"data-sizes",retinaAttribute:"data-retina",loaderAttribute:"data-loader",imageBaseAttribute:"data-imagebase",removeAttribute:!0,handledName:"handled",loadedName:"loaded",effect:"show",effectTime:0,enableThrottle:!0,throttle:250}}(window); \ No newline at end of file +/*! jQuery Lazy 1.7.2 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2016 Daniel 'Eisbehr' Kern */ +!function(t,e){"use strict";function r(r,a,i,l,u){function c(){L=t.devicePixelRatio>1,f(i),a.delay>=0&&setTimeout(function(){s(!0)},a.delay),(a.delay<0||a.combined)&&(l.e=v(a.throttle,function(t){"resize"===t.type&&(w=B=-1),s(t.all)}),l.a=function(t){f(t),i.push.apply(i,t)},l.g=function(){return i=n(i).filter(function(){return!n(this).data(a.loadedName)})},s(),n(a.appendScroll).on("scroll."+u+" resize."+u,l.e))}function f(t){var i=a.defaultImage,o=a.placeholder,l=a.imageBase,u=a.srcsetAttribute,c=a.loaderAttribute,f=a._f||{};t=n(t).filter(function(){var t=n(this),r=h(this);return!t.data(a.handledName)&&(t.attr(a.attribute)||t.attr(u)||t.attr(c)||f[r]!=e)}).data("plugin_"+a.name,r);for(var s=0,d=t.length;d>s;s++){var A=n(t[s]),m=h(t[s]),g=A.attr(a.imageBaseAttribute)||l;m==N&&g&&A.attr(u)&&A.attr(u,b(A.attr(u),g)),f[m]==e||A.attr(c)||A.attr(c,f[m]),m==N&&i&&!A.attr(E)?A.attr(E,i):m==N||!o||A.css(O)&&"none"!=A.css(O)||A.css(O,"url('"+o+"')")}}function s(t){if(!i.length)return void(a.autoDestroy&&r.destroy());for(var e=!1,o=a.imageBase||"",l=a.srcsetAttribute,u=a.handledName,c=0,f=i.length;f>c;c++)(function(r){if(t||A(r)){var i=n(r),c=h(r),f=i.attr(a.attribute),s=i.attr(a.imageBaseAttribute)||o,m=i.attr(a.loaderAttribute);i.data(u)||a.visibleOnly&&!i.is(":visible")||!((f||i.attr(l))&&(c==N&&(s+f!=i.attr(E)||i.attr(l)!=i.attr(F))||c!=N&&s+f!=i.css(O))||m)||(e=!0,i.data(u,!0),d(i,c,s,m))}})(i[c]);e&&(i=n(i).filter(function(){return!n(this).data(u)}))}function d(t,e,r,i){++z;var o=function(){y("onError",t),p(),o=n.noop};y("beforeLoad",t);var l=a.attribute,u=a.srcsetAttribute,c=a.sizesAttribute,f=a.retinaAttribute,s=a.removeAttribute,d=a.loadedName,A=t.attr(f);if(i){var m=function(){s&&t.removeAttr(a.loaderAttribute),t.data(d,!0),y(T,t),setTimeout(p,1),m=n.noop};t.off(I).one(I,o).one(D,m),y(i,t,function(e){e?(t.off(D),m()):(t.off(I),o())})||t.trigger(I)}else{var g=n(new Image);g.one(I,o).one(D,function(){t.hide(),e==N?t.attr(C,g.attr(C)).attr(F,g.attr(F)).attr(E,g.attr(E)):t.css(O,"url('"+g.attr(E)+"')"),t[a.effect](a.effectTime),s&&(t.removeAttr(l+" "+u+" "+f+" "+a.imageBaseAttribute),c!==C&&t.removeAttr(c)),t.data(d,!0),y(T,t),g.remove(),p()});var h=(L&&A?A:t.attr(l))||"";g.attr(C,t.attr(c)).attr(F,t.attr(u)).attr(E,h?r+h:null),g.complete&&g.load()}}function A(t){var e=t.getBoundingClientRect(),r=a.scrollDirection,n=a.threshold,i=g()+n>e.top&&-ne.left&&-n=0?w:w=n(t).width()}function g(){return B>=0?B:B=n(t).height()}function h(t){return t.tagName.toLowerCase()}function b(t,e){if(e){var r=t.split(",");t="";for(var a=0,n=r.length;n>a;a++)t+=e+r[a].trim()+(a!==n-1?",":"")}return t}function v(t,e){var n,i=0;return function(o,l){function u(){i=+new Date,e.call(r,o)}var c=+new Date-i;n&&clearTimeout(n),c>t||!a.enableThrottle||l?u():n=setTimeout(u,t-c)}}function p(){--z,i.length||z||y("onFinishedAll")}function y(t,e,n){return(t=a[t])?(t.apply(r,[].slice.call(arguments,1)),!0):!1}var z=0,w=-1,B=-1,L=!1,T="afterLoad",D="load",I="error",N="img",E="src",F="srcset",C="sizes",O="background-image";"event"==a.bind||o?c():n(t).on(D+"."+u,c)}function a(a,o){var l=this,u=n.extend({},l.config,o),c={},f=u.name+"-"+ ++i;return l.config=function(t,r){return r===e?u[t]:(u[t]=r,l)},l.addItems=function(t){return c.a&&c.a("string"===n.type(t)?n(t):t),l},l.getItems=function(){return c.g?c.g():{}},l.update=function(t){return c.e&&c.e({},!t),l},l.loadAll=function(){return c.e&&c.e({all:!0},!0),l},l.destroy=function(){return n(u.appendScroll).off("."+f,c.e),n(t).off("."+f),c={},e},r(l,u,a,c,f),u.chainable?a:l}var n=t.jQuery||t.Zepto,i=0,o=!1;n.fn.Lazy=n.fn.lazy=function(t){return new a(this,t)},n.Lazy=n.lazy=function(t,r,i){if(n.isFunction(r)&&(i=r,r=[]),n.isFunction(i)){t=n.isArray(t)?t:[t],r=n.isArray(r)?r:[r];for(var o=a.prototype.config,l=o._f||(o._f={}),u=0,c=t.length;c>u;u++)(o[t[u]]===e||n.isFunction(o[t[u]]))&&(o[t[u]]=i);for(var f=0,s=r.length;s>f;f++)l[r[f]]=t[0]}},a.prototype.config={name:"lazy",chainable:!0,autoDestroy:!0,bind:"load",threshold:500,visibleOnly:!1,appendScroll:t,scrollDirection:"both",imageBase:null,defaultImage:"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",placeholder:null,delay:-1,combined:!1,attribute:"data-src",srcsetAttribute:"data-srcset",sizesAttribute:"data-sizes",retinaAttribute:"data-retina",loaderAttribute:"data-loader",imageBaseAttribute:"data-imagebase",removeAttribute:!0,handledName:"handled",loadedName:"loaded",effect:"show",effectTime:0,enableThrottle:!0,throttle:250,beforeLoad:e,afterLoad:e,onError:e,onFinishedAll:e},n(t).on("load",function(){o=!0})}(window); \ No newline at end of file diff --git a/jquery.lazy.plugins.js b/jquery.lazy.plugins.js index affc05e..e573d7f 100644 --- a/jquery.lazy.plugins.js +++ b/jquery.lazy.plugins.js @@ -189,7 +189,7 @@ })(window.jQuery || window.Zepto); /*! - * jQuery & Zepto Lazy - iFrame Plugin - v1.3 + * jQuery & Zepto Lazy - iFrame Plugin - v1.4 * http://jquery.eisbehr.de/lazy/ * * Copyright 2012 - 2016, Daniel 'Eisbehr' Kern @@ -227,6 +227,8 @@ $.ajax({ url: element.attr(srcAttr), dataType: "html", + crossDomain: true, + xhrFields: {withCredentials: true}, /** * success callback @@ -299,6 +301,164 @@ }); })(window.jQuery || window.Zepto); +/*! + * jQuery & Zepto Lazy - Picture Plugin - v1.0 + * http://jquery.eisbehr.de/lazy/ + * + * Copyright 2012 - 2016, Daniel 'Eisbehr' Kern + * + * Dual licensed under the MIT and GPL-2.0 licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl-2.0.html + */ +;(function($) { + // loads picture elements like: + // + // + // + // + // + // + // or: + // + // + // + // + // + // or just with attributes in one line: + // + $.lazy(["pic", "picture"], ["picture"], function(element, response) { + var elementTagName = element[0].tagName.toLowerCase(); + + if( elementTagName == "picture" ) { + var srcAttr = "data-src", + srcsetAttr = "data-srcset", + mediaAttr = "data-media", + sizesAttr = "data-sizes", + typeAttr = "data-type", + sources = element.find(srcAttr), + image = element.find("data-img"); + + // handle as child elements + if( sources.length ) { + sources.each(function() { + renameElementTag($(this), "source"); + }); + + // create img tag from child + if( image.length == 1 ) { + image = renameElementTag(image, "img"); + + // bind event callbacks to new image tag + image.on("load", function() { + response(true); + }).on("error", function() { + response(false); + }); + + image.attr("src", image.attr(srcAttr)); + + if( this.config("removeAttribute") ) + image.removeAttr(srcAttr); + } + + // create img tag from attribute + else if( element.attr(srcAttr) ) { + // create image tag + createImageObject(element, element.attr(srcAttr), response); + + if( this.config("removeAttribute") ) + element.removeAttr(srcAttr); + } + + // pass error state + else { + // use response function for Zepto + response(false); + } + } + + // handle as attributes + else if( element.attr(srcsetAttr) ) { + // create source elements before img tag + $("").attr({ + media: element.attr(mediaAttr), + sizes: element.attr(sizesAttr), + type: element.attr(typeAttr), + srcset: element.attr(srcsetAttr) + }) + .appendTo(element); + + // create image tag + createImageObject(element, element.attr(srcAttr), response); + + // remove attributes from parent picture element + if( this.config("removeAttribute") ) + element.removeAttr(srcAttr + " " + srcsetAttr + " " + mediaAttr + " " + sizesAttr + " " + typeAttr); + } + + // pass error state + else { + // use response function for Zepto + response(false); + } + } + + else { + // pass error state + // use response function for Zepto + response(false); + } + }); + + /** + * create a new child element and copy attributes + * @param {jQuery|object} element + * @param {string} toType + * @return {jQuery|object} + */ + function renameElementTag(element, toType) { + var attributes = element.prop("attributes"), + target = $("<" + toType + ">"); + + $.each(attributes, function(index, attribute) { + target.attr(attribute.name, attribute.value); + }); + + element.replaceWith(target); + return target; + } + + /** + * create a new image element inside parent element + * @param {jQuery|object} parent + * @param {string} src + * @param {function} response + * @return void + */ + function createImageObject(parent, src, response) { + // create image tag + var imageObj = $("") + + // create image tag an bind callbacks for correct response + .one("load", function() { + response(true); + }) + .one("error", function() { + response(false); + }) + + // set into picture element + .appendTo(parent) + + // set src attribute at last to prevent early kick-in + .attr("src", src); + + // call after load even on cached image + imageObj.complete && imageObj.load(); + } +})(window.jQuery || window.Zepto); + /*! * jQuery & Zepto Lazy - Script Plugin - v1.2 * http://jquery.eisbehr.de/lazy/ @@ -328,7 +488,38 @@ })(window.jQuery || window.Zepto); /*! - * jQuery & Zepto Lazy - YouTube Plugin - v1.2 + * jQuery & Zepto Lazy - Vimeo Plugin - v1.0 + * http://jquery.eisbehr.de/lazy/ + * + * Copyright 2012 - 2016, Daniel 'Eisbehr' Kern + * + * Dual licensed under the MIT and GPL-2.0 licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl-2.0.html + */ +;(function($) { + // load vimeo video iframe, like: + // + $.lazy("vimeo", function(element, response) { + if( element[0].tagName.toLowerCase() == "iframe" ) { + // pass source to iframe + element.attr("src", "https://player.vimeo.com/video/" + element.attr("data-src")); + + // remove attribute + if( this.config("removeAttribute") ) + element.removeAttr("data-src"); + } + + else { + // pass error state + // use response function for Zepto + response(false); + } + }); +})(window.jQuery || window.Zepto); + +/*! + * jQuery & Zepto Lazy - YouTube Plugin - v1.3 * http://jquery.eisbehr.de/lazy/ * * Copyright 2012 - 2016, Daniel 'Eisbehr' Kern @@ -353,7 +544,7 @@ else { // pass error state // use response function for Zepto - response(true); + response(false); } }); })(window.jQuery || window.Zepto); \ No newline at end of file diff --git a/jquery.lazy.plugins.min.js b/jquery.lazy.plugins.min.js index e29931f..a20aa3c 100644 --- a/jquery.lazy.plugins.min.js +++ b/jquery.lazy.plugins.min.js @@ -1,2 +1,2 @@ /*! jQuery & Zepto Lazy - All Plugins - http://jquery.eisbehr.de/lazy - MIT & GPL-2.0 license - Copyright 2012-2016 Daniel 'Eisbehr' Kern */ -!function(t){function e(e,a,r,o){t.ajax({url:a.attr("data-src"),type:o||"get",dataType:a.attr("data-type")||"html",success:function(t){a.html(t),r(!0),e.config("removeAttribute")&&a.removeAttr("data-src data-method data-type")},error:function(){r(!1)}})}t.lazy("ajax",function(t,a){e(this,t,a,t.attr("data-method"))}),t.lazy("get",function(t,a){e(this,t,a,"get")}),t.lazy("post",function(t,a){e(this,t,a,"post")})}(window.jQuery||window.Zepto),function(t){t.lazy(["av","audio","video"],["audio","video"],function(e,a){var r=e[0].tagName.toLowerCase();if("audio"==r||"video"==r){var o="data-src",n=e.find(o),i=e.find("data-track"),c=0,u=function(){++c==n.length&&a(!1)},s=function(){var e=t(this),a=e[0].tagName.toLowerCase(),r=e.prop("attributes"),n=t(a==o?"":"");a==o&&n.one("error",u),t.each(r,function(t,e){n.attr(e.name,e.value)}),e.replaceWith(n)};e.one("loadedmetadata",function(){a(!0)}).off("load error").attr("poster",e.attr("data-poster")),n.length?n.each(s):e.attr(o)?(t.each(e.attr(o).split(","),function(a,r){var o=r.split("|");e.append(t("").one("error",u).attr({src:o[0].trim(),type:o[1].trim()}))}),this.config("removeAttribute")&&e.removeAttr(o)):a(!1),i.length&&i.each(s)}else a(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy(["frame","iframe"],"iframe",function(e,a){var r=this;if("iframe"==e[0].tagName.toLowerCase()){var o="data-src",n="data-error-detect",i=e.attr(n);"true"!=i&&"1"!=i?(e.attr("src",e.attr(o)),r.config("removeAttribute")&&e.removeAttr(o+" "+n)):t.ajax({url:e.attr(o),dataType:"html",success:function(t){e.html(t).attr("src",e.attr(o)),r.config("removeAttribute")&&e.removeAttr(o+" "+n)},error:function(){a(!1)}})}else a(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy("noop",function(){}),t.lazy("noop-success",function(t,e){e(!0)}),t.lazy("noop-error",function(t,e){e(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy(["js","javascript","script"],"script",function(t,e){"script"==t[0].tagName.toLowerCase()?(t.attr("src",t.attr("data-src")),this.config("removeAttribute")&&t.removeAttr("data-src")):e(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy(["yt","youtube"],function(t,e){"iframe"==t[0].tagName.toLowerCase()?(t.attr("src","https://www.youtube.com/embed/"+t.attr("data-src")+"?rel=0&showinfo=0"),this.config("removeAttribute")&&t.removeAttr("data-src")):e(!0)})}(window.jQuery||window.Zepto); \ No newline at end of file +!function(t){function e(e,r,a,o){t.ajax({url:r.attr("data-src"),type:o||"get",dataType:r.attr("data-type")||"html",success:function(t){r.html(t),a(!0),e.config("removeAttribute")&&r.removeAttr("data-src data-method data-type")},error:function(){a(!1)}})}t.lazy("ajax",function(t,r){e(this,t,r,t.attr("data-method"))}),t.lazy("get",function(t,r){e(this,t,r,"get")}),t.lazy("post",function(t,r){e(this,t,r,"post")})}(window.jQuery||window.Zepto),function(t){t.lazy(["av","audio","video"],["audio","video"],function(e,r){var a=e[0].tagName.toLowerCase();if("audio"==a||"video"==a){var o="data-src",i=e.find(o),n=e.find("data-track"),c=0,s=function(){++c==i.length&&r(!1)},u=function(){var e=t(this),r=e[0].tagName.toLowerCase(),a=e.prop("attributes"),i=t(r==o?"":"");r==o&&i.one("error",s),t.each(a,function(t,e){i.attr(e.name,e.value)}),e.replaceWith(i)};e.one("loadedmetadata",function(){r(!0)}).off("load error").attr("poster",e.attr("data-poster")),i.length?i.each(u):e.attr(o)?(t.each(e.attr(o).split(","),function(r,a){var o=a.split("|");e.append(t("").one("error",s).attr({src:o[0].trim(),type:o[1].trim()}))}),this.config("removeAttribute")&&e.removeAttr(o)):r(!1),n.length&&n.each(u)}else r(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy(["frame","iframe"],"iframe",function(e,r){var a=this;if("iframe"==e[0].tagName.toLowerCase()){var o="data-src",i="data-error-detect",n=e.attr(i);"true"!=n&&"1"!=n?(e.attr("src",e.attr(o)),a.config("removeAttribute")&&e.removeAttr(o+" "+i)):t.ajax({url:e.attr(o),dataType:"html",crossDomain:!0,xhrFields:{withCredentials:!0},success:function(t){e.html(t).attr("src",e.attr(o)),a.config("removeAttribute")&&e.removeAttr(o+" "+i)},error:function(){r(!1)}})}else r(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy("noop",function(){}),t.lazy("noop-success",function(t,e){e(!0)}),t.lazy("noop-error",function(t,e){e(!1)})}(window.jQuery||window.Zepto),function(t){function e(e,r){var a=e.prop("attributes"),o=t("<"+r+">");return t.each(a,function(t,e){o.attr(e.name,e.value)}),e.replaceWith(o),o}function r(e,r,a){var o=t("").one("load",function(){a(!0)}).one("error",function(){a(!1)}).appendTo(e).attr("src",r);o.complete&&o.load()}t.lazy(["pic","picture"],["picture"],function(a,o){var i=a[0].tagName.toLowerCase();if("picture"==i){var n="data-src",c="data-srcset",s="data-media",u="data-sizes",d="data-type",f=a.find(n),m=a.find("data-img");f.length?(f.each(function(){e(t(this),"source")}),1==m.length?(m=e(m,"img"),m.on("load",function(){o(!0)}).on("error",function(){o(!1)}),m.attr("src",m.attr(n)),this.config("removeAttribute")&&m.removeAttr(n)):a.attr(n)?(r(a,a.attr(n),o),this.config("removeAttribute")&&a.removeAttr(n)):o(!1)):a.attr(c)?(t("").attr({media:a.attr(s),sizes:a.attr(u),type:a.attr(d),srcset:a.attr(c)}).appendTo(a),r(a,a.attr(n),o),this.config("removeAttribute")&&a.removeAttr(n+" "+c+" "+s+" "+u+" "+d)):o(!1)}else o(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy(["js","javascript","script"],"script",function(t,e){"script"==t[0].tagName.toLowerCase()?(t.attr("src",t.attr("data-src")),this.config("removeAttribute")&&t.removeAttr("data-src")):e(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy("vimeo",function(t,e){"iframe"==t[0].tagName.toLowerCase()?(t.attr("src","https://player.vimeo.com/video/"+t.attr("data-src")),this.config("removeAttribute")&&t.removeAttr("data-src")):e(!1)})}(window.jQuery||window.Zepto),function(t){t.lazy(["yt","youtube"],function(t,e){"iframe"==t[0].tagName.toLowerCase()?(t.attr("src","https://www.youtube.com/embed/"+t.attr("data-src")+"?rel=0&showinfo=0"),this.config("removeAttribute")&&t.removeAttr("data-src")):e(!1)})}(window.jQuery||window.Zepto); \ No newline at end of file diff --git a/package.json b/package.json index 34c5932..bd1c321 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jquery-lazy", "title": "jQuery & Zepto Lazy - Delayed Content, Image and Background Loader", - "version": "1.7.1", + "version": "1.7.2", "description": "Lazy is a fast, feature-rich and lightweight delayed content loading plugin for jQuery and Zepto. It's designed to speed up page loading times and decrease traffic to your users by only loading the content in view.", "main": "jquery.lazy.js", "homepage": "http://jquery.eisbehr.de/lazy/", diff --git a/plugins/README.md b/plugins/README.md index b22e210..6b0594a 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -14,7 +14,9 @@ * [Audio / Video Loader](#audio--video-loader) * [iFrame Loader](#iframe-loader) * [NOOP Loader](#noop-loader) +* [Picture Loader](#picture-loader) * [JS / Script Loader](#js--script-loader) +* [Vimeo Video Loader](#vimeo-video-loader) * [YouTube Video Loader](#youtube-video-loader) * [Bugs / Feature request](#bugs--feature-request) * [License](#license) @@ -37,7 +39,9 @@ Just add the plugins you want to use or a combined file, containing all plugins, + + @@ -124,7 +128,7 @@ But there are even some shorthand names for specific request types `GET` and `PO **Default for:** `