/* * angular-sticky-plugin * https://github.com/harm-less/angular-sticky * Version: 0.4.2 - 2017-11-01 * License: MIT */ "use strict";angular.module("hl.sticky",[]).factory("mediaQuery",function(){return{matches:function(t){return t&&(matchMedia("("+t+")").matches||matchMedia(t).matches)}}}).factory("hlStickyStack",["$document","DefaultStickyStackName",function(t,n){var e=t[0].documentElement,o={};return function(t){var r=(t=t||{}).name||n;if(o[r])return o[r];var i=1039,a=[],c={};return c.options=t,c.stackName=r,c.add=function(t,n){return angular.isString(t)&&""!==t||(t=c.length()),n.id=t,n.zIndex=i,a.push(n),i-=1,n},c.get=function(t){for(var n=0;n=a()}function s(t){return(t=void 0!==t?t:window.pageYOffset||H.scrollTop)+window.innerHeight<=c()}function d(){return!1===M||r.matches(M)}function h(){var t=l(O);angular.isDefined(i.enable)&&!i.enable&&(t=!1),angular.isDefined(i.alwaysSticky)&&i.alwaysSticky&&(t=!0),t&&!z?(m(),Y({event:"stick"})):!t&&z&&(g(),Y({event:"unstick"})),z&&("top"===O?o.css("top",A+w(O)-x()+"px"):"bottom"===O&&o.css("bottom",N+w(O)-E()+"px"),o.css("width",y()+"px"))}function m(){z=!0,o.addClass(B),Q&&((D=D||angular.element("
")).css("height",p()+"px"),o.after(D));var t=P.getBoundingClientRect(),n={width:y()+"px",position:"fixed",left:t.left+"px","z-index":R?R.get(I).zIndex-(j.zIndex||0):null};n["margin-"+O]=0,o.css(n)}function g(){z=!1,o.removeClass(B),o.attr("style",q.style),D&&D.remove()}function y(){return P.offsetWidth}function p(){return P.offsetHeight}function v(t){var n=0;if(t&&t.offsetParent)do{n+=t.offsetTop,t=t.offsetParent}while(t);return n}function k(t){return v(t)+t.clientHeight}function w(t){var n=0;if("top"===t&&j.top>0&&(n+=j.top),"bottom"===t&&j.bottom>0&&(n+=j.bottom),R){var e=R.index(I);"top"===t&&e>0&&R.range(0,e).forEach(function(e){e.isSticky()&&(n+=e.computedHeight(t))}),"bottom"===t&&e!==R.length()-1&&R.range(e+1,R.length()).forEach(function(e){e.isSticky()&&(n+=e.computedHeight(t))})}return n}function S(){return w("top")}function b(){return w("bottom")}function E(t){if(null===L&&(L=void 0!==i.container&&(angular.isString(i.container)?angular.element(T.querySelector("#"+i.container))[0]:i.container)),L){var n=!(null===t||void 0===t),e=L.getBoundingClientRect(),o=n?v(L)+e.height-t:e.top-window.innerHeight+p();return Math.max(0,o-(A+w(O)))}return 0}function x(t){if(null===L&&(L=void 0!==i.container&&(angular.isString(i.container)?angular.element(T.querySelector("#"+i.container))[0]:i.container)),L){var n=!(null===t||void 0===t),e=L.getBoundingClientRect(),o=n?v(L)+e.height-t:e.bottom;return Math.max(0,A+w(O)+p()-o)}return 0}i=i||{};var $,C,D,z=!1,H=t[0].body,P=o[0],T=t[0].documentElement,I=i.id||null,M=!!angular.isDefined(i.mediaQuery)&&i.mediaQuery,B=angular.isString(i.stickyClass)&&""!==i.stickyClass?i.stickyClass:"is-sticky",Q=!angular.isDefined(i.usePlaceholder)||i.usePlaceholder,A=i.offsetTop?parseInt(i.offsetTop):0,N=i.offsetBottom?parseInt(i.offsetBottom):0,O="string"==typeof i.anchor?i.anchor.toLowerCase().trim():"top",L=null,R=!1===i.stack?null:i.stack||e(),Y=angular.isFunction(i.event)?i.event:angular.noop,j={top:0,bottom:0},q={style:o.attr("style")||""},F={};if(R){var U=R.add(I,F);I=U.id}return F.draw=function(t){var n=(t=t||{}).offset;n&&(j.top=n.top||0,j.bottom=n.bottom||0,j.zIndex=n.zIndex),!0===t.force&&g(),h()},F.anchor=function(){return O},F.isSticky=function(){return u()&&z||i.alwaysSticky},F.isEnabled=u,F.computedHeight=function(t,n){return"top"===t?Math.max(0,p()-x(n)+A):"bottom"===t?Math.max(0,p()-E(n)+N):0},F.sticksAtPosition=l,F.destroy=function(){g(),R&&R.remove(I)},F}}]).constant("DefaultStickyStackName","default-stack").provider("hlStickyElementCollection",function(){var t=0,n={collections:{},defaults:{checkDelay:250},elementsDefaults:{},$get:["$rootScope","$window","$document","$log","DefaultStickyStackName","hlStickyElement","hlStickyStack","throttle",function(e,o,r,i,a,c,u,l){function f(){++t>1||(p=l(h,n.defaults.checkDelay,{leading:!1}),v.on("resize",p),v.on("scroll",d),g=e.$on("$viewContentLoaded",p),y=e.$on("$includeContentLoaded",p),p())}function s(){--t>0||(v.off("resize",p),v.off("scroll",d),g(),y())}function d(){m()}function h(){m({force:!0})}function m(t){angular.forEach(n.collections,function(n){n.draw(t)})}var g,y,p,v=angular.element(o);return function(t){t&&angular.isObject(t)||(i.warn("Must supply an options object"),t={});var e=(t=angular.extend({},n.elementsDefaults,t)).name||a;if(n.collections[e])return n.collections[e];var o=u({name:e}),r=[],l={};return l.addElement=function(t,n){(n=n||{}).stack=o;var e=c(t,n);return r.push({stickyElement:e,element:t}),e},l.removeElement=function(t){for(var n,e=r.length;e--;)if(angular.isString(t)&&"#"+r[e].element.id===t||r[e].element===t){n=e;break}var o=r.splice(n,1)[0];return o&&o.stickyElement.destroy(),o},l.draw=function(n){var e={};if(t.parent){var o=u({name:t.parent});e.offset={top:o.heightCurrent("top"),zIndex:o.length()}}angular.extend(e,n||{}),angular.forEach(r,function(t){t.stickyElement.draw(e)})},l.destroy=function(){angular.forEach(angular.copy(r),function(t){l.removeElement(t)}),delete n.collections[e],s()},l.trackedElements=function(){return r},n.collections[e]=l,f(),l}}]};return n}).directive("hlSticky",["$log","$window","$document","hlStickyElementCollection",function(t,n,e,o){return{restrict:"A",scope:{container:"@",anchor:"@",stickyClass:"@",mediaQuery:"@",collection:"@",collectionParent:"@",event:"&",enable:"=",alwaysSticky:"="},link:function(t,n,e){n.addClass("hl-sticky");var r=o({name:t.collection,parent:t.collectionParent}),i={id:e.hlSticky,event:function(n){t.event({event:n})}};angular.forEach(["anchor","container","stickyClass","mediaQuery","enable","alwaysSticky"],function(n){angular.isDefined(t[n])&&(i[n]=t[n])}),angular.forEach(["usePlaceholder","offsetTop","offsetBottom"],function(n){angular.isDefined(e[n])&&(i[n]=t.$parent.$eval(e[n]))}),r.addElement(n,i),t.$watch("enable",function(n,e){n!==e&&(i.enable=t.enable,r.draw({force:!0}))}),t.$watch("alwaysSticky",function(n,e){n!==e&&(i.alwaysSticky=t.alwaysSticky,r.draw({force:!0}))}),t.$on("$destroy",function(){r.removeElement(n),r.trackedElements().length||r.destroy()})}}}]).factory("throttle",["$timeout",function(t){return function(n,e,o){var r=null;return o=o||{},function(){var i=this,a=arguments;r||(!1!==o.leading&&n.apply(i,a),r=t(function(){r=null,!1!==o.trailing&&n.apply(i,a)},e,!1))}}}]);