forked from dkern/jquery.lazy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.lazy.plugins.min.js
2 lines (2 loc) · 3.79 KB
/
jquery.lazy.plugins.min.js
1
2
/*! jQuery & Zepto Lazy - All Plugins v1.7.5 - http://jquery.eisbehr.de/lazy - MIT&GPL-2.0 license - Copyright 2012-2017 Daniel 'Eisbehr' Kern */
!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?"<source>":"<track>");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("<source>").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("<img>").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("<source>").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);