source: trip-planner-front/node_modules/@angular/cdk/esm2015/scrolling/scroll-dispatcher.js@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 21.3 KB
Line 
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 */
8import { coerceElement } from '@angular/cdk/coercion';
9import { Platform } from '@angular/cdk/platform';
10import { Injectable, NgZone, Optional, Inject } from '@angular/core';
11import { fromEvent, of as observableOf, Subject, Observable } from 'rxjs';
12import { auditTime, filter } from 'rxjs/operators';
13import { DOCUMENT } from '@angular/common';
14import * as i0 from "@angular/core";
15import * as i1 from "@angular/cdk/platform";
16import * as i2 from "@angular/common";
17/** Time in ms to throttle the scrolling events by default. */
18export const DEFAULT_SCROLL_TIME = 20;
19/**
20 * Service contained all registered Scrollable references and emits an event when any one of the
21 * Scrollable references emit a scrolled event.
22 */
23export class ScrollDispatcher {
24 constructor(_ngZone, _platform, document) {
25 this._ngZone = _ngZone;
26 this._platform = _platform;
27 /** Subject for notifying that a registered scrollable reference element has been scrolled. */
28 this._scrolled = new Subject();
29 /** Keeps track of the global `scroll` and `resize` subscriptions. */
30 this._globalSubscription = null;
31 /** Keeps track of the amount of subscriptions to `scrolled`. Used for cleaning up afterwards. */
32 this._scrolledCount = 0;
33 /**
34 * Map of all the scrollable references that are registered with the service and their
35 * scroll event subscriptions.
36 */
37 this.scrollContainers = new Map();
38 this._document = document;
39 }
40 /**
41 * Registers a scrollable instance with the service and listens for its scrolled events. When the
42 * scrollable is scrolled, the service emits the event to its scrolled observable.
43 * @param scrollable Scrollable instance to be registered.
44 */
45 register(scrollable) {
46 if (!this.scrollContainers.has(scrollable)) {
47 this.scrollContainers.set(scrollable, scrollable.elementScrolled()
48 .subscribe(() => this._scrolled.next(scrollable)));
49 }
50 }
51 /**
52 * Deregisters a Scrollable reference and unsubscribes from its scroll event observable.
53 * @param scrollable Scrollable instance to be deregistered.
54 */
55 deregister(scrollable) {
56 const scrollableReference = this.scrollContainers.get(scrollable);
57 if (scrollableReference) {
58 scrollableReference.unsubscribe();
59 this.scrollContainers.delete(scrollable);
60 }
61 }
62 /**
63 * Returns an observable that emits an event whenever any of the registered Scrollable
64 * references (or window, document, or body) fire a scrolled event. Can provide a time in ms
65 * to override the default "throttle" time.
66 *
67 * **Note:** in order to avoid hitting change detection for every scroll event,
68 * all of the events emitted from this stream will be run outside the Angular zone.
69 * If you need to update any data bindings as a result of a scroll event, you have
70 * to run the callback using `NgZone.run`.
71 */
72 scrolled(auditTimeInMs = DEFAULT_SCROLL_TIME) {
73 if (!this._platform.isBrowser) {
74 return observableOf();
75 }
76 return new Observable((observer) => {
77 if (!this._globalSubscription) {
78 this._addGlobalListener();
79 }
80 // In the case of a 0ms delay, use an observable without auditTime
81 // since it does add a perceptible delay in processing overhead.
82 const subscription = auditTimeInMs > 0 ?
83 this._scrolled.pipe(auditTime(auditTimeInMs)).subscribe(observer) :
84 this._scrolled.subscribe(observer);
85 this._scrolledCount++;
86 return () => {
87 subscription.unsubscribe();
88 this._scrolledCount--;
89 if (!this._scrolledCount) {
90 this._removeGlobalListener();
91 }
92 };
93 });
94 }
95 ngOnDestroy() {
96 this._removeGlobalListener();
97 this.scrollContainers.forEach((_, container) => this.deregister(container));
98 this._scrolled.complete();
99 }
100 /**
101 * Returns an observable that emits whenever any of the
102 * scrollable ancestors of an element are scrolled.
103 * @param elementOrElementRef Element whose ancestors to listen for.
104 * @param auditTimeInMs Time to throttle the scroll events.
105 */
106 ancestorScrolled(elementOrElementRef, auditTimeInMs) {
107 const ancestors = this.getAncestorScrollContainers(elementOrElementRef);
108 return this.scrolled(auditTimeInMs).pipe(filter(target => {
109 return !target || ancestors.indexOf(target) > -1;
110 }));
111 }
112 /** Returns all registered Scrollables that contain the provided element. */
113 getAncestorScrollContainers(elementOrElementRef) {
114 const scrollingContainers = [];
115 this.scrollContainers.forEach((_subscription, scrollable) => {
116 if (this._scrollableContainsElement(scrollable, elementOrElementRef)) {
117 scrollingContainers.push(scrollable);
118 }
119 });
120 return scrollingContainers;
121 }
122 /** Use defaultView of injected document if available or fallback to global window reference */
123 _getWindow() {
124 return this._document.defaultView || window;
125 }
126 /** Returns true if the element is contained within the provided Scrollable. */
127 _scrollableContainsElement(scrollable, elementOrElementRef) {
128 let element = coerceElement(elementOrElementRef);
129 let scrollableElement = scrollable.getElementRef().nativeElement;
130 // Traverse through the element parents until we reach null, checking if any of the elements
131 // are the scrollable's element.
132 do {
133 if (element == scrollableElement) {
134 return true;
135 }
136 } while (element = element.parentElement);
137 return false;
138 }
139 /** Sets up the global scroll listeners. */
140 _addGlobalListener() {
141 this._globalSubscription = this._ngZone.runOutsideAngular(() => {
142 const window = this._getWindow();
143 return fromEvent(window.document, 'scroll').subscribe(() => this._scrolled.next());
144 });
145 }
146 /** Cleans up the global scroll listener. */
147 _removeGlobalListener() {
148 if (this._globalSubscription) {
149 this._globalSubscription.unsubscribe();
150 this._globalSubscription = null;
151 }
152 }
153}
154ScrollDispatcher.ɵprov = i0.ɵɵdefineInjectable({ factory: function ScrollDispatcher_Factory() { return new ScrollDispatcher(i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i1.Platform), i0.ɵɵinject(i2.DOCUMENT, 8)); }, token: ScrollDispatcher, providedIn: "root" });
155ScrollDispatcher.decorators = [
156 { type: Injectable, args: [{ providedIn: 'root' },] }
157];
158ScrollDispatcher.ctorParameters = () => [
159 { type: NgZone },
160 { type: Platform },
161 { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] }
162];
163//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2Nyb2xsLWRpc3BhdGNoZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL3Njcm9sbGluZy9zY3JvbGwtZ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