3 * Copyright Google Inc. All Rights Reserved.
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
8 /* tslint:disable:array-type member-access variable-name typedef
9 only-arrow-functions directive-class-suffix component-class-suffix
11 import {Subscription} from 'rxjs/Subscription';
13 import {OverlayRef} from '../overlay-ref';
15 import {ScrollDispatcher} from './scroll-dispatcher';
16 import {getMdScrollStrategyAlreadyAttachedError, ScrollStrategy} from './scroll-strategy';
19 * Config options for the RepositionScrollStrategy.
21 export interface RepositionScrollStrategyConfig { scrollThrottle?: number; }
24 * Strategy that will update the element position as the user is scrolling.
26 export class RepositionScrollStrategy implements ScrollStrategy {
27 private _scrollSubscription: Subscription|null = null;
28 private _overlayRef: OverlayRef;
31 private _scrollDispatcher: ScrollDispatcher,
32 private _config?: RepositionScrollStrategyConfig) {}
34 attach(overlayRef: OverlayRef) {
35 if (this._overlayRef) {
36 throw getMdScrollStrategyAlreadyAttachedError();
39 this._overlayRef = overlayRef;
43 if (!this._scrollSubscription) {
44 const throttle = this._config ? this._config.scrollThrottle : 0;
46 this._scrollSubscription =
47 this._scrollDispatcher.scrolled(throttle, () => {
48 this._overlayRef.updatePosition();
54 if (this._scrollSubscription) {
55 this._scrollSubscription.unsubscribe();
56 this._scrollSubscription = null;