@@ -129,6 +129,12 @@ angular
129
129
* outside the panel to close it. Defaults to false.
130
130
* - `escapeToClose` - `{boolean=}`: Whether the user can press escape to
131
131
* close the panel. Defaults to false.
132
+ * - `onCloseSuccess` - `{function(!panelRef, string)=}`: Function that is
133
+ * called after the close successfully finishes. The first parameter passed
134
+ * into this function is the current panelRef and the 2nd is an optional
135
+ * string explaining the close reason. The currently supported closeReasons
136
+ * can be found in the MdPanelRef.closeReasons enum. These are by default
137
+ * passed along by the panel.
132
138
* - `trapFocus` - `{boolean=}`: Whether focus should be trapped within the
133
139
* panel. If `trapFocus` is true, the user will not be able to interact
134
140
* with the rest of the page until the panel is dismissed. Defaults to
@@ -870,6 +876,18 @@ function MdPanelService($rootElement, $rootScope, $injector, $window) {
870
876
* @type {enum }
871
877
*/
872
878
this . interceptorTypes = MdPanelRef . interceptorTypes ;
879
+
880
+ /**
881
+ * Possible values for closing of a panel.
882
+ * @type {enum }
883
+ */
884
+ this . closeReasons = MdPanelRef . closeReasons ;
885
+
886
+ /**
887
+ * Possible values of absolute position.
888
+ * @type {enum }
889
+ */
890
+ this . absPosition = MdPanelPosition . absPosition ;
873
891
}
874
892
875
893
@@ -1200,20 +1218,24 @@ MdPanelRef.prototype.open = function() {
1200
1218
1201
1219
/**
1202
1220
* Closes the panel.
1221
+ * @param {string } closeReason The event type that triggered the close.
1203
1222
* @returns {!angular.$q.Promise<!MdPanelRef> } A promise that is resolved when
1204
1223
* the panel is closed and animations finish.
1205
1224
*/
1206
- MdPanelRef . prototype . close = function ( ) {
1225
+ MdPanelRef . prototype . close = function ( closeReason ) {
1207
1226
var self = this ;
1208
1227
1209
1228
return this . _$q ( function ( resolve , reject ) {
1210
1229
self . _callInterceptors ( MdPanelRef . interceptorTypes . CLOSE ) . then ( function ( ) {
1211
1230
var done = self . _done ( resolve , self ) ;
1212
1231
var detach = self . _simpleBind ( self . detach , self ) ;
1232
+ var onCloseSuccess = self . config [ 'onCloseSuccess' ] || angular . noop ;
1233
+ onCloseSuccess = angular . bind ( self , onCloseSuccess , self , closeReason ) ;
1213
1234
1214
1235
self . hide ( )
1215
1236
. then ( detach )
1216
1237
. then ( done )
1238
+ . then ( onCloseSuccess )
1217
1239
. catch ( reject ) ;
1218
1240
} , reject ) ;
1219
1241
} ) ;
@@ -1802,7 +1824,7 @@ MdPanelRef.prototype._configureEscapeToClose = function() {
1802
1824
ev . stopPropagation ( ) ;
1803
1825
ev . preventDefault ( ) ;
1804
1826
1805
- self . close ( ) ;
1827
+ self . close ( MdPanelRef . closeReasons . ESCAPE ) ;
1806
1828
}
1807
1829
} ;
1808
1830
@@ -1845,7 +1867,7 @@ MdPanelRef.prototype._configureClickOutsideToClose = function() {
1845
1867
ev . stopPropagation ( ) ;
1846
1868
ev . preventDefault ( ) ;
1847
1869
1848
- self . close ( ) ;
1870
+ self . close ( MdPanelRef . closeReasons . CLICK_OUTSIDE ) ;
1849
1871
}
1850
1872
} ;
1851
1873
@@ -2154,6 +2176,14 @@ MdPanelRef.prototype.removeFromGroup = function(groupName) {
2154
2176
}
2155
2177
} ;
2156
2178
2179
+ /**
2180
+ * Possible default closeReasons for the close function.
2181
+ * @enum {string}
2182
+ */
2183
+ MdPanelRef . closeReasons = {
2184
+ CLICK_OUTSIDE : 'clickOutsideToClose' ,
2185
+ ESCAPE : 'escapeToClose' ,
2186
+ } ;
2157
2187
2158
2188
/*****************************************************************************
2159
2189
* MdPanelPosition *
0 commit comments