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';
20 * Strategy that will close the overlay as soon as the user starts scrolling.
22 export class CloseScrollStrategy implements ScrollStrategy {
23 private _scrollSubscription: Subscription|null = null;
24 private _overlayRef: OverlayRef;
26 constructor(private _scrollDispatcher: ScrollDispatcher) {}
28 attach(overlayRef: OverlayRef) {
29 if (this._overlayRef) {
30 throw getMdScrollStrategyAlreadyAttachedError();
33 this._overlayRef = overlayRef;
37 if (!this._scrollSubscription) {
38 this._scrollSubscription = this._scrollDispatcher.scrolled(0, () => {
39 if (this._overlayRef.hasAttached()) {
40 this._overlayRef.detach();
49 if (this._scrollSubscription) {
50 this._scrollSubscription.unsubscribe();
51 this._scrollSubscription = null;