@@ -552,6 +552,7 @@ function MdDialogDirective($$rAF, $mdTheming, $mdDialog) {
552
552
function MdDialogProvider ( $$interimElementProvider ) {
553
553
// Elements to capture and redirect focus when the user presses tab at the dialog boundary.
554
554
var topFocusTrap , bottomFocusTrap ;
555
+ var removeFocusTrap ;
555
556
556
557
return $$interimElementProvider ( '$mdDialog' )
557
558
. setDefaults ( {
@@ -641,9 +642,9 @@ function MdDialogProvider($$interimElementProvider) {
641
642
}
642
643
643
644
/* @ngInject */
644
- function dialogDefaultOptions ( $mdDialog , $mdAria , $mdUtil , $mdConstant , $animate , $document , $window , $rootElement ,
645
- $log , $injector , $mdTheming , $interpolate , $mdInteraction ) {
646
-
645
+ function dialogDefaultOptions ( $mdDialog , $mdAria , $mdUtil , $mdConstant , $animate , $document ,
646
+ $window , $rootElement , $ log, $injector , $mdTheming , $interpolate ,
647
+ $mdInteraction ) {
647
648
return {
648
649
hasBackdrop : true ,
649
650
isolateScope : true ,
@@ -768,12 +769,9 @@ function MdDialogProvider($$interimElementProvider) {
768
769
options . hideBackdrop ( options . $destroy ) ;
769
770
770
771
// Remove the focus traps that we added earlier for keeping focus within the dialog.
771
- if ( topFocusTrap && topFocusTrap . parentNode ) {
772
- topFocusTrap . parentNode . removeChild ( topFocusTrap ) ;
773
- }
774
-
775
- if ( bottomFocusTrap && bottomFocusTrap . parentNode ) {
776
- bottomFocusTrap . parentNode . removeChild ( bottomFocusTrap ) ;
772
+ if ( removeFocusTrap ) {
773
+ removeFocusTrap ( ) ;
774
+ removeFocusTrap = null ;
777
775
}
778
776
779
777
// For navigation $destroy events, do a quick, non-animated removal,
@@ -936,10 +934,8 @@ function MdDialogProvider($$interimElementProvider) {
936
934
937
935
// Queue remove listeners function
938
936
removeListeners . push ( function ( ) {
939
-
940
937
element . off ( 'keydown' , keyHandlerFn ) ;
941
938
parentTarget . off ( 'keydown' , keyHandlerFn ) ;
942
-
943
939
} ) ;
944
940
}
945
941
@@ -1015,11 +1011,13 @@ function MdDialogProvider($$interimElementProvider) {
1015
1011
*/
1016
1012
options . hideBackdrop = function hideBackdrop ( $destroy ) {
1017
1013
if ( options . backdrop ) {
1018
- if ( $destroy ) options . backdrop . remove ( ) ;
1019
- else $animate . leave ( options . backdrop ) ;
1014
+ if ( $destroy ) {
1015
+ options . backdrop . remove ( ) ;
1016
+ } else {
1017
+ $animate . leave ( options . backdrop ) ;
1018
+ }
1020
1019
}
1021
1020
1022
-
1023
1021
if ( options . disableParentScroll ) {
1024
1022
options . restoreScroll && options . restoreScroll ( ) ;
1025
1023
delete options . restoreScroll ;
@@ -1088,15 +1086,27 @@ function MdDialogProvider($$interimElementProvider) {
1088
1086
topFocusTrap . addEventListener ( 'focus' , focusHandler ) ;
1089
1087
bottomFocusTrap . addEventListener ( 'focus' , focusHandler ) ;
1090
1088
1091
- // The top focus trap inserted immeidately before the md-dialog element (as a sibling).
1089
+ removeFocusTrap = function ( ) {
1090
+ topFocusTrap . removeEventListener ( 'focus' , focusHandler ) ;
1091
+ bottomFocusTrap . removeEventListener ( 'focus' , focusHandler ) ;
1092
+
1093
+ if ( topFocusTrap && topFocusTrap . parentNode ) {
1094
+ topFocusTrap . parentNode . removeChild ( topFocusTrap ) ;
1095
+ }
1096
+
1097
+ if ( bottomFocusTrap && bottomFocusTrap . parentNode ) {
1098
+ bottomFocusTrap . parentNode . removeChild ( bottomFocusTrap ) ;
1099
+ }
1100
+ } ;
1101
+
1102
+ // The top focus trap inserted immediately before the md-dialog element (as a sibling).
1092
1103
// The bottom focus trap is inserted at the very end of the md-dialog element (as a child).
1093
1104
element [ 0 ] . parentNode . insertBefore ( topFocusTrap , element [ 0 ] ) ;
1094
1105
element . after ( bottomFocusTrap ) ;
1095
1106
}
1096
1107
1097
1108
/**
1098
- * Prevents screen reader interaction behind modal window
1099
- * on swipe interfaces
1109
+ * Prevents screen reader interaction behind modal window on swipe interfaces.
1100
1110
*/
1101
1111
function lockScreenReader ( element , options ) {
1102
1112
var isHidden = true ;
@@ -1112,8 +1122,9 @@ function MdDialogProvider($$interimElementProvider) {
1112
1122
} ;
1113
1123
1114
1124
/**
1115
- * Get all of an element's parent elements up the DOM tree
1116
- * @return {Array } The parent elements
1125
+ * Get all of an element's parent elements up the DOM tree.
1126
+ * @param {Node & ParentNode } element the element to start from
1127
+ * @return {Element[] } The parent elements
1117
1128
*/
1118
1129
function getParents ( element ) {
1119
1130
var parents = [ ] ;
@@ -1137,8 +1148,9 @@ function MdDialogProvider($$interimElementProvider) {
1137
1148
}
1138
1149
1139
1150
/**
1140
- * Walk DOM to apply or remove aria-hidden on sibling nodes
1141
- * and parent sibling nodes
1151
+ * Walk DOM to apply or remove aria-hidden on sibling nodes and parent sibling nodes.
1152
+ * @param {Element } element the element to start from when walking up the DOM
1153
+ * @returns {void }
1142
1154
*/
1143
1155
function walkDOM ( element ) {
1144
1156
var elements = getParents ( element ) ;
@@ -1149,12 +1161,17 @@ function MdDialogProvider($$interimElementProvider) {
1149
1161
}
1150
1162
1151
1163
/**
1152
- * Ensure the dialog container fill-stretches to the viewport
1164
+ * Ensure the dialog container fill-stretches to the viewport.
1165
+ * @param {JQLite } container dialog container
1166
+ * @param {Object } options
1167
+ * @returns {function(): void } function that reverts the modified styles
1153
1168
*/
1154
1169
function stretchDialogContainerToViewport ( container , options ) {
1155
1170
var isFixed = $window . getComputedStyle ( $document [ 0 ] . body ) . position === 'fixed' ;
1156
1171
var backdrop = options . backdrop ? $window . getComputedStyle ( options . backdrop [ 0 ] ) : null ;
1157
- var height = backdrop ? Math . min ( $document [ 0 ] . body . clientHeight , Math . ceil ( Math . abs ( parseInt ( backdrop . height , 10 ) ) ) ) : 0 ;
1172
+ var height = backdrop ?
1173
+ Math . min ( $document [ 0 ] . body . clientHeight , Math . ceil ( Math . abs ( parseInt ( backdrop . height , 10 ) ) ) )
1174
+ : 0 ;
1158
1175
1159
1176
var previousStyles = {
1160
1177
top : container . css ( 'top' ) ,
@@ -1178,7 +1195,10 @@ function MdDialogProvider($$interimElementProvider) {
1178
1195
}
1179
1196
1180
1197
/**
1181
- * Dialog open and pop-in animation
1198
+ * Dialog open and pop-in animation.
1199
+ * @param {JQLite } container dialog container
1200
+ * @param {Object } options
1201
+ * @returns {* }
1182
1202
*/
1183
1203
function dialogPopIn ( container , options ) {
1184
1204
// Add the `md-dialog-container` to the DOM
@@ -1219,7 +1239,6 @@ function MdDialogProvider($$interimElementProvider) {
1219
1239
buildTranslateToOrigin ( dialogEl , options . origin )
1220
1240
)
1221
1241
) ;
1222
-
1223
1242
} ;
1224
1243
1225
1244
// Function to revert the generated animation styles on the dialog element.
@@ -1243,7 +1262,10 @@ function MdDialogProvider($$interimElementProvider) {
1243
1262
}
1244
1263
1245
1264
/**
1246
- * Dialog close and pop-out animation
1265
+ * Dialog close and pop-out animation.
1266
+ * @param {JQLite } container dialog container
1267
+ * @param {Object } options
1268
+ * @returns {* }
1247
1269
*/
1248
1270
function dialogPopOut ( container , options ) {
1249
1271
return options . reverseAnimate ( ) . then ( function ( ) {
@@ -1256,13 +1278,13 @@ function MdDialogProvider($$interimElementProvider) {
1256
1278
}
1257
1279
1258
1280
/**
1259
- * Utility function to filter out raw DOM nodes
1281
+ * Utility function to filter out raw DOM nodes.
1282
+ * @param {Node } elem
1283
+ * @param {string[] } nodeTypeArray
1284
+ * @returns {boolean }
1260
1285
*/
1261
1286
function isNodeOneOf ( elem , nodeTypeArray ) {
1262
- if ( nodeTypeArray . indexOf ( elem . nodeName ) !== - 1 ) {
1263
- return true ;
1264
- }
1287
+ return nodeTypeArray . indexOf ( elem . nodeName ) !== - 1 ;
1265
1288
}
1266
-
1267
1289
}
1268
1290
}
0 commit comments