You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
9.1 KiB
1 lines
9.1 KiB
!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(this),s=a(b),t=(r.offsetParent(),r.selector||"",r.data(q)),u=b.requestAnimationFrame||b.mozRequestAnimationFrame||b.webkitRequestAnimationFrame||b.msRequestAnimationFrame||function(a){setTimeout(a,0)},v=this;g={initialize:function(){g.verbose("Initializing visibility",n),g.reset(),g.save.position(),g.bindEvents(),g.instantiate(),"image"==n.type&&g.setup.image(),u(g.checkVisibility)},instantiate:function(){g.verbose("Storing instance of module",g),t=g,r.data(q,g)},destroy:function(){g.verbose("Destroying previous module"),s.off(p),r.off(p).removeData(q)},bindEvents:function(){g.verbose("Binding visibility events to scroll and resize"),s.on("resize",g.event.refresh).on("scroll",g.event.scroll)},event:{refresh:function(){u(g.refresh)},scroll:function(){g.verbose("Scroll position changed"),n.throttle?(clearTimeout(g.timer),g.timer=setTimeout(g.checkVisibility,200)):u(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=r.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+n.offset<g.cache.element.top;r.attr("src",b),c?r.show():a.fn.transition!==d?r.transition(n.transition,n.duration):r.fadeIn(n.duration)}},refresh:function(){g.debug("Refreshing constants (element width/height)"),g.reset(),g.save.position(),g.checkVisibility(),a.proxy(n.onRefresh,v)()},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.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),c&&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),c&&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),c&&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),c&&b.topPassed?g.execute(c,e):n.once||g.remove.occurred(e),a===d?b.topPassed: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),c&&b.bottomPassed?g.execute(c,e):n.once||g.remove.occurred(e),a===d?b.bottomPassed:void 0},execute:function(b,c){var d=g.get.elementCalculations(),e=g.get.screenCalculations();n.continuous?(g.debug("Callback called continuously on valid",c,d),a.proxy(b,v)(d,e)):g.get.occurred(c)||(g.debug("Callback conditions met",c,d),a.proxy(b,v)(d,e)),g.save.occurred(c)},remove:{occurred:function(a){a?g.cache.occurred[a]=!1:g.cache.occurred={}}},save:{occurred:function(a){a&&(g.cache.occurred[a]=!0)},scroll:function(){g.cache.scroll=s.scrollTop()+n.offset},direction:function(){var a,b=g.get.scroll(),c=g.get.lastScroll();return a=b>c&&c?"down":c>b&&c?"up":"static",g.cache.direction=a,g.cache.direction},elementPosition:function(){var b=g.get.screenSize();return g.verbose("Saving element position"),a.extend(g.cache.element,{margin:{top:parseInt(r.css("margin-top"),10),bottom:parseInt(r.css("margin-bottom"),10)},fits:v.height<b.height,offset:r.offset(),width:r.outerWidth(),height:r.outerHeight()}),g.cache.element},elementCalculations:function(){var b=g.get.screenCalculations(),c=g.get.elementPosition();n.includeMargin?a.extend(g.cache.element,{top:c.offset.top-c.margin.top,bottom:c.offset.top+c.height+c.margin.bottom}):a.extend(g.cache.element,{top:c.offset.top,bottom:c.offset.top+c.height}),a.extend(g.cache.element,{topVisible:b.bottom>c.top,topPassed:b.top>c.top,bottomVisible:b.bottom>c.bottom,bottomPassed:b.top>c.bottom,pixelsPassed:0,percentagePassed:0}),a.extend(g.cache.element,{visible:g.cache.element.topVisible||g.cache.element.bottomVisible,passing:g.cache.element.topPassed&&!g.cache.element.bottomPassed,hidden:!g.cache.element.topVisible&&!g.cache.element.bottomVisible}),g.cache.element.passing&&(g.cache.element.pixelsPassed=b.top-c.top,g.cache.element.percentagePassed=(b.top-c.top)/c.height),g.verbose("Updated element calculations",g.cache.element)},screenCalculations:function(){var b=s.scrollTop();return g.cache.scroll===d&&(g.cache.scroll=s.scrollTop()),g.save.direction(),a.extend(g.cache.screen,{top:b-n.offset,bottom:b-n.offset+g.cache.screen.height}),g.cache.screen},screenSize:function(){g.verbose("Saving window position"),g.cache.screen={height:s.height()}},position:function(){g.save.screenSize(),g.save.elementPosition()}},get:{pixelsPassed:function(a){var b=g.get.elementCalculations();return a.search("%")>-1?b.height*(parseInt(a,10)/100):parseInt(a,10)},occurred:function(a){return g.cache.occurred!==d?g.cache.occurred[a]||!1:!1},direction:function(){return g.cache.direction===d&&g.save.direction(),g.cache.direction},elementPosition:function(){return g.cache.element===d&&g.save.elementPosition(),g.cache.element},elementCalculations:function(){return g.cache.element===d&&g.save.elementCalculations(),g.cache.element},screenCalculations:function(){return g.cache.screen===d&&g.save.screenCalculations(),g.cache.screen},screenSize:function(){return g.cache.screen===d&&g.save.screenSize(),g.cache.screen},scroll:function(){return g.cache.scroll===d&&g.save.scroll(),g.cache.scroll},lastScroll:function(){return g.cache.screen===d?(g.debug("First scroll event, no last scroll could be found"),!1):g.cache.screen.top}},setting:function(b,c){if(a.isPlainObject(b))a.extend(!0,n,b);else{if(c===d)return n[b];n[b]=c}},internal:function(b,c){if(a.isPlainObject(b))a.extend(!0,g,b);else{if(c===d)return g[b];g[b]=c}},debug:function(){n.debug&&(n.performance?g.performance.log(arguments):(g.debug=Function.prototype.bind.call(console.info,console,n.name+":"),g.debug.apply(console,arguments)))},verbose:function(){n.verbose&&n.debug&&(n.performance?g.performance.log(arguments):(g.verbose=Function.prototype.bind.call(console.info,console,n.name+":"),g.verbose.apply(console,arguments)))},error:function(){g.error=Function.prototype.bind.call(console.error,console,n.name+":"),g.error.apply(console,arguments)},performance:{log:function(a){var b,c,d;n.performance&&(b=(new Date).getTime(),d=i||b,c=b-d,i=b,j.push({Element:v,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":c})),clearTimeout(g.performance.timer),g.performance.timer=setTimeout(g.performance.display,100)},display:function(){var b=n.name+":",c=0;i=!1,clearTimeout(g.performance.timer),a.each(j,function(a,b){c+=b["Execution Time"]}),b+=" "+c+"ms",h&&(b+=" '"+h+"'"),(console.group!==d||console.table!==d)&&j.length>0&&(console.groupCollapsed(b),console.table?console.table(j):a.each(j,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),j=[]}},invoke:function(b,c,e){var g,h,i,j=t;return c=c||m,e=v||e,"string"==typeof b&&j!==d&&(b=b.split(/[\. ]/),g=b.length-1,a.each(b,function(c,e){var f=c!=g?e+b[c+1].charAt(0).toUpperCase()+b[c+1].slice(1):b;if(a.isPlainObject(j[f])&&c!=g)j=j[f];else{if(j[f]!==d)return h=j[f],!1;if(!a.isPlainObject(j[e])||c==g)return j[e]!==d?(h=j[e],!1):!1;j=j[e]}})),a.isFunction(h)?i=h.apply(e,c):h!==d&&(i=h),a.isArray(f)?f.push(i):f!==d?f=[f,i]:i!==d&&(f=i),h}},l?(t===d&&g.initialize(),g.invoke(k)):(t!==d&&g.destroy(),g.initialize())}),f!==d?f:this},a.fn.visibility.settings={name:"Visibility",namespace:"visibility",debug:!1,verbose:!1,performance:!0,offset:0,includeMargin:!1,throttle:!1,type:!1,transition:"fade in",duration:500,onPassed:{},onPassing:!1,onTopVisible:!1,onBottomVisible:!1,onTopPassed:!1,onBottomPassed:!1,once:!0,continuous:!1,onRefresh:function(){},onScroll:function(){},watch:!0,watchedProperties:["offsetWidth","offsetHeight","top","left"],error:{method:"The method you called is not defined."}}}(jQuery,window,document);
|