lazyload.min.js 8.6 KB

1
  1. !function(){var t={},e={},n={},r={};t=function(t){function e(){}function n(t,n){var r;return Object.create?r=Object.create(t):(e.prototype=t,r=new e),r.constructor=n,r}function r(t,e){if(t){if(t.nodeType)return[t];var e=e&&e.nodeType?e:document;return t&&"string"==typeof t?e.querySelectorAll(t):void 0}}for(var i=/\\?\{([^{}]+)\}/g,o="",s=/^[\s\xa0]+|[\s\xa0]+$/g,l=String.prototype.trim,u=l?function(t){return null==t?o:l.call(t)}:function(t){return null==t?o:(t+"").replace(s,o)},c=0,f=function(t){var e=t.offsetTop;return null!=t.offsetParent&&(e+=f(t.offsetParent)),e},a=function(t){var e=t.offsetLeft;return null!=t.offsetParent&&(e+=a(t.offsetParent)),e},p=({isObject:function(t){return t===Object(t)},isArray:Array.isArray||function(t){return"[object Array]"==toString.call(t)},isEmpty:function(t){if(null==t)return!0;if(this.isArray(t)||this.isString(t))return 0===t.length;for(var e in t)if(this.has(t,e))return!1;return!0},mix:function(t,e,n){for(var r in e)t[r]=e[r];return t},extend:function(t,e,r,i){if(!e||!t)return t;var o,s=e.prototype;return o=n(s,t),t.prototype=this.mix(o,t.prototype),t.superclass=n(s,e),r&&this.mix(o,r),i&&this.mix(t,i),t},startsWith:function(t,e){return 0===t.lastIndexOf(e,0)},endsWith:function(t,e){var n=t.length-e.length;return n>=0&&t.indexOf(e,n)===n},trim:u,substitute:function(t,e,n){return"string"==typeof t&&e?t.replace(n||i,function(t,n){return"\\"===t.charAt(0)?t.slice(1):void 0===e[n]?o:e[n]}):t},vendor:function(){for(var t,e=document.createElement("div").style,n=["t","webkitT","MozT","msT","OT"],r=0,i=n.length;r<i;r++)if(t=n[r]+"ransform",t in e)return n[r].substr(0,n[r].length-1);return!1}(),prefixStyle:function(t){return this.vendor!==!1&&(""===this.vendor?t:this.vendor+t.charAt(0).toUpperCase()+t.substr(1))},hasClass:function(t,e){return t&&t.className&&e&&t.className.indexOf(e)!=-1},addClass:function(t,e){t&&e&&!this.hasClass(t,e)&&(t.className+=" "+e)},removeClass:function(t,e){t&&t.className&&e&&(t.className=t.className.replace(e,""))},remove:function(t){t&&t.parentNode&&t.parentNode.removeChild(t)},getOffsetTop:f,getOffsetLeft:a,findParentEl:function(t,e,n){var r=null,i=null,o=/^#/.test(e)?"id":/^\./.test(e)?"class":"tag",s=e.replace(/\.|#/g,"");if(n&&"string"==typeof n&&(n=document.querySelector(n)),n=n||document.body,t&&e){if("class"==o&&t.className&&t.className.match(s))return t;if("id"==o&&t.id&&u(t.id)==s)return t;if("tag"==o&&t.tagName.toLowerCase()==s)return t;for(;!r&&i!=n&&(i=t.parentNode);){if("class"==o&&i.className&&i.className.match(s)||"id"==o&&i.id&&u(i.id)==s||"tag"==o&&i.tagName&&i.tagName.toLowerCase()==s)return r=i;t=i}return null}},guid:function(t){var e=++c+"";return t?t+e:e},isAndroid:function(){return/Android /.test(window.navigator.appVersion)},isBadAndroid:function(){return/Android /.test(window.navigator.appVersion)&&!/Chrome\/\d/.test(window.navigator.appVersion)},px2Num:function(t){return Number(t.replace(/px/,""))},getNodes:r,getNode:function(t,e){var n=r(t,e);return n&&n[0]},stringifyStyle:function(t){var e="";for(var n in t)e+=[n,":",t[n],";"].join("");return e}}),g=["Arguments","Function","String","Number","Date","RegExp"],h=0;h<g.length;h++)p["is"+g[h]]=function(t){return toString.call(t)=="[object "+g[h]+"]"};return"object"==typeof module&&module.exports?t=p:p}(t),e=function(e){var n=t,r=function(t){var e,n=!1;return function(){return n?e:(n=!0,e=t.apply(this,arguments),t=null,e)}},i={on:function(t,e,n){if(!s(this,"on",t,[e,n])||!e)return this;this._events||(this._events={});var r=this._events[t]||(this._events[t]=[]);return r.push({callback:e,context:n,ctx:n||this}),this},once:function(t,e,n){if(!s(this,"once",t,[e,n])||!e)return this;var i=this,o=r(function(){i.off(t,o),e.apply(this,arguments)});return o._callback=e,this.on(t,o,n)},off:function(t,e,n){if(!this._events||!s(this,"off",t,[e,n]))return this;if(!t&&!e&&!n)return this._events=void 0,this;for(var r=t?[t]:Object.keys(this._events),i=0,o=r.length;i<o;i++){t=r[i];var l=this._events[t];if(l)if(e||n){for(var u=[],c=0,f=l.length;c<f;c++){var a=l[c];(e&&e!==a.callback&&e!==a.callback._callback||n&&n!==a.context)&&u.push(a)}u.length?this._events[t]=u:delete this._events[t]}else delete this._events[t]}return this},trigger:function(t){if(!this._events)return this;var e=Array.prototype.slice.call(arguments,1);if(!s(this,"trigger",t,e))return this;var n=this._events[t],r=this._events.all;return n&&l(n,e),r&&l(r,arguments),this},listenTo:function(t,e,r){var i=this._listeningTo||(this._listeningTo={}),o=t._listenId||(t._listenId=n.guid("l"));return i[o]=t,r||"object"!=typeof e||(r=this),t.on(e,r,this),this},listenToOnce:function(t,e,n){if("object"==typeof e){for(var i in e)this.listenToOnce(t,i,e[i]);return this}var o=r(function(){this.stopListening(t,e,o),n.apply(this,arguments)});return o._callback=n,this.listenTo(t,e,o)},stopListening:function(t,e,r){var i=this._listeningTo;if(!i)return this;var o=!e&&!r;r||"object"!=typeof e||(r=this),t&&((i={})[t._listenId]=t);for(var s in i)t=i[s],t.off(e,r,this),(o||n.isEmpty(t._events))&&delete this._listeningTo[s];return this}},o=/\s+/,s=function(t,e,n,r){if(!n)return!0;if("object"==typeof n){for(var i in n)t[e].apply(t,[i,n[i]].concat(r));return!1}if(o.test(n)){for(var s=n.split(o),l=0,u=s.length;l<u;l++)t[e].apply(t,[s[l]].concat(r));return!1}return!0},l=function(t,e){var n,r=-1,i=t.length,o=e[0],s=e[1],l=e[2];switch(e.length){case 0:for(;++r<i;)(n=t[r]).callback.call(n.ctx);return;case 1:for(;++r<i;)(n=t[r]).callback.call(n.ctx,o);return;case 2:for(;++r<i;)(n=t[r]).callback.call(n.ctx,o,s);return;case 3:for(;++r<i;)(n=t[r]).callback.call(n.ctx,o,s,l);return;default:for(;++r<i;)(n=t[r]).callback.apply(n.ctx,e);return}};return i.bind=i.on,i.unbind=i.off,"object"==typeof module&&module.exports?e=i:i}(e),n=function(n){var r=t,i=e,o=function(){};return r.mix(o.prototype,i),r.mix(o.prototype,{plug:function(t){var e=this;if(t&&t.pluginId){e.__plugins||(e.__plugins=[]);var n=e.getPlugin(t.pluginId);return n&&e.unplug(t.pluginId),t.pluginInitializer(e),e.__plugins.push(t),e}},unplug:function(t){var e=this;if(t&&e.__plugins){var n="string"==typeof t?e.getPlugin(t):t;n.pluginDestructor(e);for(var r=0,i=e.__plugins.length;r<i;r++)if(e.__plugins[r]==n)return e.__plugins.splice(r,1)}},getPlugin:function(t){var e=this,n=[];if(e.__plugins){for(var r=0,i=e.__plugins.length;r<i;r++)e.__plugins[r]&&e.__plugins[r].pluginId==t&&n.push(e.__plugins[r]);return n.length>1?n:n[0]||null}}}),"object"==typeof module&&module.exports?n=o:o}(n),r=function(e){var r=t,i=n,o=function(t){o.superclass.constructor.call(this,t),this.userConfig=r.mix({imgsSelector:"img",delay:200,imgSetter:function(t){var e=t.getAttribute("data-src");e&&t.setAttribute("src",e)}},t)};if(r.extend(o,i,{pluginId:"lazyload",pluginInitializer:function(t){var e=this;return e.xscroll=t,e.reset(),e._bindEvt(),e},pluginDestructor:function(){var t=this;t.xscroll&&t.xscroll.off("scroll scrollend afterrender",t._filterItem,t),t._isEvtBinded=!1},_filterItem:function(){var t=this;t.xscroll.getPlugin("infinite")?t._filterItemByInfinite.call(t):t._filterItemByNormal.call(t)},_filterItemByNormal:function(){for(var t,e=this,n=e.xscroll.getScrollPos(),r="x"==e.zoomType?n.scrollLeft:n.scrollTop,i="x"==e.zoomType?"offsetWidth":"offsetHeight",o="x"==e.zoomType?"left":"top",s="x"==e.zoomType?"right":"bottom",l=0,u=e.positions.length;l<u;l++)t=e.positions[l],(t[o]>=r&&t[o]<=r+e.xscroll.renderTo[i]||t[s]>=r&&t[s]<=r+e.xscroll.renderTo[i])&&e.userConfig.imgSetter.call(e,e.imgs[l])},_filterItemByInfinite:function(){var t=this,e=t.xscroll.getPlugin("infinite");clearTimeout(t._timeout),t._timeout=setTimeout(function(){if(!t.xscroll["isScrolling"+t.zoomType.toUpperCase()]){for(var n=0;n<e.infiniteLength;n++)if(e.infiniteElementsCache[n]._visible&&e.infiniteElements[n])for(var r=e.infiniteElements[n].querySelectorAll(t.userConfig.imgsSelector),i=0,o=r.length;i<o;i++)t.userConfig.imgSetter.call(t,r[i]);t._filterItemByNormal()}},t.userConfig.delay)},reset:function(){var t,e,n=this;n.zoomType=n.xscroll.userConfig.zoomType,n.imgs=n.xscroll.renderTo.querySelectorAll(n.userConfig.imgsSelector);var i=(n.xscroll.getScrollPos(),"x"==n.zoomType?"left":"top"),o="x"==n.zoomType?"right":"bottom",s="x"==n.zoomType?r.getOffsetLeft:r.getOffsetTop,l="x"==n.zoomType?"offsetWidth":"offsetHeight",u="x"==n.zoomType?"width":"height";n.positions=[];for(var c=0,f=n.imgs.length;c<f;c++)t=n.imgs[c],e={},e[i]=s(t),e[u]=t[l],e[o]=e[i]+e[u],n.positions.push(e);return n},_bindEvt:function(){var t=this;if(!t._isEvtBinded){t._isEvtBinded=!0;var e=t.xscroll.userConfig.useOriginScroll?"scroll":"scrollend";t.xscroll.on("afterrender",t._filterItem,t),t.xscroll.on(e,t._filterItem,t)}}}),"object"==typeof module&&module.exports)e=o;else if(window.XScroll&&window.XScroll.Plugins)return XScroll.Plugins.LazyLoad=o;return e}(r)}();