1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { Platform } from '@angular/cdk/platform';
|
---|
9 | import { ElementRef, NgZone, OnDestroy } from '@angular/core';
|
---|
10 | import { Subscription, Observable } from 'rxjs';
|
---|
11 | import { CdkScrollable } from './scrollable';
|
---|
12 | /** Time in ms to throttle the scrolling events by default. */
|
---|
13 | export declare const DEFAULT_SCROLL_TIME = 20;
|
---|
14 | /**
|
---|
15 | * Service contained all registered Scrollable references and emits an event when any one of the
|
---|
16 | * Scrollable references emit a scrolled event.
|
---|
17 | */
|
---|
18 | export declare class ScrollDispatcher implements OnDestroy {
|
---|
19 | private _ngZone;
|
---|
20 | private _platform;
|
---|
21 | /** Used to reference correct document/window */
|
---|
22 | protected _document: Document;
|
---|
23 | constructor(_ngZone: NgZone, _platform: Platform, document: any);
|
---|
24 | /** Subject for notifying that a registered scrollable reference element has been scrolled. */
|
---|
25 | private readonly _scrolled;
|
---|
26 | /** Keeps track of the global `scroll` and `resize` subscriptions. */
|
---|
27 | _globalSubscription: Subscription | null;
|
---|
28 | /** Keeps track of the amount of subscriptions to `scrolled`. Used for cleaning up afterwards. */
|
---|
29 | private _scrolledCount;
|
---|
30 | /**
|
---|
31 | * Map of all the scrollable references that are registered with the service and their
|
---|
32 | * scroll event subscriptions.
|
---|
33 | */
|
---|
34 | scrollContainers: Map<CdkScrollable, Subscription>;
|
---|
35 | /**
|
---|
36 | * Registers a scrollable instance with the service and listens for its scrolled events. When the
|
---|
37 | * scrollable is scrolled, the service emits the event to its scrolled observable.
|
---|
38 | * @param scrollable Scrollable instance to be registered.
|
---|
39 | */
|
---|
40 | register(scrollable: CdkScrollable): void;
|
---|
41 | /**
|
---|
42 | * Deregisters a Scrollable reference and unsubscribes from its scroll event observable.
|
---|
43 | * @param scrollable Scrollable instance to be deregistered.
|
---|
44 | */
|
---|
45 | deregister(scrollable: CdkScrollable): void;
|
---|
46 | /**
|
---|
47 | * Returns an observable that emits an event whenever any of the registered Scrollable
|
---|
48 | * references (or window, document, or body) fire a scrolled event. Can provide a time in ms
|
---|
49 | * to override the default "throttle" time.
|
---|
50 | *
|
---|
51 | * **Note:** in order to avoid hitting change detection for every scroll event,
|
---|
52 | * all of the events emitted from this stream will be run outside the Angular zone.
|
---|
53 | * If you need to update any data bindings as a result of a scroll event, you have
|
---|
54 | * to run the callback using `NgZone.run`.
|
---|
55 | */
|
---|
56 | scrolled(auditTimeInMs?: number): Observable<CdkScrollable | void>;
|
---|
57 | ngOnDestroy(): void;
|
---|
58 | /**
|
---|
59 | * Returns an observable that emits whenever any of the
|
---|
60 | * scrollable ancestors of an element are scrolled.
|
---|
61 | * @param elementOrElementRef Element whose ancestors to listen for.
|
---|
62 | * @param auditTimeInMs Time to throttle the scroll events.
|
---|
63 | */
|
---|
64 | ancestorScrolled(elementOrElementRef: ElementRef | HTMLElement, auditTimeInMs?: number): Observable<CdkScrollable | void>;
|
---|
65 | /** Returns all registered Scrollables that contain the provided element. */
|
---|
66 | getAncestorScrollContainers(elementOrElementRef: ElementRef | HTMLElement): CdkScrollable[];
|
---|
67 | /** Use defaultView of injected document if available or fallback to global window reference */
|
---|
68 | private _getWindow;
|
---|
69 | /** Returns true if the element is contained within the provided Scrollable. */
|
---|
70 | private _scrollableContainsElement;
|
---|
71 | /** Sets up the global scroll listeners. */
|
---|
72 | private _addGlobalListener;
|
---|
73 | /** Cleans up the global scroll listener. */
|
---|
74 | private _removeGlobalListener;
|
---|
75 | }
|
---|