@@ -10,7 +10,7 @@ angular
10
10
. directive ( 'mdDialog' , MdDialogDirective )
11
11
. provider ( '$mdDialog' , MdDialogProvider ) ;
12
12
13
- function MdDialogDirective ( $$rAF , $mdTheming ) {
13
+ function MdDialogDirective ( $$rAF , $mdTheming , $mdDialog ) {
14
14
return {
15
15
restrict : 'E' ,
16
16
link : function ( scope , element , attr ) {
@@ -25,9 +25,19 @@ function MdDialogDirective($$rAF, $mdTheming) {
25
25
//-- delayed image loading may impact scroll height, check after images are loaded
26
26
angular . element ( images ) . on ( 'load' , addOverflowClass ) ;
27
27
}
28
+
29
+ scope . $on ( '$destroy' , function ( ) {
30
+ $mdDialog . destroy ( ) ;
31
+ } ) ;
32
+
33
+ /**
34
+ *
35
+ */
28
36
function addOverflowClass ( ) {
29
37
element . toggleClass ( 'md-content-overflow' , content . scrollHeight > content . clientHeight ) ;
30
38
}
39
+
40
+
31
41
} ) ;
32
42
}
33
43
} ;
@@ -530,16 +540,30 @@ function MdDialogProvider($$interimElementProvider) {
530
540
function onRemove ( scope , element , options ) {
531
541
options . deactivateListeners ( ) ;
532
542
options . unlockScreenReader ( ) ;
543
+ options . hideBackdrop ( options . $destroy ) ;
533
544
534
- options . hideBackdrop ( ) ;
545
+ // For navigation $destroy events, do a quick, non-animated removal,
546
+ // but for normal closes (from clicks, etc) animate the removal
535
547
536
- return dialogPopOut ( element , options )
537
- . finally ( function ( ) {
538
- angular . element ( $document [ 0 ] . body ) . removeClass ( 'md-dialog-is-showing' ) ;
539
- element . remove ( ) ;
548
+ return ! ! options . $destroy ? detachAndClean ( ) : animateRemoval ( ) . then ( detachAndClean ) ;
540
549
541
- options . origin . focus ( ) ;
542
- } ) ;
550
+ /**
551
+ * For normal closes, animate the removal.
552
+ * For forced closes (like $destroy events), skip the animations
553
+ */
554
+ function animateRemoval ( ) {
555
+ return dialogPopOut ( element , options ) ;
556
+ }
557
+
558
+ /**
559
+ * Detach the element
560
+ */
561
+ function detachAndClean ( ) {
562
+ angular . element ( $document [ 0 ] . body ) . removeClass ( 'md-dialog-is-showing' ) ;
563
+ element . remove ( ) ;
564
+
565
+ if ( ! options . $destroy ) options . origin . focus ( ) ;
566
+ }
543
567
}
544
568
545
569
/**
@@ -661,10 +685,12 @@ function MdDialogProvider($$interimElementProvider) {
661
685
/**
662
686
* Hide modal backdrop element...
663
687
*/
664
- options . hideBackdrop = function hideBackdrop ( ) {
688
+ options . hideBackdrop = function hideBackdrop ( $destroy ) {
665
689
if ( options . backdrop ) {
666
- $animate . leave ( options . backdrop ) ;
690
+ if ( ! ! $destroy ) options . backdrop . remove ( ) ;
691
+ else $animate . leave ( options . backdrop ) ;
667
692
}
693
+
668
694
if ( options . disableParentScroll ) {
669
695
options . restoreScroll ( ) ;
670
696
delete options . restoreScroll ;
@@ -755,7 +781,6 @@ function MdDialogProvider($$interimElementProvider) {
755
781
756
782
var isFixed = $window . getComputedStyle ( $document [ 0 ] . body ) . position == 'fixed' ;
757
783
var backdrop = options . backdrop ? $window . getComputedStyle ( options . backdrop [ 0 ] ) : null ;
758
-
759
784
var height = backdrop ? Math . min ( $document [ 0 ] . body . clientHeight , Math . ceil ( Math . abs ( parseInt ( backdrop . height , 10 ) ) ) ) : 0 ;
760
785
761
786
container . css ( {
0 commit comments