blob: 3c3331c42a9539ada912dd887034517c1f1b4abd [file] [log] [blame]
/*!
* Angular Material Design
* https://github.com/angular/material
* @license MIT
* v1.0.0-master-19c11fd
*/
!function(t,e,n){"use strict";function r(t,r,o,i){function l(t){function e(t,e){e.addClass("md-sticky-clone");var n={element:t,clone:e};return v.items.push(n),i.nextTick(function(){m.prepend(n.clone)}),d(),function(){v.items.forEach(function(e,n){e.element[0]===t[0]&&(v.items.splice(n,1),e.clone.remove())}),d()}}function l(){v.items.forEach(c),v.items=v.items.sort(function(t,e){return t.top<e.top?-1:1});for(var t,e=m.prop("scrollTop"),n=v.items.length-1;n>=0;n--)if(e>v.items[n].top){t=v.items[n];break}u(t)}function c(t){var e=t.element[0];for(t.top=0,t.left=0;e&&e!==m[0];)t.top+=e.offsetTop,t.left+=e.offsetLeft,e=e.offsetParent;t.height=t.element.prop("offsetHeight"),t.clone.css("margin-left",t.left+"px"),i.floatingScrollbars()&&t.clone.css("margin-right","0")}function a(){var t=m.prop("scrollTop"),e=t>(a.prevScrollTop||0);if(a.prevScrollTop=t,0===t)return void u(null);if(e){if(v.next&&v.next.top<=t)return void u(v.next);if(v.current&&v.next&&v.next.top-t<=v.next.height)return void p(v.current,t+(v.next.top-v.next.height-t))}if(!e){if(v.current&&v.prev&&t<v.current.top)return void u(v.prev);if(v.next&&v.current&&t>=v.next.top-v.current.height)return void p(v.current,t+(v.next.top-t-v.current.height))}v.current&&p(v.current,t)}function u(t){if(v.current!==t){v.current&&(p(v.current,null),f(v.current,null)),t&&f(t,"active"),v.current=t;var e=v.items.indexOf(t);v.next=v.items[e+1],v.prev=v.items[e-1],f(v.next,"next"),f(v.prev,"prev")}}function f(t,e){t&&t.state!==e&&(t.state&&(t.clone.attr("sticky-prev-state",t.state),t.element.attr("sticky-prev-state",t.state)),t.clone.attr("sticky-state",e),t.element.attr("sticky-state",e),t.state=e)}function p(t,e){t&&(null===e||e===n?t.translateY&&(t.translateY=null,t.clone.css(r.CSS.TRANSFORM,"")):(t.translateY=e,t.clone.css(r.CSS.TRANSFORM,"translate3d("+t.left+"px,"+e+"px,0)")))}var m=t.$element,d=o.throttle(l);s(m),m.on("$scrollstart",d),m.on("$scroll",a);var v;return v={prev:null,current:null,next:null,items:[],add:e,refreshElements:l}}function c(n){var r,o=e.element("<div>");t[0].body.appendChild(o[0]);for(var i=["sticky","-webkit-sticky"],l=0;l<i.length;++l)if(o.css({position:i[l],top:0,"z-index":2}),o.css("position")==i[l]){r=i[l];break}return o.remove(),r}function s(t){function e(){+i.now()-r>l?(n=!1,t.triggerHandler("$scrollend")):(t.triggerHandler("$scroll"),o.throttle(e))}var n,r,l=200;t.on("scroll touchmove",function(){n||(n=!0,o.throttle(e),t.triggerHandler("$scrollstart")),t.triggerHandler("$scroll"),r=+i.now()})}var a=c();return function(t,e,n){var r=e.controller("mdContent");if(r)if(a)e.css({position:a,top:0,"z-index":2});else{var o=r.$element.data("$$sticky");o||(o=l(r),r.$element.data("$$sticky",o));var i=o.add(e,n||e.clone());t.$on("$destroy",i)}}}e.module("material.components.sticky",["material.core","material.components.content"]).factory("$mdSticky",r),r.$inject=["$document","$mdConstant","$$rAF","$mdUtil"]}(window,window.angular);