@@ -5,9 +5,11 @@ import {applyCssTransform} from '../../style/apply-transform';
5
5
import {
6
6
ConnectionPositionPair ,
7
7
OriginConnectionPosition ,
8
- OverlayConnectionPosition
8
+ OverlayConnectionPosition ,
9
+ ConnectedOverlayPositionChange
9
10
} from './connected-position' ;
10
-
11
+ import { Subject } from 'rxjs/Subject' ;
12
+ import { Observable } from 'rxjs/Observable' ;
11
13
12
14
/**
13
15
* A strategy for positioning overlays. Using this strategy, an overlay is given an
@@ -36,6 +38,13 @@ export class ConnectedPositionStrategy implements PositionStrategy {
36
38
/** The origin element against which the overlay will be positioned. */
37
39
private _origin : HTMLElement ;
38
40
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
+ }
39
48
40
49
constructor (
41
50
private _connectedTo : ElementRef ,
@@ -64,6 +73,7 @@ export class ConnectedPositionStrategy implements PositionStrategy {
64
73
// We use the viewport rect to determine whether a position would go off-screen.
65
74
const viewportRect = this . _viewportRuler . getViewportRect ( ) ;
66
75
let firstOverlayPoint : Point = null ;
76
+ let isFirstPosition = true ;
67
77
68
78
// We want to place the overlay in the first of the preferred positions such that the
69
79
// overlay fits on-screen.
@@ -77,8 +87,12 @@ export class ConnectedPositionStrategy implements PositionStrategy {
77
87
// If the overlay in the calculated position fits on-screen, put it there and we're done.
78
88
if ( this . _willOverlayFitWithinViewport ( overlayPoint , overlayRect , viewportRect ) ) {
79
89
this . _setElementPosition ( element , overlayPoint ) ;
90
+ if ( ! isFirstPosition ) {
91
+ this . _onPositionChange . next ( new ConnectedOverlayPositionChange ( pos ) ) ;
92
+ }
80
93
return Promise . resolve ( null ) ;
81
94
}
95
+ isFirstPosition = false ;
82
96
}
83
97
84
98
// TODO(jelbourn): fallback behavior for when none of the preferred positions fit on-screen.
0 commit comments