@angular/cdk
Version:
Angular Material Component Development Kit
10 lines (9 loc) • 6.18 kB
JavaScript
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/cdk/platform"),require("@angular/core"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@angular/cdk/scrolling",["exports","@angular/cdk/platform","@angular/core","rxjs","rxjs/operators"],t):t((e.ng=e.ng||{},e.ng.cdk=e.ng.cdk||{},e.ng.cdk.scrolling={}),e.ng.cdk.platform,e.ng.core,e.rxjs,e.rxjs.operators)}(this,function(e,t,r,n,o){"use strict";function i(e,t,r){return e||new s(t,r)}function l(e,t,r){return e||new a(t,r)}var s=function(){function e(e,t){this._ngZone=e,this._platform=t,this._scrolled=new n.Subject,this._globalSubscription=null,this._scrolledCount=0,this.scrollContainers=new Map}return e.prototype.register=function(e){var t=this,r=e.elementScrolled().subscribe(function(){return t._scrolled.next(e)});this.scrollContainers.set(e,r)},e.prototype.deregister=function(e){var t=this.scrollContainers.get(e);t&&(t.unsubscribe(),this.scrollContainers.delete(e))},e.prototype.scrolled=function(e){var t=this;return void 0===e&&(e=20),this._platform.isBrowser?n.Observable.create(function(r){t._globalSubscription||t._addGlobalListener();var n=e>0?t._scrolled.pipe(o.auditTime(e)).subscribe(r):t._scrolled.subscribe(r);return t._scrolledCount++,function(){n.unsubscribe(),--t._scrolledCount||t._removeGlobalListener()}}):n.of()},e.prototype.ngOnDestroy=function(){var e=this;this._removeGlobalListener(),this.scrollContainers.forEach(function(t,r){return e.deregister(r)}),this._scrolled.complete()},e.prototype.ancestorScrolled=function(e,t){var r=this.getAncestorScrollContainers(e);return this.scrolled(t).pipe(o.filter(function(e){return!e||r.indexOf(e)>-1}))},e.prototype.getAncestorScrollContainers=function(e){var t=this,r=[];return this.scrollContainers.forEach(function(n,o){t._scrollableContainsElement(o,e)&&r.push(o)}),r},e.prototype._scrollableContainsElement=function(e,t){var r=t.nativeElement,n=e.getElementRef().nativeElement;do{if(r==n)return!0}while(r=r.parentElement);return!1},e.prototype._addGlobalListener=function(){var e=this;this._globalSubscription=this._ngZone.runOutsideAngular(function(){return n.fromEvent(window.document,"scroll").subscribe(function(){return e._scrolled.next()})})},e.prototype._removeGlobalListener=function(){this._globalSubscription&&(this._globalSubscription.unsubscribe(),this._globalSubscription=null)},e.decorators=[{type:r.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:r.NgZone},{type:t.Platform}]},e.ngInjectableDef=r.defineInjectable({factory:function(){return new e(r.inject(r.NgZone),r.inject(t.Platform))},token:e,providedIn:"root"}),e}(),c={provide:s,deps:[[new r.Optional,new r.SkipSelf,s],r.NgZone,t.Platform],useFactory:i},u=function(){function e(e,t,r){var o=this;this._elementRef=e,this._scroll=t,this._ngZone=r,this._elementScrolled=new n.Subject,this._scrollListener=function(e){return o._elementScrolled.next(e)}}return e.prototype.ngOnInit=function(){var e=this;this._ngZone.runOutsideAngular(function(){e.getElementRef().nativeElement.addEventListener("scroll",e._scrollListener)}),this._scroll.register(this)},e.prototype.ngOnDestroy=function(){this._scroll.deregister(this),this._scrollListener&&this.getElementRef().nativeElement.removeEventListener("scroll",this._scrollListener),this._elementScrolled.complete()},e.prototype.elementScrolled=function(){return this._elementScrolled.asObservable()},e.prototype.getElementRef=function(){return this._elementRef},e.decorators=[{type:r.Directive,args:[{selector:"[cdk-scrollable], [cdkScrollable]"}]}],e.ctorParameters=function(){return[{type:r.ElementRef},{type:s},{type:r.NgZone}]},e}(),a=function(){function e(e,t){var r=this;this._platform=e,this._change=e.isBrowser?t.runOutsideAngular(function(){return n.merge(n.fromEvent(window,"resize"),n.fromEvent(window,"orientationchange"))}):n.of(),this._invalidateCache=this.change().subscribe(function(){return r._updateViewportSize()})}return e.prototype.ngOnDestroy=function(){this._invalidateCache.unsubscribe()},e.prototype.getViewportSize=function(){this._viewportSize||this._updateViewportSize();var e={width:this._viewportSize.width,height:this._viewportSize.height};return this._platform.isBrowser||(this._viewportSize=null),e},e.prototype.getViewportRect=function(){var e=this.getViewportScrollPosition(),t=this.getViewportSize(),r=t.width,n=t.height;return{top:e.top,left:e.left,bottom:e.top+n,right:e.left+r,height:n,width:r}},e.prototype.getViewportScrollPosition=function(){if(!this._platform.isBrowser)return{top:0,left:0};var e=document.documentElement.getBoundingClientRect();return{top:-e.top||document.body.scrollTop||window.scrollY||document.documentElement.scrollTop||0,left:-e.left||document.body.scrollLeft||window.scrollX||document.documentElement.scrollLeft||0}},e.prototype.change=function(e){return void 0===e&&(e=20),e>0?this._change.pipe(o.auditTime(e)):this._change},e.prototype._updateViewportSize=function(){this._viewportSize=this._platform.isBrowser?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0}},e.decorators=[{type:r.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:t.Platform},{type:r.NgZone}]},e.ngInjectableDef=r.defineInjectable({factory:function(){return new e(r.inject(t.Platform),r.inject(r.NgZone))},token:e,providedIn:"root"}),e}(),p={provide:a,deps:[[new r.Optional,new r.SkipSelf,a],t.Platform,r.NgZone],useFactory:l},d=function(){function e(){}return e.decorators=[{type:r.NgModule,args:[{imports:[t.PlatformModule],exports:[u],declarations:[u]}]}],e}();e.DEFAULT_SCROLL_TIME=20,e.ScrollDispatcher=s,e.SCROLL_DISPATCHER_PROVIDER_FACTORY=i,e.SCROLL_DISPATCHER_PROVIDER=c,e.CdkScrollable=u,e.DEFAULT_RESIZE_TIME=20,e.ViewportRuler=a,e.VIEWPORT_RULER_PROVIDER_FACTORY=l,e.VIEWPORT_RULER_PROVIDER=p,e.ScrollDispatchModule=d,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=cdk-scrolling.umd.min.js.map