@@ -131,6 +131,17 @@ angular
131
131
* behind the panel. Defaults to false.
132
132
* - `disableParentScroll` - `{boolean=}`: Whether the user can scroll the
133
133
* page behind the panel. Defaults to false.
134
+ * - `onDomAdded` - `{function=}`: Callback function used to announce when
135
+ * the panel is added to the DOM.
136
+ * - `onOpenComplete` - `{function=}`: Callback function used to announce
137
+ * when the open() action is finished.
138
+ * - `onRemoving` - `{function=}`: Callback function used to announce the
139
+ * close/hide() action is starting.
140
+ * - `onDomRemoved` - `{function=}`: Callback function used to announce when the
141
+ * panel is removed from the DOM.
142
+ * - `origin` - `{(string|!angular.JQLite|!Element)=}`: The element to
143
+ * focus on when the panel closes. This is commonly the element which triggered
144
+ * the opening of the panel.
134
145
*
135
146
* TODO(ErinCoughlan): Add the following config options.
136
147
* - `groupName` - `{string=}`: Name of panel groups. This group name is
@@ -212,15 +223,6 @@ angular
212
223
* create.
213
224
* - `isAttached` - `{boolean}`: Whether the panel is attached to the DOM.
214
225
* Visibility to the user does not factor into isAttached.
215
- *
216
- * TODO(ErinCoughlan): Add the following properties.
217
- * - `onDomAdded` - `{function=}`: Callback function used to announce when
218
- * the panel is added to the DOM.
219
- * - `onOpenComplete` - `{function=}`: Callback function used to announce
220
- * when the open() action is finished.
221
- * - `onRemoving` - `{function=}`: Callback function used to announce the
222
- * close/hide() action is starting. This allows developers to run custom
223
- * animations in parallel the close animations.
224
226
*/
225
227
226
228
/**
@@ -237,8 +239,7 @@ angular
237
239
* @ngdoc method
238
240
* @name MdPanelRef#close
239
241
* @description
240
- * Hides and detaches the panel. This method destroys the reference to the panel.
241
- * In order to open the panel again, a new one must be created.
242
+ * Hides and detaches the panel.
242
243
*
243
244
* @returns {!angular.$q.Promise } A promise that is resolved when the panel is
244
245
* closed.
@@ -725,6 +726,7 @@ MdPanelService.prototype._wrapTemplate = function(origTemplate) {
725
726
'</div>' ;
726
727
} ;
727
728
729
+
728
730
/*****************************************************************************
729
731
* MdPanelRef *
730
732
*****************************************************************************/
@@ -779,7 +781,6 @@ function MdPanelRef(config, $injector) {
779
781
*/
780
782
this . isAttached = false ;
781
783
782
-
783
784
// Private variables.
784
785
/** @private {!Object} */
785
786
this . _config = config ;
@@ -821,8 +822,9 @@ MdPanelRef.prototype.open = function() {
821
822
var show = self . _simpleBind ( self . show , self ) ;
822
823
823
824
self . attach ( )
824
- . then ( show , reject )
825
- . then ( done , reject ) ;
825
+ . then ( show )
826
+ . then ( done )
827
+ . catch ( reject ) ;
826
828
} ) ;
827
829
} ;
828
830
@@ -835,13 +837,15 @@ MdPanelRef.prototype.open = function() {
835
837
*/
836
838
MdPanelRef . prototype . close = function ( ) {
837
839
var self = this ;
840
+
838
841
return this . _$q ( function ( resolve , reject ) {
839
842
var done = self . _done ( resolve , self ) ;
840
843
var detach = self . _simpleBind ( self . detach , self ) ;
841
844
842
845
self . hide ( )
843
- . then ( detach , reject )
844
- . then ( done , reject ) ;
846
+ . then ( detach )
847
+ . then ( done )
848
+ . catch ( reject ) ;
845
849
} ) ;
846
850
} ;
847
851
@@ -860,14 +864,21 @@ MdPanelRef.prototype.attach = function() {
860
864
var self = this ;
861
865
return this . _$q ( function ( resolve , reject ) {
862
866
var done = self . _done ( resolve , self ) ;
863
-
864
- self . _$q . all ( [
865
- self . _createBackdrop ( ) ,
866
- self . _createPanel ( ) . then ( function ( ) {
867
+ var onDomAdded = self . _config [ 'onDomAdded' ] || angular . noop ;
868
+ var addListeners = function ( response ) {
867
869
self . isAttached = true ;
868
870
self . _addEventListeners ( ) ;
869
- } , reject )
870
- ] ) . then ( done , reject ) ;
871
+ return response ;
872
+ } ;
873
+
874
+ self . _$q . all ( [
875
+ self . _createBackdrop ( ) ,
876
+ self . _createPanel ( )
877
+ . then ( addListeners )
878
+ . catch ( reject )
879
+ ] ) . then ( onDomAdded )
880
+ . then ( done )
881
+ . catch ( reject ) ;
871
882
} ) ;
872
883
} ;
873
884
@@ -884,8 +895,10 @@ MdPanelRef.prototype.detach = function() {
884
895
}
885
896
886
897
var self = this ;
898
+ var onDomRemoved = self . _config [ 'onDomRemoved' ] || angular . noop ;
899
+
887
900
var detachFn = function ( ) {
888
- self . _removeEventListener ( ) ;
901
+ self . _removeEventListeners ( ) ;
889
902
890
903
// Remove the focus traps that we added earlier for keeping focus within
891
904
// the panel.
@@ -913,11 +926,21 @@ MdPanelRef.prototype.detach = function() {
913
926
self . _$q . all ( [
914
927
detachFn ( ) ,
915
928
self . _backdropRef ? self . _backdropRef . detach ( ) : true
916
- ] ) . then ( done , reject ) ;
929
+ ] ) . then ( onDomRemoved )
930
+ . then ( done )
931
+ . catch ( reject ) ;
917
932
} ) ;
918
933
} ;
919
934
920
935
936
+ /**
937
+ * Destroys the panel. The Panel cannot be opened again after this.
938
+ */
939
+ MdPanelRef . prototype . destroy = function ( ) {
940
+ this . _config . locals = null ;
941
+ } ;
942
+
943
+
921
944
/**
922
945
* Shows the panel.
923
946
*
@@ -943,11 +966,14 @@ MdPanelRef.prototype.show = function() {
943
966
944
967
return this . _$q ( function ( resolve , reject ) {
945
968
var done = self . _done ( resolve , self ) ;
969
+ var onOpenComplete = self . _config [ 'onOpenComplete' ] || angular . noop ;
946
970
947
971
self . _$q . all ( [
948
972
self . _backdropRef ? self . _backdropRef . show ( ) : self ,
949
973
animatePromise ( ) . then ( function ( ) { self . _focusOnOpen ( ) ; } , reject )
950
- ] ) . then ( done , reject ) ;
974
+ ] ) . then ( onOpenComplete )
975
+ . then ( done )
976
+ . catch ( reject ) ;
951
977
} ) ;
952
978
} ;
953
979
@@ -970,13 +996,29 @@ MdPanelRef.prototype.hide = function() {
970
996
}
971
997
972
998
var self = this ;
999
+
973
1000
return this . _$q ( function ( resolve , reject ) {
974
1001
var done = self . _done ( resolve , self ) ;
1002
+ var onRemoving = self . _config [ 'onRemoving' ] || angular . noop ;
1003
+
1004
+ var focusOnOrigin = function ( ) {
1005
+ var origin = self . _config [ 'origin' ] ;
1006
+ if ( origin ) {
1007
+ getElement ( origin ) . focus ( ) ;
1008
+ }
1009
+ } ;
1010
+
1011
+ var hidePanel = function ( ) {
1012
+ self . addClass ( MD_PANEL_HIDDEN ) ;
1013
+ } ;
975
1014
976
1015
self . _$q . all ( [
977
1016
self . _backdropRef ? self . _backdropRef . hide ( ) : self ,
978
- self . _animateClose ( ) . then ( function ( ) { self . addClass ( MD_PANEL_HIDDEN ) ; } ,
979
- reject )
1017
+ self . _animateClose ( )
1018
+ . then ( onRemoving )
1019
+ . then ( hidePanel )
1020
+ . then ( focusOnOrigin )
1021
+ . catch ( reject )
980
1022
] ) . then ( done , reject ) ;
981
1023
} ) ;
982
1024
} ;
@@ -1037,10 +1079,12 @@ MdPanelRef.prototype.toggleClass = function(toggleClass) {
1037
1079
*/
1038
1080
MdPanelRef . prototype . _createPanel = function ( ) {
1039
1081
var self = this ;
1082
+
1040
1083
return this . _$q ( function ( resolve , reject ) {
1041
1084
if ( ! self . _config . locals ) {
1042
1085
self . _config . locals = { } ;
1043
1086
}
1087
+
1044
1088
self . _config . locals . mdPanelRef = self ;
1045
1089
self . _$mdCompiler . compile ( self . _config )
1046
1090
. then ( function ( compileData ) {
@@ -1184,7 +1228,7 @@ MdPanelRef.prototype._addEventListeners = function() {
1184
1228
* Remove event listeners added in _addEventListeners.
1185
1229
* @private
1186
1230
*/
1187
- MdPanelRef . prototype . _removeEventListener = function ( ) {
1231
+ MdPanelRef . prototype . _removeEventListeners = function ( ) {
1188
1232
this . _removeListeners && this . _removeListeners . forEach ( function ( removeFn ) {
1189
1233
removeFn ( ) ;
1190
1234
} ) ;
@@ -1289,6 +1333,12 @@ MdPanelRef.prototype._configureTrapFocus = function() {
1289
1333
this . _topFocusTrap . addEventListener ( 'focus' , focusHandler ) ;
1290
1334
this . _bottomFocusTrap . addEventListener ( 'focus' , focusHandler ) ;
1291
1335
1336
+ // Queue remove listeners function
1337
+ this . _removeListeners . push ( this . _simpleBind ( function ( ) {
1338
+ this . _topFocusTrap . removeEventListener ( 'focus' , focusHandler ) ;
1339
+ this . _bottomFocusTrap . removeEventListener ( 'focus' , focusHandler ) ;
1340
+ } , this ) ) ;
1341
+
1292
1342
// The top focus trap inserted immediately before the md-panel element (as
1293
1343
// a sibling). The bottom focus trap inserted immediately after the
1294
1344
// md-panel element (as a sibling).
0 commit comments