diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 6d1e8d2..17bbff4 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,3 +1,9 @@ +### Version 2.2.10 - March 28, 2017 + +- **Visibility** - Visibility events now fire correctly when using `context` other than body that has `overflow-x` or `overflow-y` set to `auto` or `scroll` +- **Visibility** - Fixed bug where using visibility with `context` setting on a scrollable context (with overflow) would cause callbacks to fire incorrectly +- **Visibility** - Fixed bug where `top passed` and `bottom passed` would appear as incorrect values if using settings from `get element calculations` when element is off screen. + #### Dropdown - **Visibility** - Added documentation for `onOnscreen` and `onOffScreen`, two very important callbacks that occur when an element is or isn't in currently scrolled view. diff --git a/composer.json b/composer.json index 12b357e..6baca75 100644 --- a/composer.json +++ b/composer.json @@ -15,5 +15,5 @@ "framework" ], "license": "MIT", - "version": "2.2.9" + "version": "2.2.10" } \ No newline at end of file diff --git a/index.js b/index.js index 1decf66..4fb3a9c 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ /*! - * # Semantic UI 2.2.9 - Visibility + * # Semantic UI 2.2.10 - Visibility * http://github.com/semantic-org/semantic-ui/ * * @@ -423,6 +423,22 @@ module.exports = function(parameters) { return !(module.cache.element.width === 0 && module.cache.element.offset.top === 0); } return false; + }, + verticallyScrollableContext: function() { + var + overflowY = ($context.get(0) !== window) + ? $context.css('overflow-y') + : false + ; + return (overflowY == 'auto' || overflowY == 'scroll'); + }, + horizontallyScrollableContext: function() { + var + overflowX = ($context.get(0) !== window) + ? $context.css('overflow-x') + : false + ; + return (overflowX == 'auto' || overflowX == 'scroll'); } }, @@ -880,6 +896,13 @@ module.exports = function(parameters) { element.offset = $module.offset(); element.width = $module.outerWidth(); element.height = $module.outerHeight(); + // compensate for scroll in context + if(module.is.verticallyScrollableContext()) { + element.offset.top += $context.scrollTop() - $context.offset().top; + } + if(module.is.horizontallyScrollableContext()) { + element.offset.left += $context.scrollLeft - $context.offset().left; + } // store module.cache.element = element; return element; @@ -903,10 +926,10 @@ module.exports = function(parameters) { } // visibility - element.topVisible = (screen.bottom >= element.top); element.topPassed = (screen.top >= element.top); - element.bottomVisible = (screen.bottom >= element.bottom); element.bottomPassed = (screen.top >= element.bottom); + element.topVisible = (screen.bottom >= element.top) && !element.bottomPassed; + element.bottomVisible = (screen.bottom >= element.bottom) && !element.topPassed; element.pixelsPassed = 0; element.percentagePassed = 0; diff --git a/package.js b/package.js index 6e2deb3..07056b3 100644 --- a/package.js +++ b/package.js @@ -2,7 +2,7 @@ Package.describe({ name : 'semantic:ui-visibility', summary : 'Semantic UI - Visibility: Single component release', - version : '2.2.9', + version : '2.2.10', git : 'git://github.com/Semantic-Org/UI-Visibility.git', }); diff --git a/package.json b/package.json index 068152e..d431fec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "semantic-ui-visibility", - "version": "2.2.9", + "version": "2.2.10", "title": "Semantic UI - Visibility", "description": "Single component release of visibility", "homepage": "http://www.semantic-ui.com", diff --git a/visibility.js b/visibility.js index 292ea64..1ef85a4 100644 --- a/visibility.js +++ b/visibility.js @@ -1,5 +1,5 @@ /*! - * # Semantic UI 2.2.9 - Visibility + * # Semantic UI 2.2.10 - Visibility * http://github.com/semantic-org/semantic-ui/ * * @@ -422,6 +422,22 @@ $.fn.visibility = function(parameters) { return !(module.cache.element.width === 0 && module.cache.element.offset.top === 0); } return false; + }, + verticallyScrollableContext: function() { + var + overflowY = ($context.get(0) !== window) + ? $context.css('overflow-y') + : false + ; + return (overflowY == 'auto' || overflowY == 'scroll'); + }, + horizontallyScrollableContext: function() { + var + overflowX = ($context.get(0) !== window) + ? $context.css('overflow-x') + : false + ; + return (overflowX == 'auto' || overflowX == 'scroll'); } }, @@ -879,6 +895,13 @@ $.fn.visibility = function(parameters) { element.offset = $module.offset(); element.width = $module.outerWidth(); element.height = $module.outerHeight(); + // compensate for scroll in context + if(module.is.verticallyScrollableContext()) { + element.offset.top += $context.scrollTop() - $context.offset().top; + } + if(module.is.horizontallyScrollableContext()) { + element.offset.left += $context.scrollLeft - $context.offset().left; + } // store module.cache.element = element; return element; @@ -902,10 +925,10 @@ $.fn.visibility = function(parameters) { } // visibility - element.topVisible = (screen.bottom >= element.top); element.topPassed = (screen.top >= element.top); - element.bottomVisible = (screen.bottom >= element.bottom); element.bottomPassed = (screen.top >= element.bottom); + element.topVisible = (screen.bottom >= element.top) && !element.bottomPassed; + element.bottomVisible = (screen.bottom >= element.bottom) && !element.topPassed; element.pixelsPassed = 0; element.percentagePassed = 0; diff --git a/visibility.min.js b/visibility.min.js index 7fab044..1926199 100644 --- a/visibility.min.js +++ b/visibility.min.js @@ -1,5 +1,5 @@ /*! - * # Semantic UI 2.2.9 - Visibility + * # Semantic UI 2.2.10 - Visibility * http://github.com/semantic-org/semantic-ui/ * * @@ -7,4 +7,4 @@ * http://opensource.org/licenses/MIT * */ -!function(e,n,o,t){"use strict";n="undefined"!=typeof n&&n.Math==Math?n:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.visibility=function(i){var s,c=e(this),r=c.selector||"",a=(new Date).getTime(),l=[],d=arguments[0],u="string"==typeof d,f=[].slice.call(arguments,1),b=c.length,m=0;return c.each(function(){var c,g,p,v,h=e.isPlainObject(i)?e.extend(!0,{},e.fn.visibility.settings,i):e.extend({},e.fn.visibility.settings),P=h.className,x=h.namespace,C=h.error,y=h.metadata,R="."+x,V="module-"+x,S=e(n),k=e(this),T=e(h.context),O=(k.selector||"",k.data(V)),A=n.requestAnimationFrame||n.mozRequestAnimationFrame||n.webkitRequestAnimationFrame||n.msRequestAnimationFrame||function(e){setTimeout(e,0)},z=this,w=!1;v={initialize:function(){v.debug("Initializing",h),v.setup.cache(),v.should.trackChanges()&&("image"==h.type&&v.setup.image(),"fixed"==h.type&&v.setup.fixed(),h.observeChanges&&v.observeChanges(),v.bind.events()),v.save.position(),v.is.visible()||v.error(C.visible,k),h.initialCheck&&v.checkVisibility(),v.instantiate()},instantiate:function(){v.debug("Storing instance",v),k.data(V,v),O=v},destroy:function(){v.verbose("Destroying previous module"),p&&p.disconnect(),g&&g.disconnect(),S.off("load"+R,v.event.load).off("resize"+R,v.event.resize),T.off("scroll"+R,v.event.scroll).off("scrollchange"+R,v.event.scrollchange),"fixed"==h.type&&(v.resetFixed(),v.remove.placeholder()),k.off(R).removeData(V)},observeChanges:function(){"MutationObserver"in n&&(g=new MutationObserver(v.event.contextChanged),p=new MutationObserver(v.event.changed),g.observe(o,{childList:!0,subtree:!0}),p.observe(z,{childList:!0,subtree:!0}),v.debug("Setting up mutation observer",p))},bind:{events:function(){v.verbose("Binding visibility events to scroll and resize"),h.refreshOnLoad&&S.on("load"+R,v.event.load),S.on("resize"+R,v.event.resize),T.off("scroll"+R).on("scroll"+R,v.event.scroll).on("scrollchange"+R,v.event.scrollchange)}},event:{changed:function(e){v.verbose("DOM tree modified, updating visibility calculations"),v.timer=setTimeout(function(){v.verbose("DOM tree modified, updating sticky menu"),v.refresh()},100)},contextChanged:function(n){[].forEach.call(n,function(n){n.removedNodes&&[].forEach.call(n.removedNodes,function(n){(n==z||e(n).find(z).length>0)&&(v.debug("Element removed from DOM, tearing down events"),v.destroy())})})},resize:function(){v.debug("Window resized"),h.refreshOnResize&&A(v.refresh)},load:function(){v.debug("Page finished loading"),A(v.refresh)},scroll:function(){h.throttle?(clearTimeout(v.timer),v.timer=setTimeout(function(){T.triggerHandler("scrollchange"+R,[T.scrollTop()])},h.throttle)):A(function(){T.triggerHandler("scrollchange"+R,[T.scrollTop()])})},scrollchange:function(e,n){v.checkVisibility(n)}},precache:function(n,t){n instanceof Array||(n=[n]);for(var i=n.length,s=0,c=[],r=o.createElement("img"),a=function(){s++,s>=n.length&&e.isFunction(t)&&t()};i--;)r=o.createElement("img"),r.onload=a,r.onerror=a,r.src=n[i],c.push(r)},enableCallbacks:function(){v.debug("Allowing callbacks to occur"),w=!1},disableCallbacks:function(){v.debug("Disabling all callbacks temporarily"),w=!0},should:{trackChanges:function(){return u?(v.debug("One time query, no need to bind events"),!1):(v.debug("Callbacks being attached"),!0)}},setup:{cache:function(){v.cache={occurred:{},screen:{},element:{}}},image:function(){var e=k.data(y.src);e&&(v.verbose("Lazy loading image",e),h.once=!0,h.observeChanges=!1,h.onOnScreen=function(){v.debug("Image on screen",z),v.precache(e,function(){v.set.image(e,function(){m++,m==b&&h.onAllLoaded.call(this),h.onLoad.call(this)})})})},fixed:function(){v.debug("Setting up fixed"),h.once=!1,h.observeChanges=!1,h.initialCheck=!0,h.refreshOnLoad=!0,i.transition||(h.transition=!1),v.create.placeholder(),v.debug("Added placeholder",c),h.onTopPassed=function(){v.debug("Element passed, adding fixed position",k),v.show.placeholder(),v.set.fixed(),h.transition&&e.fn.transition!==t&&k.transition(h.transition,h.duration)},h.onTopPassedReverse=function(){v.debug("Element returned to position, removing fixed",k),v.hide.placeholder(),v.remove.fixed()}}},create:{placeholder:function(){v.verbose("Creating fixed position placeholder"),c=k.clone(!1).css("display","none").addClass(P.placeholder).insertAfter(k)}},show:{placeholder:function(){v.verbose("Showing placeholder"),c.css("display","block").css("visibility","hidden")}},hide:{placeholder:function(){v.verbose("Hiding placeholder"),c.css("display","none").css("visibility","")}},set:{fixed:function(){v.verbose("Setting element to fixed position"),k.addClass(P.fixed).css({position:"fixed",top:h.offset+"px",left:"auto",zIndex:h.zIndex}),h.onFixed.call(z)},image:function(n,o){if(k.attr("src",n),h.transition)if(e.fn.transition!==t){if(k.hasClass(P.visible))return void v.debug("Transition already occurred on this image, skipping animation");k.transition(h.transition,h.duration,o)}else k.fadeIn(h.duration,o);else k.show()}},is:{onScreen:function(){var e=v.get.elementCalculations();return e.onScreen},offScreen:function(){var e=v.get.elementCalculations();return e.offScreen},visible:function(){return!(!v.cache||!v.cache.element)&&!(0===v.cache.element.width&&0===v.cache.element.offset.top)}},refresh:function(){v.debug("Refreshing constants (width/height)"),"fixed"==h.type&&v.resetFixed(),v.reset(),v.save.position(),h.checkOnRefresh&&v.checkVisibility(),h.onRefresh.call(z)},resetFixed:function(){v.remove.fixed(),v.remove.occurred()},reset:function(){v.verbose("Resetting all cached values"),e.isPlainObject(v.cache)&&(v.cache.screen={},v.cache.element={})},checkVisibility:function(e){v.verbose("Checking visibility of element",v.cache.element),!w&&v.is.visible()&&(v.save.scroll(e),v.save.calculations(),v.passed(),v.passingReverse(),v.topVisibleReverse(),v.bottomVisibleReverse(),v.topPassedReverse(),v.bottomPassedReverse(),v.onScreen(),v.offScreen(),v.passing(),v.topVisible(),v.bottomVisible(),v.topPassed(),v.bottomPassed(),h.onUpdate&&h.onUpdate.call(z,v.get.elementCalculations()))},passed:function(n,o){var i=v.get.elementCalculations();if(n&&o)h.onPassed[n]=o;else{if(n!==t)return v.get.pixelsPassed(n)>i.pixelsPassed;i.passing&&e.each(h.onPassed,function(e,n){i.bottomVisible||i.pixelsPassed>v.get.pixelsPassed(e)?v.execute(n,e):h.once||v.remove.occurred(n)})}},onScreen:function(e){var n=v.get.elementCalculations(),o=e||h.onOnScreen,i="onScreen";if(e&&(v.debug("Adding callback for onScreen",e),h.onOnScreen=e),n.onScreen?v.execute(o,i):h.once||v.remove.occurred(i),e!==t)return n.onOnScreen},offScreen:function(e){var n=v.get.elementCalculations(),o=e||h.onOffScreen,i="offScreen";if(e&&(v.debug("Adding callback for offScreen",e),h.onOffScreen=e),n.offScreen?v.execute(o,i):h.once||v.remove.occurred(i),e!==t)return n.onOffScreen},passing:function(e){var n=v.get.elementCalculations(),o=e||h.onPassing,i="passing";if(e&&(v.debug("Adding callback for passing",e),h.onPassing=e),n.passing?v.execute(o,i):h.once||v.remove.occurred(i),e!==t)return n.passing},topVisible:function(e){var n=v.get.elementCalculations(),o=e||h.onTopVisible,i="topVisible";if(e&&(v.debug("Adding callback for top visible",e),h.onTopVisible=e),n.topVisible?v.execute(o,i):h.once||v.remove.occurred(i),e===t)return n.topVisible},bottomVisible:function(e){var n=v.get.elementCalculations(),o=e||h.onBottomVisible,i="bottomVisible";if(e&&(v.debug("Adding callback for bottom visible",e),h.onBottomVisible=e),n.bottomVisible?v.execute(o,i):h.once||v.remove.occurred(i),e===t)return n.bottomVisible},topPassed:function(e){var n=v.get.elementCalculations(),o=e||h.onTopPassed,i="topPassed";if(e&&(v.debug("Adding callback for top passed",e),h.onTopPassed=e),n.topPassed?v.execute(o,i):h.once||v.remove.occurred(i),e===t)return n.topPassed},bottomPassed:function(e){var n=v.get.elementCalculations(),o=e||h.onBottomPassed,i="bottomPassed";if(e&&(v.debug("Adding callback for bottom passed",e),h.onBottomPassed=e),n.bottomPassed?v.execute(o,i):h.once||v.remove.occurred(i),e===t)return n.bottomPassed},passingReverse:function(e){var n=v.get.elementCalculations(),o=e||h.onPassingReverse,i="passingReverse";if(e&&(v.debug("Adding callback for passing reverse",e),h.onPassingReverse=e),n.passing?h.once||v.remove.occurred(i):v.get.occurred("passing")&&v.execute(o,i),e!==t)return!n.passing},topVisibleReverse:function(e){var n=v.get.elementCalculations(),o=e||h.onTopVisibleReverse,i="topVisibleReverse";if(e&&(v.debug("Adding callback for top visible reverse",e),h.onTopVisibleReverse=e),n.topVisible?h.once||v.remove.occurred(i):v.get.occurred("topVisible")&&v.execute(o,i),e===t)return!n.topVisible},bottomVisibleReverse:function(e){var n=v.get.elementCalculations(),o=e||h.onBottomVisibleReverse,i="bottomVisibleReverse";if(e&&(v.debug("Adding callback for bottom visible reverse",e),h.onBottomVisibleReverse=e),n.bottomVisible?h.once||v.remove.occurred(i):v.get.occurred("bottomVisible")&&v.execute(o,i),e===t)return!n.bottomVisible},topPassedReverse:function(e){var n=v.get.elementCalculations(),o=e||h.onTopPassedReverse,i="topPassedReverse";if(e&&(v.debug("Adding callback for top passed reverse",e),h.onTopPassedReverse=e),n.topPassed?h.once||v.remove.occurred(i):v.get.occurred("topPassed")&&v.execute(o,i),e===t)return!n.onTopPassed},bottomPassedReverse:function(e){var n=v.get.elementCalculations(),o=e||h.onBottomPassedReverse,i="bottomPassedReverse";if(e&&(v.debug("Adding callback for bottom passed reverse",e),h.onBottomPassedReverse=e),n.bottomPassed?h.once||v.remove.occurred(i):v.get.occurred("bottomPassed")&&v.execute(o,i),e===t)return!n.bottomPassed},execute:function(e,n){var o=v.get.elementCalculations(),t=v.get.screenCalculations();e=e||!1,e&&(h.continuous?(v.debug("Callback being called continuously",n,o),e.call(z,o,t)):v.get.occurred(n)||(v.debug("Conditions met",n,o),e.call(z,o,t))),v.save.occurred(n)},remove:{fixed:function(){v.debug("Removing fixed position"),k.removeClass(P.fixed).css({position:"",top:"",left:"",zIndex:""}),h.onUnfixed.call(z)},placeholder:function(){v.debug("Removing placeholder content"),c&&c.remove()},occurred:function(e){if(e){var n=v.cache.occurred;n[e]!==t&&n[e]===!0&&(v.debug("Callback can now be called again",e),v.cache.occurred[e]=!1)}else v.cache.occurred={}}},save:{calculations:function(){v.verbose("Saving all calculations necessary to determine positioning"),v.save.direction(),v.save.screenCalculations(),v.save.elementCalculations()},occurred:function(e){e&&(v.cache.occurred[e]!==t&&v.cache.occurred[e]===!0||(v.verbose("Saving callback occurred",e),v.cache.occurred[e]=!0))},scroll:function(e){e=e+h.offset||T.scrollTop()+h.offset,v.cache.scroll=e},direction:function(){var e,n=v.get.scroll(),o=v.get.lastScroll();return e=n>o&&o?"down":n=n.top,n.topPassed=e.top>=n.top,n.bottomVisible=e.bottom>=n.bottom,n.bottomPassed=e.top>=n.bottom,n.pixelsPassed=0,n.percentagePassed=0,n.onScreen=n.topVisible&&!n.bottomPassed,n.passing=n.topPassed&&!n.bottomPassed,n.offScreen=!n.onScreen,n.passing&&(n.pixelsPassed=e.top-n.top,n.percentagePassed=(e.top-n.top)/n.height),v.cache.element=n,v.verbose("Updated element calculations",n),n},screenCalculations:function(){var e=v.get.scroll();return v.save.direction(),v.cache.screen.top=e,v.cache.screen.bottom=e+v.cache.screen.height,v.cache.screen},screenSize:function(){v.verbose("Saving window position"),v.cache.screen={height:T.height()}},position:function(){v.save.screenSize(),v.save.elementPosition()}},get:{pixelsPassed:function(e){var n=v.get.elementCalculations();return e.search("%")>-1?n.height*(parseInt(e,10)/100):parseInt(e,10)},occurred:function(e){return v.cache.occurred!==t&&(v.cache.occurred[e]||!1)},direction:function(){return v.cache.direction===t&&v.save.direction(),v.cache.direction},elementPosition:function(){return v.cache.element===t&&v.save.elementPosition(),v.cache.element},elementCalculations:function(){return v.cache.element===t&&v.save.elementCalculations(),v.cache.element},screenCalculations:function(){return v.cache.screen===t&&v.save.screenCalculations(),v.cache.screen},screenSize:function(){return v.cache.screen===t&&v.save.screenSize(),v.cache.screen},scroll:function(){return v.cache.scroll===t&&v.save.scroll(),v.cache.scroll},lastScroll:function(){return v.cache.screen===t?(v.debug("First scroll event, no last scroll could be found"),!1):v.cache.screen.top}},setting:function(n,o){if(e.isPlainObject(n))e.extend(!0,h,n);else{if(o===t)return h[n];h[n]=o}},internal:function(n,o){if(e.isPlainObject(n))e.extend(!0,v,n);else{if(o===t)return v[n];v[n]=o}},debug:function(){!h.silent&&h.debug&&(h.performance?v.performance.log(arguments):(v.debug=Function.prototype.bind.call(console.info,console,h.name+":"),v.debug.apply(console,arguments)))},verbose:function(){!h.silent&&h.verbose&&h.debug&&(h.performance?v.performance.log(arguments):(v.verbose=Function.prototype.bind.call(console.info,console,h.name+":"),v.verbose.apply(console,arguments)))},error:function(){h.silent||(v.error=Function.prototype.bind.call(console.error,console,h.name+":"),v.error.apply(console,arguments))},performance:{log:function(e){var n,o,t;h.performance&&(n=(new Date).getTime(),t=a||n,o=n-t,a=n,l.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:z,"Execution Time":o})),clearTimeout(v.performance.timer),v.performance.timer=setTimeout(v.performance.display,500)},display:function(){var n=h.name+":",o=0;a=!1,clearTimeout(v.performance.timer),e.each(l,function(e,n){o+=n["Execution Time"]}),n+=" "+o+"ms",r&&(n+=" '"+r+"'"),(console.group!==t||console.table!==t)&&l.length>0&&(console.groupCollapsed(n),console.table?console.table(l):e.each(l,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),l=[]}},invoke:function(n,o,i){var c,r,a,l=O;return o=o||f,i=z||i,"string"==typeof n&&l!==t&&(n=n.split(/[\. ]/),c=n.length-1,e.each(n,function(o,i){var s=o!=c?i+n[o+1].charAt(0).toUpperCase()+n[o+1].slice(1):n;if(e.isPlainObject(l[s])&&o!=c)l=l[s];else{if(l[s]!==t)return r=l[s],!1;if(!e.isPlainObject(l[i])||o==c)return l[i]!==t?(r=l[i],!1):(v.error(C.method,n),!1);l=l[i]}})),e.isFunction(r)?a=r.apply(i,o):r!==t&&(a=r),e.isArray(s)?s.push(a):s!==t?s=[s,a]:a!==t&&(s=a),r}},u?(O===t&&v.initialize(),O.save.scroll(),O.save.calculations(),v.invoke(d)):(O!==t&&O.invoke("destroy"),v.initialize())}),s!==t?s:this},e.fn.visibility.settings={name:"Visibility",namespace:"visibility",debug:!1,verbose:!1,performance:!0,observeChanges:!0,initialCheck:!0,refreshOnLoad:!0,refreshOnResize:!0,checkOnRefresh:!0,once:!0,continuous:!1,offset:0,includeMargin:!1,context:n,throttle:!1,type:!1,zIndex:"10",transition:"fade in",duration:1e3,onPassed:{},onOnScreen:!1,onOffScreen:!1,onPassing:!1,onTopVisible:!1,onBottomVisible:!1,onTopPassed:!1,onBottomPassed:!1,onPassingReverse:!1,onTopVisibleReverse:!1,onBottomVisibleReverse:!1,onTopPassedReverse:!1,onBottomPassedReverse:!1,onLoad:function(){},onAllLoaded:function(){},onFixed:function(){},onUnfixed:function(){},onUpdate:!1,onRefresh:function(){},metadata:{src:"src"},className:{fixed:"fixed",placeholder:"placeholder",visible:"visible"},error:{method:"The method you called is not defined.",visible:"Element is hidden, you must call refresh after element becomes visible"}}}(jQuery,window,document); \ No newline at end of file +!function(e,o,n,t){"use strict";o="undefined"!=typeof o&&o.Math==Math?o:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.visibility=function(i){var s,c=e(this),r=c.selector||"",a=(new Date).getTime(),l=[],d=arguments[0],u="string"==typeof d,f=[].slice.call(arguments,1),b=c.length,g=0;return c.each(function(){var c,m,v,p,h=e.isPlainObject(i)?e.extend(!0,{},e.fn.visibility.settings,i):e.extend({},e.fn.visibility.settings),P=h.className,x=h.namespace,C=h.error,y=h.metadata,S="."+x,R="module-"+x,V=e(o),k=e(this),T=e(h.context),O=(k.selector||"",k.data(R)),z=o.requestAnimationFrame||o.mozRequestAnimationFrame||o.webkitRequestAnimationFrame||o.msRequestAnimationFrame||function(e){setTimeout(e,0)},A=this,w=!1;p={initialize:function(){p.debug("Initializing",h),p.setup.cache(),p.should.trackChanges()&&("image"==h.type&&p.setup.image(),"fixed"==h.type&&p.setup.fixed(),h.observeChanges&&p.observeChanges(),p.bind.events()),p.save.position(),p.is.visible()||p.error(C.visible,k),h.initialCheck&&p.checkVisibility(),p.instantiate()},instantiate:function(){p.debug("Storing instance",p),k.data(R,p),O=p},destroy:function(){p.verbose("Destroying previous module"),v&&v.disconnect(),m&&m.disconnect(),V.off("load"+S,p.event.load).off("resize"+S,p.event.resize),T.off("scroll"+S,p.event.scroll).off("scrollchange"+S,p.event.scrollchange),"fixed"==h.type&&(p.resetFixed(),p.remove.placeholder()),k.off(S).removeData(R)},observeChanges:function(){"MutationObserver"in o&&(m=new MutationObserver(p.event.contextChanged),v=new MutationObserver(p.event.changed),m.observe(n,{childList:!0,subtree:!0}),v.observe(A,{childList:!0,subtree:!0}),p.debug("Setting up mutation observer",v))},bind:{events:function(){p.verbose("Binding visibility events to scroll and resize"),h.refreshOnLoad&&V.on("load"+S,p.event.load),V.on("resize"+S,p.event.resize),T.off("scroll"+S).on("scroll"+S,p.event.scroll).on("scrollchange"+S,p.event.scrollchange)}},event:{changed:function(e){p.verbose("DOM tree modified, updating visibility calculations"),p.timer=setTimeout(function(){p.verbose("DOM tree modified, updating sticky menu"),p.refresh()},100)},contextChanged:function(o){[].forEach.call(o,function(o){o.removedNodes&&[].forEach.call(o.removedNodes,function(o){(o==A||e(o).find(A).length>0)&&(p.debug("Element removed from DOM, tearing down events"),p.destroy())})})},resize:function(){p.debug("Window resized"),h.refreshOnResize&&z(p.refresh)},load:function(){p.debug("Page finished loading"),z(p.refresh)},scroll:function(){h.throttle?(clearTimeout(p.timer),p.timer=setTimeout(function(){T.triggerHandler("scrollchange"+S,[T.scrollTop()])},h.throttle)):z(function(){T.triggerHandler("scrollchange"+S,[T.scrollTop()])})},scrollchange:function(e,o){p.checkVisibility(o)}},precache:function(o,t){o instanceof Array||(o=[o]);for(var i=o.length,s=0,c=[],r=n.createElement("img"),a=function(){s++,s>=o.length&&e.isFunction(t)&&t()};i--;)r=n.createElement("img"),r.onload=a,r.onerror=a,r.src=o[i],c.push(r)},enableCallbacks:function(){p.debug("Allowing callbacks to occur"),w=!1},disableCallbacks:function(){p.debug("Disabling all callbacks temporarily"),w=!0},should:{trackChanges:function(){return u?(p.debug("One time query, no need to bind events"),!1):(p.debug("Callbacks being attached"),!0)}},setup:{cache:function(){p.cache={occurred:{},screen:{},element:{}}},image:function(){var e=k.data(y.src);e&&(p.verbose("Lazy loading image",e),h.once=!0,h.observeChanges=!1,h.onOnScreen=function(){p.debug("Image on screen",A),p.precache(e,function(){p.set.image(e,function(){g++,g==b&&h.onAllLoaded.call(this),h.onLoad.call(this)})})})},fixed:function(){p.debug("Setting up fixed"),h.once=!1,h.observeChanges=!1,h.initialCheck=!0,h.refreshOnLoad=!0,i.transition||(h.transition=!1),p.create.placeholder(),p.debug("Added placeholder",c),h.onTopPassed=function(){p.debug("Element passed, adding fixed position",k),p.show.placeholder(),p.set.fixed(),h.transition&&e.fn.transition!==t&&k.transition(h.transition,h.duration)},h.onTopPassedReverse=function(){p.debug("Element returned to position, removing fixed",k),p.hide.placeholder(),p.remove.fixed()}}},create:{placeholder:function(){p.verbose("Creating fixed position placeholder"),c=k.clone(!1).css("display","none").addClass(P.placeholder).insertAfter(k)}},show:{placeholder:function(){p.verbose("Showing placeholder"),c.css("display","block").css("visibility","hidden")}},hide:{placeholder:function(){p.verbose("Hiding placeholder"),c.css("display","none").css("visibility","")}},set:{fixed:function(){p.verbose("Setting element to fixed position"),k.addClass(P.fixed).css({position:"fixed",top:h.offset+"px",left:"auto",zIndex:h.zIndex}),h.onFixed.call(A)},image:function(o,n){if(k.attr("src",o),h.transition)if(e.fn.transition!==t){if(k.hasClass(P.visible))return void p.debug("Transition already occurred on this image, skipping animation");k.transition(h.transition,h.duration,n)}else k.fadeIn(h.duration,n);else k.show()}},is:{onScreen:function(){var e=p.get.elementCalculations();return e.onScreen},offScreen:function(){var e=p.get.elementCalculations();return e.offScreen},visible:function(){return p.cache&&p.cache.element?!(0===p.cache.element.width&&0===p.cache.element.offset.top):!1},verticallyScrollableContext:function(){var e=T.get(0)!==o?T.css("overflow-y"):!1;return"auto"==e||"scroll"==e},horizontallyScrollableContext:function(){var e=T.get(0)!==o?T.css("overflow-x"):!1;return"auto"==e||"scroll"==e}},refresh:function(){p.debug("Refreshing constants (width/height)"),"fixed"==h.type&&p.resetFixed(),p.reset(),p.save.position(),h.checkOnRefresh&&p.checkVisibility(),h.onRefresh.call(A)},resetFixed:function(){p.remove.fixed(),p.remove.occurred()},reset:function(){p.verbose("Resetting all cached values"),e.isPlainObject(p.cache)&&(p.cache.screen={},p.cache.element={})},checkVisibility:function(e){p.verbose("Checking visibility of element",p.cache.element),!w&&p.is.visible()&&(p.save.scroll(e),p.save.calculations(),p.passed(),p.passingReverse(),p.topVisibleReverse(),p.bottomVisibleReverse(),p.topPassedReverse(),p.bottomPassedReverse(),p.onScreen(),p.offScreen(),p.passing(),p.topVisible(),p.bottomVisible(),p.topPassed(),p.bottomPassed(),h.onUpdate&&h.onUpdate.call(A,p.get.elementCalculations()))},passed:function(o,n){var i=p.get.elementCalculations();if(o&&n)h.onPassed[o]=n;else{if(o!==t)return p.get.pixelsPassed(o)>i.pixelsPassed;i.passing&&e.each(h.onPassed,function(e,o){i.bottomVisible||i.pixelsPassed>p.get.pixelsPassed(e)?p.execute(o,e):h.once||p.remove.occurred(o)})}},onScreen:function(e){var o=p.get.elementCalculations(),n=e||h.onOnScreen,i="onScreen";return e&&(p.debug("Adding callback for onScreen",e),h.onOnScreen=e),o.onScreen?p.execute(n,i):h.once||p.remove.occurred(i),e!==t?o.onOnScreen:void 0},offScreen:function(e){var o=p.get.elementCalculations(),n=e||h.onOffScreen,i="offScreen";return e&&(p.debug("Adding callback for offScreen",e),h.onOffScreen=e),o.offScreen?p.execute(n,i):h.once||p.remove.occurred(i),e!==t?o.onOffScreen:void 0},passing:function(e){var o=p.get.elementCalculations(),n=e||h.onPassing,i="passing";return e&&(p.debug("Adding callback for passing",e),h.onPassing=e),o.passing?p.execute(n,i):h.once||p.remove.occurred(i),e!==t?o.passing:void 0},topVisible:function(e){var o=p.get.elementCalculations(),n=e||h.onTopVisible,i="topVisible";return e&&(p.debug("Adding callback for top visible",e),h.onTopVisible=e),o.topVisible?p.execute(n,i):h.once||p.remove.occurred(i),e===t?o.topVisible:void 0},bottomVisible:function(e){var o=p.get.elementCalculations(),n=e||h.onBottomVisible,i="bottomVisible";return e&&(p.debug("Adding callback for bottom visible",e),h.onBottomVisible=e),o.bottomVisible?p.execute(n,i):h.once||p.remove.occurred(i),e===t?o.bottomVisible:void 0},topPassed:function(e){var o=p.get.elementCalculations(),n=e||h.onTopPassed,i="topPassed";return e&&(p.debug("Adding callback for top passed",e),h.onTopPassed=e),o.topPassed?p.execute(n,i):h.once||p.remove.occurred(i),e===t?o.topPassed:void 0},bottomPassed:function(e){var o=p.get.elementCalculations(),n=e||h.onBottomPassed,i="bottomPassed";return e&&(p.debug("Adding callback for bottom passed",e),h.onBottomPassed=e),o.bottomPassed?p.execute(n,i):h.once||p.remove.occurred(i),e===t?o.bottomPassed:void 0},passingReverse:function(e){var o=p.get.elementCalculations(),n=e||h.onPassingReverse,i="passingReverse";return e&&(p.debug("Adding callback for passing reverse",e),h.onPassingReverse=e),o.passing?h.once||p.remove.occurred(i):p.get.occurred("passing")&&p.execute(n,i),e!==t?!o.passing:void 0},topVisibleReverse:function(e){var o=p.get.elementCalculations(),n=e||h.onTopVisibleReverse,i="topVisibleReverse";return e&&(p.debug("Adding callback for top visible reverse",e),h.onTopVisibleReverse=e),o.topVisible?h.once||p.remove.occurred(i):p.get.occurred("topVisible")&&p.execute(n,i),e===t?!o.topVisible:void 0},bottomVisibleReverse:function(e){var o=p.get.elementCalculations(),n=e||h.onBottomVisibleReverse,i="bottomVisibleReverse";return e&&(p.debug("Adding callback for bottom visible reverse",e),h.onBottomVisibleReverse=e),o.bottomVisible?h.once||p.remove.occurred(i):p.get.occurred("bottomVisible")&&p.execute(n,i),e===t?!o.bottomVisible:void 0},topPassedReverse:function(e){var o=p.get.elementCalculations(),n=e||h.onTopPassedReverse,i="topPassedReverse";return e&&(p.debug("Adding callback for top passed reverse",e),h.onTopPassedReverse=e),o.topPassed?h.once||p.remove.occurred(i):p.get.occurred("topPassed")&&p.execute(n,i),e===t?!o.onTopPassed:void 0},bottomPassedReverse:function(e){var o=p.get.elementCalculations(),n=e||h.onBottomPassedReverse,i="bottomPassedReverse";return e&&(p.debug("Adding callback for bottom passed reverse",e),h.onBottomPassedReverse=e),o.bottomPassed?h.once||p.remove.occurred(i):p.get.occurred("bottomPassed")&&p.execute(n,i),e===t?!o.bottomPassed:void 0},execute:function(e,o){var n=p.get.elementCalculations(),t=p.get.screenCalculations();e=e||!1,e&&(h.continuous?(p.debug("Callback being called continuously",o,n),e.call(A,n,t)):p.get.occurred(o)||(p.debug("Conditions met",o,n),e.call(A,n,t))),p.save.occurred(o)},remove:{fixed:function(){p.debug("Removing fixed position"),k.removeClass(P.fixed).css({position:"",top:"",left:"",zIndex:""}),h.onUnfixed.call(A)},placeholder:function(){p.debug("Removing placeholder content"),c&&c.remove()},occurred:function(e){if(e){var o=p.cache.occurred;o[e]!==t&&o[e]===!0&&(p.debug("Callback can now be called again",e),p.cache.occurred[e]=!1)}else p.cache.occurred={}}},save:{calculations:function(){p.verbose("Saving all calculations necessary to determine positioning"),p.save.direction(),p.save.screenCalculations(),p.save.elementCalculations()},occurred:function(e){e&&(p.cache.occurred[e]!==t&&p.cache.occurred[e]===!0||(p.verbose("Saving callback occurred",e),p.cache.occurred[e]=!0))},scroll:function(e){e=e+h.offset||T.scrollTop()+h.offset,p.cache.scroll=e},direction:function(){var e,o=p.get.scroll(),n=p.get.lastScroll();return e=o>n&&n?"down":n>o&&n?"up":"static",p.cache.direction=e,p.cache.direction},elementPosition:function(){var e=p.cache.element,o=p.get.screenSize();return p.verbose("Saving element position"),e.fits=e.height=o.top,o.bottomPassed=e.top>=o.bottom,o.topVisible=e.bottom>=o.top&&!o.bottomPassed,o.bottomVisible=e.bottom>=o.bottom&&!o.topPassed,o.pixelsPassed=0,o.percentagePassed=0,o.onScreen=o.topVisible&&!o.bottomPassed,o.passing=o.topPassed&&!o.bottomPassed,o.offScreen=!o.onScreen,o.passing&&(o.pixelsPassed=e.top-o.top,o.percentagePassed=(e.top-o.top)/o.height),p.cache.element=o,p.verbose("Updated element calculations",o),o},screenCalculations:function(){var e=p.get.scroll();return p.save.direction(),p.cache.screen.top=e,p.cache.screen.bottom=e+p.cache.screen.height,p.cache.screen},screenSize:function(){p.verbose("Saving window position"),p.cache.screen={height:T.height()}},position:function(){p.save.screenSize(),p.save.elementPosition()}},get:{pixelsPassed:function(e){var o=p.get.elementCalculations();return e.search("%")>-1?o.height*(parseInt(e,10)/100):parseInt(e,10)},occurred:function(e){return p.cache.occurred!==t?p.cache.occurred[e]||!1:!1},direction:function(){return p.cache.direction===t&&p.save.direction(),p.cache.direction},elementPosition:function(){return p.cache.element===t&&p.save.elementPosition(),p.cache.element},elementCalculations:function(){return p.cache.element===t&&p.save.elementCalculations(),p.cache.element},screenCalculations:function(){return p.cache.screen===t&&p.save.screenCalculations(),p.cache.screen},screenSize:function(){return p.cache.screen===t&&p.save.screenSize(),p.cache.screen},scroll:function(){return p.cache.scroll===t&&p.save.scroll(),p.cache.scroll},lastScroll:function(){return p.cache.screen===t?(p.debug("First scroll event, no last scroll could be found"),!1):p.cache.screen.top}},setting:function(o,n){if(e.isPlainObject(o))e.extend(!0,h,o);else{if(n===t)return h[o];h[o]=n}},internal:function(o,n){if(e.isPlainObject(o))e.extend(!0,p,o);else{if(n===t)return p[o];p[o]=n}},debug:function(){!h.silent&&h.debug&&(h.performance?p.performance.log(arguments):(p.debug=Function.prototype.bind.call(console.info,console,h.name+":"),p.debug.apply(console,arguments)))},verbose:function(){!h.silent&&h.verbose&&h.debug&&(h.performance?p.performance.log(arguments):(p.verbose=Function.prototype.bind.call(console.info,console,h.name+":"),p.verbose.apply(console,arguments)))},error:function(){h.silent||(p.error=Function.prototype.bind.call(console.error,console,h.name+":"),p.error.apply(console,arguments))},performance:{log:function(e){var o,n,t;h.performance&&(o=(new Date).getTime(),t=a||o,n=o-t,a=o,l.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:A,"Execution Time":n})),clearTimeout(p.performance.timer),p.performance.timer=setTimeout(p.performance.display,500)},display:function(){var o=h.name+":",n=0;a=!1,clearTimeout(p.performance.timer),e.each(l,function(e,o){n+=o["Execution Time"]}),o+=" "+n+"ms",r&&(o+=" '"+r+"'"),(console.group!==t||console.table!==t)&&l.length>0&&(console.groupCollapsed(o),console.table?console.table(l):e.each(l,function(e,o){console.log(o.Name+": "+o["Execution Time"]+"ms")}),console.groupEnd()),l=[]}},invoke:function(o,n,i){var c,r,a,l=O;return n=n||f,i=A||i,"string"==typeof o&&l!==t&&(o=o.split(/[\. ]/),c=o.length-1,e.each(o,function(n,i){var s=n!=c?i+o[n+1].charAt(0).toUpperCase()+o[n+1].slice(1):o;if(e.isPlainObject(l[s])&&n!=c)l=l[s];else{if(l[s]!==t)return r=l[s],!1;if(!e.isPlainObject(l[i])||n==c)return l[i]!==t?(r=l[i],!1):(p.error(C.method,o),!1);l=l[i]}})),e.isFunction(r)?a=r.apply(i,n):r!==t&&(a=r),e.isArray(s)?s.push(a):s!==t?s=[s,a]:a!==t&&(s=a),r}},u?(O===t&&p.initialize(),O.save.scroll(),O.save.calculations(),p.invoke(d)):(O!==t&&O.invoke("destroy"),p.initialize())}),s!==t?s:this},e.fn.visibility.settings={name:"Visibility",namespace:"visibility",debug:!1,verbose:!1,performance:!0,observeChanges:!0,initialCheck:!0,refreshOnLoad:!0,refreshOnResize:!0,checkOnRefresh:!0,once:!0,continuous:!1,offset:0,includeMargin:!1,context:o,throttle:!1,type:!1,zIndex:"10",transition:"fade in",duration:1e3,onPassed:{},onOnScreen:!1,onOffScreen:!1,onPassing:!1,onTopVisible:!1,onBottomVisible:!1,onTopPassed:!1,onBottomPassed:!1,onPassingReverse:!1,onTopVisibleReverse:!1,onBottomVisibleReverse:!1,onTopPassedReverse:!1,onBottomPassedReverse:!1,onLoad:function(){},onAllLoaded:function(){},onFixed:function(){},onUnfixed:function(){},onUpdate:!1,onRefresh:function(){},metadata:{src:"src"},className:{fixed:"fixed",placeholder:"placeholder",visible:"visible"},error:{method:"The method you called is not defined.",visible:"Element is hidden, you must call refresh after element becomes visible"}}}(jQuery,window,document); \ No newline at end of file