-
Notifications
You must be signed in to change notification settings - Fork 3
/
jquery.sonar.min.js
1 lines (1 loc) · 1.43 KB
/
jquery.sonar.min.js
1
!function(e,t,n,o){e.fn.sonar=function(t,n){if(typeof t==="boolean"){n=t;t=o}return e.sonar(this[0],t,n)};var i=n.body,f=e(t),l="scrollin",r="scrollout",s=function(e,f,l){if(e){i||(i=n.body);var r=e,s=0,a=i.offsetHeight,u=t.innerHeight||n.documentElement.clientHeight||i.clientHeight||0,c=n.documentElement.scrollTop||t.pageYOffset||i.scrollTop||0,d=e.offsetHeight||0;if(!e.sonarElemTop||e.sonarBodyHeight!==a){if(r.offsetParent){do{s+=r.offsetTop}while(r=r.offsetParent)}e.sonarElemTop=s;e.sonarBodyHeight=a}f=f===o?0:f;return!(e.sonarElemTop+(l?0:d)<c-f)&&!(e.sonarElemTop+(l?d:0)>c+u+f)}},a={},u=0,c,d=function(){c&&clearTimeout(c);c=setTimeout(function(){var t,n,o,i,f,l,u;for(o in a){n=a[o];for(l=0,u=n.length;l<u;l++){i=n[l];t=i.elem;f=s(t,i.px,i.full);if(o===r?!f:f){if(!i.tr){if(t["_"+o]){e(t).triggerHandler(o);i.tr=1}else{n.splice(l,1);l--;u--}}}else{i.tr=0}}}},0)},p=function(e,t){e["_"+t]=0},h=function(n,o){var i=o.px,c=o.full,p=o.evt,h=t,m=s(n,i,c),g=0;n["_"+p]=1;if(p===r?!m:m){setTimeout(function(){e(n).triggerHandler(p===r?r:l)},0);g=1}a[p].push({elem:n,px:i,full:c,tr:g});if(!u){f.bind("scroll",d);u=1}};e.sonar=s;a[l]=[];e.event.special[l]={add:function(e){var t=e.data||{},n=this;if(!n[l]){h(this,{px:t.distance,full:t.full,evt:l})}},remove:function(e){p(this,l)}};a[r]=[];e.event.special[r]={add:function(e){var t=e.data||{},n=this;if(!n[r]){h(n,{px:t.distance,full:t.full,evt:r})}},remove:function(e){p(this,r)}}}(jQuery,window,document);