(function(n,t,i){typeof define=="function"&&define.amd?define([],i):typeof module!="undefined"&&typeof exports=="object"?module.exports=i():n[t]=i()})(this,"withinviewport",function(){var t=window.innerHeight!==undefined,n=function n(i,r){var a=!1,e={},u={},o,h,c,f,s,l=[0,0],w,v,y,p;if(typeof jQuery!="undefined"&&i instanceof jQuery&&(i=i.get(0)),typeof i!="object"||i.nodeType!==1)throw new Error("First argument must be an element");for(i.getAttribute("data-withinviewport-settings")&&window.JSON&&(e=JSON.parse(i.getAttribute("data-withinviewport-settings"))),o=typeof r=="string"?{sides:r}:r||{},u.container=o.container||e.container||n.defaults.container||window,u.sides=o.sides||e.sides||n.defaults.sides||"all",u.top=o.top||e.top||n.defaults.top||0,u.right=o.right||e.right||n.defaults.right||0,u.bottom=o.bottom||e.bottom||n.defaults.bottom||0,u.left=o.left||e.left||n.defaults.left||0,typeof jQuery!="undefined"&&u.container instanceof jQuery&&(u.container=u.container.get(0)),(u.container===document.body||!1)&&(u.container=window),c=u.container===window,h={top:function(){return c?f.top>=u.top:f.top>=containerScrollTop-(containerScrollTop-s.top)+u.top},right:function(){return c?f.right<=s.right+containerScrollLeft-u.right:f.right<=s.right-l[0]-u.right},bottom:function(){var n;return n=c?t?u.container.innerHeight:document.documentElement.clientHeight:s.bottom,f.bottom<=n-l[1]-u.bottom},left:function(){return c?f.left>=u.left:f.left>=containerScrollLeft-(containerScrollLeft-s.left)+u.left},all:function(){return h.top()&&h.bottom()&&h.left()&&h.right()}},f=i.getBoundingClientRect(),c?(s=document.documentElement.getBoundingClientRect(),containerScrollTop=document.body.scrollTop,containerScrollLeft=document.body.scrollLeft):(s=u.container.getBoundingClientRect(),containerScrollTop=u.container.scrollTop,containerScrollLeft=u.container.scrollLeft),containerScrollLeft&&(l[0]=18),containerScrollTop&&(l[1]=16),w=/^top$|^right$|^bottom$|^left$|^all$/,v=u.sides.split(" "),p=v.length;p--;)if(y=v[p].toLowerCase(),w.test(y))if(h[y]())a=!0;else{a=!1;break}return a};return n.prototype.defaults={container:document.body,sides:"all",top:0,right:0,bottom:0,left:0},n.defaults=n.prototype.defaults,n.prototype.top=function(t){return n(t,"top")},n.prototype.right=function(t){return n(t,"right")},n.prototype.bottom=function(t){return n(t,"bottom")},n.prototype.left=function(t){return n(t,"left")},n}),function(n){n.fn.withinviewport=function(t){var r,i;return typeof t=="string"&&(t={sides:t}),r=n.extend({},t,{sides:"all"}),i=[],this.each(function(){withinviewport(this,r)&&i.push(this)}),n(i)};n.extend(n.expr[":"],{"within-viewport":function(n){return withinviewport(n,"all")}});n.fn.withinviewporttop=function(t){var r,i;return typeof t=="string"&&(t={sides:t}),r=n.extend({},t,{sides:"top"}),i=[],this.each(function(){withinviewport(this,r)&&i.push(this)}),n(i)};n.fn.withinviewportright=function(t){var r,i;return typeof t=="string"&&(t={sides:t}),r=n.extend({},t,{sides:"right"}),i=[],this.each(function(){withinviewport(this,r)&&i.push(this)}),n(i)};n.fn.withinviewportbottom=function(t){var r,i;return typeof t=="string"&&(t={sides:t}),r=n.extend({},t,{sides:"bottom"}),i=[],this.each(function(){withinviewport(this,r)&&i.push(this)}),n(i)};n.fn.withinviewportleft=function(t){var r,i;return typeof t=="string"&&(t={sides:t}),r=n.extend({},t,{sides:"left"}),i=[],this.each(function(){withinviewport(this,r)&&i.push(this)}),n(i)};n.extend(n.expr[":"],{"within-viewport-top":function(n){return withinviewport(n,"top")},"within-viewport-right":function(n){return withinviewport(n,"right")},"within-viewport-bottom":function(n){return withinviewport(n,"bottom")},"within-viewport-left":function(n){return withinviewport(n,"left")}})}(jQuery)