|
|
!function(a,b,c,d){a.fn.visibility=function(e){var f,g=a(this),h=g.selector||"",i=(new Date).getTime(),j=[],k=arguments[0],l="string"==typeof k,m=[].slice.call(arguments,1);return g.each(function(){var g,n=a.extend(!0,{},a.fn.visibility.settings,e),o=(n.className,n.namespace),p=(n.error,"."+o),q="module-"+o,r=a(b),s=a(this),t=a(n.context),u=(s.offsetParent(),s.selector||"",s.data(q)),v=b.requestAnimationFrame||b.mozRequestAnimationFrame||b.webkitRequestAnimationFrame||b.msRequestAnimationFrame||function(a){setTimeout(a,0)},w=this;g={initialize:function(){g.verbose("Initializing visibility",n),g.reset(),g.save.position(),g.bindEvents(),g.instantiate(),"image"==n.type&&g.setup.image(),v(g.checkVisibility)},instantiate:function(){g.verbose("Storing instance of module",g),u=g,s.data(q,g)},destroy:function(){g.verbose("Destroying previous module"),s.off(p).removeData(q)},bindEvents:function(){g.verbose("Binding visibility events to scroll and resize"),r.on("resize"+p,g.event.refresh),t.on("scroll"+p,g.event.scroll)},event:{refresh:function(){v(g.refresh)},scroll:function(){g.verbose("Scroll position changed"),n.throttle?(clearTimeout(g.timer),g.timer=setTimeout(g.checkVisibility,n.throttle)):v(g.checkVisibility)}},precache:function(b,d){b instanceof Array||(b=[b]);for(var e=b.length,f=0,g=[],h=c.createElement("img"),i=function(){f++,f>=b.length&&a.isFunction(d)&&d()};e--;)h=c.createElement("img"),h.onload=i,h.onerror=i,h.src=b[e],g.push(h)},setup:{image:function(){var a=s.data("src");a&&(g.verbose("Lazy loading image",a),g.topVisible(function(){g.precache(a,function(){g.set.image(a),n.onTopVisible=!1})}))}},set:{image:function(b){var c=g.cache.screen.bottom<g.cache.element.top;s.attr("src",b),c?s.show():a.fn.transition!==d?s.transition(n.transition,n.duration):s.fadeIn(n.duration)}},refresh:function(){g.debug("Refreshing constants (element width/height)"),g.reset(),g.save.position(),g.checkVisibility(),a.proxy(n.onRefresh,w)()},reset:function(){g.verbose("Reseting all cached values"),g.cache={occurred:{},screen:{},element:{}}},checkVisibility:function(){g.verbose("Checking visibility of element",g.cache.element),g.save.scroll(),g.save.direction(),g.save.screenCalculations(),g.save.elementCalculations(),g.passed(),g.passingReverse(),g.topVisibleReverse(),g.bottomVisibleReverse(),g.topPassedReverse(),g.bottomPassedReverse(),g.passing(),g.topVisible(),g.bottomVisible(),g.topPassed(),g.bottomPassed()},passed:function(b,c){var e=g.get.elementCalculations();if(b!==d&&c!==d)n.onPassed[b]=c;else{if(b!==d)return g.get.pixelsPassed(b)>e.pixelsPassed;e.passing&&a.each(n.onPassed,function(a,b){e.bottomVisible||e.pixelsPassed>g.get.pixelsPassed(a)?g.execute(b,a):n.once||g.remove.occurred(b)})}},passing:function(a){var b=g.get.elementCalculations(),c=a||n.onPassing,e="passing";return a&&(g.debug("Adding callback for passing",a),n.onPassing=a),b.passing?g.execute(c,e):n.once||g.remove.occurred(e),a!==d?b.passing:void 0},topVisible:function(a){var b=g.get.elementCalculations(),c=a||n.onTopVisible,e="topVisible";return a&&(g.debug("Adding callback for top visible",a),n.onTopVisible=a),b.topVisible?g.execute(c,e):n.once||g.remove.occurred(e),a===d?b.topVisible:void 0},bottomVisible:function(a){var b=g.get.elementCalculations(),c=a||n.onBottomVisible,e="bottomVisible";return a&&(g.debug("Adding callback for bottom visible",a),n.onBottomVisible=a),b.bottomVisible?g.execute(c,e):n.once||g.remove.occurred(e),a===d?b.bottomVisible:void 0},topPassed:function(a){var b=g.get.elementCalculations(),c=a||n.onTopPassed,e="topPassed";return a&&(g.debug("Adding callback for top passed",a),n.onTopPassed=a),b.topPassed?g.execute(c,e):n.once||g.remove.occurred(e),a===d?b.onTopPassed:void 0},bottomPassed:function(a){var b=g.get.elementCalculations(),c=a||n.onBottomPassed,e="bottomPassed";return a&&(g.debug("Adding callback for bottom passed",a),n.onBottomPassed=a),b.bottomPassed?g.execute(c,e):n.once||g.remove.occurred(e),a===d?b.bottomPassed:void 0},passingReverse:function(a){var b=g.get.elementCalculations(),c=a||n.onPassingReverse,e="passingReverse";return
|