syriastreet.com/assets/js/lib/jquery.isInViewport.js

1 line
2.1 KiB
JavaScript
Raw Normal View History

2023-10-06 21:29:45 +00:00
!function(u,l){String.prototype.hasOwnProperty("trim")||(String.prototype.trim=function(){return this.replace(/^\s*(.*?)\s*$/,"$1")});function n(e){if(!((e=1===arguments.length&&"function"==typeof e?[e]:e)instanceof Array))throw new SyntaxError("isInViewport: Argument(s) passed to .do/.run should be a function or an array of functions");for(var n=0;n<e.length;n++)if("function"!=typeof e[n])console.warn("isInViewport: Argument(s) passed to .do/.run should be a function or an array of functions"),console.warn("isInViewport: Ignoring non-function values in array and moving on");else for(var t=0;t<this.length;t++)e[n].call(u(this[t]));return this}function d(e,n){var e=e.getBoundingClientRect(),t=e.top,o=e.bottom,r=e.left,e=e.right,n=u.extend({tolerance:0,viewport:l},n),i=n.viewport.jquery?n.viewport:u(n.viewport),s=(i.length||(console.warn("isInViewport: The viewport selector you have provided matches no element on page."),console.warn("isInViewport: Defaulting to viewport as window"),i=u(l)),i.height()),a=i.width(),c=i[0].toString();return i[0]!==l&&"[object Window]"!==c&&"[object DOMWindow]"!==c&&(t-=(c=i[0].getBoundingClientRect()).top,o-=c.top,r-=c.left,e-=c.left,a-=d.scrollBarWidth=d.scrollBarWidth||(c=i,i=u("<div></div>").css({width:"100%"}),c.append(i),c=c.width()-i.width(),i.remove(),c)),n.tolerance=~~Math.round(parseFloat(n.tolerance)),n.tolerance<0&&(n.tolerance=s+n.tolerance),!(e<=0||a<=r)&&(n.tolerance?t<=n.tolerance&&o>=n.tolerance:0<o&&t<=s)}u.fn.do=function(e){return console.warn("isInViewport: .do is deprecated as it causes issues in IE and some browsers since it's a reserved word. Use $.fn.run instead i.e., $(el).run(fn)."),n(e)},u.fn.run=n;function o(e){return e?(1===(e=e.split(",")).length&&isNaN(e[0])&&(e[1]=e[0],e[0]=void 0),{tolerance:e[0]?e[0].trim():void 0,viewport:e[1]?u(e[1].trim()):void 0}):{}}u.extend(u.expr[":"],{"in-viewport":u.expr.createPseudo?u.expr.createPseudo(function(n){return function(e){return d(e,o(n))}}):function(e,n,t){return d(e,o(t[3]))}}),u.fn.isInViewport=function(t){return this.filter(function(e,n){return d(n,t)})}}(jQuery,window);