define(["angular"],function(){(function(){"use strict";var e,n,t,o,u,r,i,l,c,f,s,a,h,m,p,d,w,v,b,g=[].slice;u=angular.module("angular-inview",[]).directive("inView",["$parse",function(e){return{restrict:"A",require:"?^inViewContainer",link:function(n,t,u,r){var c,f,s,a,m,p;if(u.inView)return c=e(u.inView),f={element:t,wasInView:!1,offset:0,customDebouncedCheck:null,callback:function(e,o,u){return null==e&&(e={}),n.$evalAsync(function(r){return function(){return e.inViewTarget=t[0],c(n,{$event:e,$inview:o,$inviewpart:u})}}(this))}},null!=u.inViewOptions&&(s=n.$eval(u.inViewOptions))&&(f.offset=s.offset||[s.offsetTop||0,s.offsetBottom||0],s.debounce&&(f.customDebouncedCheck=l(function(e){return i([f],t[0],e)},s.debounce))),a=null!=(m=null!=(p=f.customDebouncedCheck)?p:null!=r?r.checkInView:void 0)?m:v,null!=r?r.addItem(f):o(f),setTimeout(a),n.$on("$destroy",function(){return null!=r&&r.removeItem(f),h(f)})}}}]).directive("inViewContainer",function(){return{restrict:"AC",controller:["$element",function(e){return this.items=[],this.addItem=function(e){return this.items.push(e)},this.removeItem=function(e){var n;return this.items=function(){var t,o,u,r;for(u=this.items,r=[],t=0,o=u.length;t<o;t++)n=u[t],n!==e&&r.push(n);return r}.call(this)},this.checkInView=function(n){return function(t){var o,u,r,l;for(l=n.items,u=0,r=l.length;u<r;u++)o=l[u],null!=o.customDebouncedCheck&&o.customDebouncedCheck();return i(function(){var e,n,t,u;for(t=this.items,u=[],e=0,n=t.length;e<n;e++)o=t[e],null==o.customDebouncedCheck&&u.push(o);return u}.call(n),e[0],t)}}(this),this}],link:function(e,n,t,o){return n.bind("scroll",o.checkInView),m(o),e.$on("$destroy",function(){return n.unbind("scroll",o.checkInView),w(o)})}}}),t=[],o=function(e){return t.push(e),r()},h=function(e){var n;return t=function(){var o,u,r;for(r=[],o=0,u=t.length;o<u;o++)n=t[o],n!==e&&r.push(n);return r}(),d()},e=[],m=function(n){return e.push(n),r()},w=function(n){var t;return e=function(){var o,u,r;for(r=[],o=0,u=e.length;o<u;o++)t=e[o],t!==n&&r.push(t);return r}(),d()},n=!1,b=function(n){var o,u,r;for(u=0,r=e.length;u<r;u++)o=e[u],o.checkInView(n);if(t.length)return v(n)},r=function(){if(!n)return n=!0,angular.element(window).bind("checkInView click ready wheel mousewheel DomMouseScroll MozMousePixelScroll resize scroll touchmove mouseup",b)},d=function(){if(n&&!t.length&&!e.length)return n=!1,angular.element(window).unbind("checkInView click ready wheel mousewheel DomMouseScroll MozMousePixelScroll resize scroll touchmove mouseup",b)},p=function(e,n,t,o,u){var r,i;if(t){if(r=c(n.element[0]).top+window.pageYOffset,i=o&&u&&"neither"||o&&"top"||u&&"bottom"||"both",!n.wasInView||n.wasInView!==i||r!==n.lastOffsetTop)return n.lastOffsetTop=r,n.wasInView=i,n.callback(e,!0,i)}else if(n.wasInView)return n.wasInView=!1,n.callback(e,!1)},i=function(e,n,t){var o,u,r,i,l,h,m,d,w,v,b,g,k,V,I;if(I={top:0,bottom:s()},n&&n!==window){if(o=c(n),o.top>I.bottom||o.bottom<I.top){for(h=0,d=e.length;h<d;h++)l=e[h],p(t,l,!1);return}o.top>I.top&&(I.top=o.top),o.bottom<I.bottom&&(I.bottom=o.bottom)}for(V=[],m=0,w=e.length;m<w;m++)l=e[m],i=l.element[0],o=c(i),r=o.top+(a(l.offset)?f(o,l.offset):parseInt(null!=(v=null!=(b=l.offset)?b[0]:void 0)?v:l.offset)),u=o.bottom+(a(l.offset)?f(o,l.offset):parseInt(null!=(g=null!=(k=l.offset)?k[1]:void 0)?g:l.offset)),r<I.bottom&&u>=I.top?V.push(p(t,l,!0,u>I.bottom,r<I.top)):V.push(p(t,l,!1));return V},a=function(e){return"string"==typeof e&&"%"===e.slice(-1)},f=function(e,n){var t;return t=n.substring(0,n.length-1),(e.bottom-e.top)*(t/100)},s=function(){var e,n,t;return(e=window.innerHeight)?e:(n=document.compatMode,!n&&("undefined"!=typeof $&&null!==$&&null!=(t=$.support)?t.boxModel:void 0)||(e="CSS1Compat"===n?document.documentElement.clientHeight:document.body.clientHeight),e)},c=function(e){var n,t,o;if(null!=e.getBoundingClientRect)return e.getBoundingClientRect();for(o=0,n=e;n;)o+=n.offsetTop,n=n.offsetParent;for(t=e.parentElement;t;)null!=t.scrollTop&&(o-=t.scrollTop),t=t.parentElement;return{top:o,bottom:o+e.offsetHeight}},l=function(e,n){var t;return t=null,function(){var o;return o=1<=arguments.length?g.call(arguments,0):[],null!=t&&clearTimeout(t),t=setTimeout(function(){return e.apply(null,o)},null!=n?n:100)}},v=function(e){var n,o,u;for(o=0,u=t.length;o<u;o++)n=t[o],null!=n.customDebouncedCheck&&n.customDebouncedCheck();return i(function(){var e,o,u;for(u=[],e=0,o=t.length;e<o;e++)n=t[e],null==n.customDebouncedCheck&&u.push(n);return u}(),null,e)}}).call(this)});