@@ -5,9 +5,11 @@ import {applyCssTransform} from '../../style/apply-transform';
55import {
66 ConnectionPositionPair ,
77 OriginConnectionPosition ,
8- OverlayConnectionPosition
8+ OverlayConnectionPosition ,
9+ ConnectedOverlayPositionChange
910} from './connected-position' ;
10-
11+ import { Subject } from 'rxjs/Subject' ;
12+ import { Observable } from 'rxjs/Observable' ;
1113
1214/**
1315 * A strategy for positioning overlays. Using this strategy, an overlay is given an
@@ -36,6 +38,13 @@ export class ConnectedPositionStrategy implements PositionStrategy {
3638 /** The origin element against which the overlay will be positioned. */
3739 private _origin : HTMLElement ;
3840
41+ private _onPositionChange :
42+ Subject < ConnectedOverlayPositionChange > = new Subject < ConnectedOverlayPositionChange > ( ) ;
43+
44+ /** Emits an event when the connection point changes. */
45+ get onPositionChange ( ) : Observable < ConnectedOverlayPositionChange > {
46+ return this . _onPositionChange . asObservable ( ) ;
47+ }
3948
4049 constructor (
4150 private _connectedTo : ElementRef ,
@@ -64,6 +73,7 @@ export class ConnectedPositionStrategy implements PositionStrategy {
6473 // We use the viewport rect to determine whether a position would go off-screen.
6574 const viewportRect = this . _viewportRuler . getViewportRect ( ) ;
6675 let firstOverlayPoint : Point = null ;
76+ let isFirstPosition = true ;
6777
6878 // We want to place the overlay in the first of the preferred positions such that the
6979 // overlay fits on-screen.
@@ -77,8 +87,12 @@ export class ConnectedPositionStrategy implements PositionStrategy {
7787 // If the overlay in the calculated position fits on-screen, put it there and we're done.
7888 if ( this . _willOverlayFitWithinViewport ( overlayPoint , overlayRect , viewportRect ) ) {
7989 this . _setElementPosition ( element , overlayPoint ) ;
90+ if ( ! isFirstPosition ) {
91+ this . _onPositionChange . next ( new ConnectedOverlayPositionChange ( pos ) ) ;
92+ }
8093 return Promise . resolve ( null ) ;
8194 }
95+ isFirstPosition = false ;
8296 }
8397
8498 // TODO(jelbourn): fallback behavior for when none of the preferred positions fit on-screen.
0 commit comments