Files
kit/assets/jquery-lazy/jquery.lazy.plugins.min.js
T
2024-05-17 19:55:37 +03:00

11 lines
4.6 KiB
JavaScript

/*!
* jQuery & Zepto Lazy - AJAX Plugin - v1.4
* http://jquery.eisbehr.de/lazy/
*
* Copyright 2012 - 2018, 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(t){function e(e,a,r,o){var i;"POST"!==(o=o?o.toUpperCase():"GET")&&"PUT"!==o||!e.config("ajaxCreateData")||(i=e.config("ajaxCreateData").apply(e,[a])),t.ajax({url:a.attr("data-src"),type:"POST"===o||"PUT"===o?o:"GET",data:i,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")})),t.lazy("put",(function(t,a){e(this,t,a,"PUT")}))}(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",i=e.find(o),n=e.find("data-track"),c=0,s=function(){++c===i.length&&a(!1)},u=function(){var e=t(this),a=e[0].tagName.toLowerCase(),r=e.prop("attributes"),i=t(a===o?"<source>":"<track>");a===o&&i.one("error",s),t.each(r,(function(t,e){i.attr(e.name,e.value)})),e.replaceWith(i)};e.one("loadedmetadata",(function(){a(!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(a,r){var o=r.split("|");e.append(t("<source>").one("error",s).attr({src:o[0].trim(),type:o[1].trim()}))})),this.config("removeAttribute")&&e.removeAttr(o)):a(!1),n.length&&n.each(u)}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",i="data-error-detect",n=e.attr(i);"true"!==n&&"1"!==n?(e.attr("src",e.attr(o)),r.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)),r.config("removeAttribute")&&e.removeAttr(o+" "+i)},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){var e="data-src",a="data-srcset",r="data-media",o="data-sizes",i="data-type";function n(a,r,o){var i=a.prop("attributes"),n=t("<"+r+">");return t.each(i,(function(t,a){"srcset"!==a.name&&a.name!==e||(a.value=s(a.value,o)),n.attr(a.name,a.value)})),a.replaceWith(n),n}function c(e,a,r){var o=t("<img>").one("load",(function(){r(!0)})).one("error",(function(){r(!1)})).appendTo(e).attr("src",a);o.complete&&o.load()}function s(t,e){if(e){var a=t.split(",");t="";for(var r=0,o=a.length;r<o;r++)t+=e+a[r].trim()+(r!==o-1?",":"")}return t}t.lazy(["pic","picture"],["picture"],(function(u,d){if("picture"===u[0].tagName.toLowerCase()){var f=u.find(e),m=u.find("data-img"),p=this.config("imageBase")||"";f.length?(f.each((function(){n(t(this),"source",p)})),1===m.length?((m=n(m,"img",p)).on("load",(function(){d(!0)})).on("error",(function(){d(!1)})),m.attr("src",m.attr(e)),this.config("removeAttribute")&&m.removeAttr(e)):u.attr(e)?(c(u,p+u.attr(e),d),this.config("removeAttribute")&&u.removeAttr(e)):d(!1)):u.attr(a)?(t("<source>").attr({media:u.attr(r),sizes:u.attr(o),type:u.attr(i),srcset:s(u.attr(a),p)}).appendTo(u),c(u,p+u.attr(e),d),this.config("removeAttribute")&&u.removeAttr(e+" "+a+" "+r+" "+o+" "+i)):d(!1)}else d(!1)}))}(window.jQuery||window.Zepto),(window.jQuery||window.Zepto).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).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).lazy(["yt","youtube"],(function(t,e){if("iframe"===t[0].tagName.toLowerCase()){var a=/1|true/.test(t.attr("data-nocookie"));t.attr("src","https://www.youtube"+(a?"-nocookie":"")+".com/embed/"+t.attr("data-src")+"?rel=0&amp;showinfo=0"),this.config("removeAttribute")&&t.removeAttr("data-src")}else e(!1)})),(window.jQuery||window.Zepto).lazy(["do"],(function(t,e){var a=t.attr("data-callback");"function"==typeof window[a]?(window[a](t,e),this.config("removeAttribute")&&t.removeAttr("data-callback")):e(!1)}));