forked from d-oliveros/ngSticky
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsticky.min.js
1 lines (1 loc) · 2.06 KB
/
sticky.min.js
1
(function(){var a=angular.module("sticky",[]);window.matchMedia||(window.matchMedia=function(){window.console&&console.warn&&console.warn("angular-sticky: This browser does not support matchMedia, therefore the minWidth option will not work on this browser. Polyfill matchMedia to fix this issue.");return function(){return{matches:true}}}());a.directive("sticky",function(){var b=function(d,x,r){var t=d.mediaQuery||null,i=d.stickyClass||"",u=d.bodyClass||"",c=x,x=c[0],o=angular.element(window),s=angular.element(document.body),z=document.documentElement,f={top:c.css("top"),width:c.css("width"),position:c.css("position"),marginTop:c.css("margin-top")},e=false,y=false,w;var k=typeof d.offset==="string"?parseInt(d.offset.replace(/px;?/,"")):0;var m=typeof d.anchor==="string"?d.anchor.toLowerCase().trim():"top";switch(m){case"top":case"bottom":break;default:console.log("Unknown anchor "+m+", defaulting to top");m="top";break}var h=l(x);d.$watch(function(){if(y){return h}h=(m=="top")?l(x):n(x);return h},function(B,A){if(B!==A||typeof w==="undefined"){w=B-k;p()}});function p(){if(t&&!matchMedia("("+t+")").matches){return}if(m=="top"){var C=(window.pageYOffset||z.scrollTop)-(z.clientTop||0);var A=C>=w}else{var B=window.pageYOffset+window.innerHeight;var A=B<=w}if(A&&!y){q()}else{if(!A&&y){v()}}}function q(){f.offsetWidth=x.offsetWidth;y=true;u&&s.addClass(u);i&&c.addClass(i);c.css("width",x.offsetWidth+"px").css("position","fixed").css(m,k+"px").css("margin-top",0);if(m=="bottom"){c.css("margin-bottom",0)}}function v(){y=false;u&&s.removeClass(u);i&&c.removeClass(i);c.css("width",f.offsetWidth+"px").css("top",f.top).css("position",f.position).css("margin-top",f.marginTop)}function l(A){var B=0;if(A.offsetParent){do{B+=A.offsetTop;A=A.offsetParent}while(A)}return B}function n(A){return A.offsetTop+A.clientHeight}o.on("scroll",p);o.on("resize",d.$apply.bind(d,g));d.$on("$destroy",j);function g(){f.offsetWidth=x.offsetWidth}function j(){o.off("scroll",p);o.off("resize",g)}};return{scope:{anchor:"@",offset:"@",mediaQuery:"@",stickyClass:"@",bodyClass:"@"},restrict:"A",link:b}})}());