source: trip-planner-front/node_modules/@angular/cdk/esm2015/overlay/scroll/reposition-scroll-strategy.js

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

initial commit

  • Property mode set to 100644
File size: 9.0 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 { getMatScrollStrategyAlreadyAttachedError } from './scroll-strategy';
9import { isElementScrolledOutsideView } from '../position/scroll-clip';
10/**
11 * Strategy that will update the element position as the user is scrolling.
12 */
13export class RepositionScrollStrategy {
14 constructor(_scrollDispatcher, _viewportRuler, _ngZone, _config) {
15 this._scrollDispatcher = _scrollDispatcher;
16 this._viewportRuler = _viewportRuler;
17 this._ngZone = _ngZone;
18 this._config = _config;
19 this._scrollSubscription = null;
20 }
21 /** Attaches this scroll strategy to an overlay. */
22 attach(overlayRef) {
23 if (this._overlayRef && (typeof ngDevMode === 'undefined' || ngDevMode)) {
24 throw getMatScrollStrategyAlreadyAttachedError();
25 }
26 this._overlayRef = overlayRef;
27 }
28 /** Enables repositioning of the attached overlay on scroll. */
29 enable() {
30 if (!this._scrollSubscription) {
31 const throttle = this._config ? this._config.scrollThrottle : 0;
32 this._scrollSubscription = this._scrollDispatcher.scrolled(throttle).subscribe(() => {
33 this._overlayRef.updatePosition();
34 // TODO(crisbeto): make `close` on by default once all components can handle it.
35 if (this._config && this._config.autoClose) {
36 const overlayRect = this._overlayRef.overlayElement.getBoundingClientRect();
37 const { width, height } = this._viewportRuler.getViewportSize();
38 // TODO(crisbeto): include all ancestor scroll containers here once
39 // we have a way of exposing the trigger element to the scroll strategy.
40 const parentRects = [{ width, height, bottom: height, right: width, top: 0, left: 0 }];
41 if (isElementScrolledOutsideView(overlayRect, parentRects)) {
42 this.disable();
43 this._ngZone.run(() => this._overlayRef.detach());
44 }
45 }
46 });
47 }
48 }
49 /** Disables repositioning of the attached overlay on scroll. */
50 disable() {
51 if (this._scrollSubscription) {
52 this._scrollSubscription.unsubscribe();
53 this._scrollSubscription = null;
54 }
55 }
56 detach() {
57 this.disable();
58 this._overlayRef = null;
59 }
60}
61//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVwb3NpdGlvbi1zY3JvbGwtc3RyYXRlZ3kuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL292ZXJsYXkvc2Nyb2xsL3JlcG9zaXRpb24tc2Nyb2xsLXN0cmF0ZWd5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUlILE9BQU8sRUFBaUIsd0NBQXdDLEVBQUMsTUFBTSxtQkFBbUIsQ0FBQztBQUczRixPQUFPLEVBQUMsNEJBQTRCLEVBQUMsTUFBTSx5QkFBeUIsQ0FBQztBQWFyRTs7R0FFRztBQUNILE1BQU0sT0FBTyx3QkFBd0I7SUFJbkMsWUFDVSxpQkFBbUMsRUFDbkMsY0FBNkIsRUFDN0IsT0FBZSxFQUNmLE9BQXdDO1FBSHhDLHNCQUFpQixHQUFqQixpQkFBaUIsQ0FBa0I7UUFDbkMsbUJBQWMsR0FBZCxjQUFjLENBQWU7UUFDN0IsWUFBTyxHQUFQLE9BQU8sQ0FBUTtRQUNmLFlBQU8sR0FBUCxPQUFPLENBQWlDO1FBUDFDLHdCQUFtQixHQUFzQixJQUFJLENBQUM7SUFPQSxDQUFDO0lBRXZELG1EQUFtRDtJQUNuRCxNQUFNLENBQUMsVUFBNEI7UUFDakMsSUFBSSxJQUFJLENBQUMsV0FBVyxJQUFJLENBQUMsT0FBTyxTQUFTLEtBQUssV0FBVyxJQUFJLFNBQVMsQ0FBQyxFQUFFO1lBQ3ZFLE1BQU0sd0NBQXdDLEVBQUUsQ0FBQztTQUNsRDtRQUVELElBQUksQ0FBQyxXQUFXLEdBQUcsVUFBVSxDQUFDO0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mcgb2YgdGhlIGF0dGFjaGVkIG92ZXJsYXkgb24gc2Nyb2xsLiAqL1xuICBkaXNhYmxlKCkge1xuICAgIGlmICh0aGlzLl9zY3JvbGxTdWJzY3JpcHRpb24pIHtcbiAgICAgIHRoaXMuX3Njcm9sbFN1YnNjcmlwdGlvbi51bnN1YnNjcmliZSgpO1xuICAgICAgdGhpcy5fc2Nyb2xsU3Vic2NyaXB0aW9uID0gbnVsbDtcbiAgICB9XG4gIH1cblxuICBkZXRhY2goKSB7XG4gICAgdGhpcy5kaXNhYmxlKCk7XG4gICAgdGhpcy5fb3ZlcmxheVJlZiA9IG51bGwhO1xuICB9XG59XG4iXX0=
Note: See TracBrowser for help on using the repository browser.