@@ -57,7 +57,7 @@ angular.module('ui.bootstrap.modal', [])
5757/**
5858 * A helper directive for the $modal service. It creates a backdrop element.
5959 */
60- . directive ( 'modalBackdrop' , [ '$modalStack' , '$ timeout', function ( $modalStack , $timeout ) {
60+ . directive ( 'modalBackdrop' , [ '$timeout' , function ( $timeout ) {
6161 return {
6262 restrict : 'EA' ,
6363 replace : true ,
@@ -70,20 +70,11 @@ angular.module('ui.bootstrap.modal', [])
7070 $timeout ( function ( ) {
7171 scope . animate = true ;
7272 } ) ;
73-
74- scope . close = function ( evt ) {
75- var modal = $modalStack . getTop ( ) ;
76- if ( modal && modal . value . backdrop && modal . value . backdrop != 'static' ) {
77- evt . preventDefault ( ) ;
78- evt . stopPropagation ( ) ;
79- $modalStack . dismiss ( modal . key , 'backdrop click' ) ;
80- }
81- } ;
8273 }
8374 } ;
8475 } ] )
8576
86- . directive ( 'modalWindow' , [ '$timeout' , function ( $timeout ) {
77+ . directive ( 'modalWindow' , [ '$modalStack' , '$ timeout', function ( $modalStack , $timeout ) {
8778 return {
8879 restrict : 'EA' ,
8980 scope : {
@@ -95,13 +86,21 @@ angular.module('ui.bootstrap.modal', [])
9586 link : function ( scope , element , attrs ) {
9687 scope . windowClass = attrs . windowClass || '' ;
9788
98- // focus a freshly-opened modal
99- element [ 0 ] . focus ( ) ;
100-
10189 $timeout ( function ( ) {
10290 // trigger CSS transitions
10391 scope . animate = true ;
92+ // focus a freshly-opened modal
93+ element [ 0 ] . focus ( ) ;
10494 } ) ;
95+
96+ scope . close = function ( evt ) {
97+ var modal = $modalStack . getTop ( ) ;
98+ if ( modal && modal . value . backdrop && modal . value . backdrop != 'static' && ( evt . target === evt . currentTarget ) ) {
99+ evt . preventDefault ( ) ;
100+ evt . stopPropagation ( ) ;
101+ $modalStack . dismiss ( modal . key , 'backdrop click' ) ;
102+ }
103+ } ;
105104 }
106105 } ;
107106 } ] )
@@ -195,9 +194,9 @@ angular.module('ui.bootstrap.modal', [])
195194 } ;
196195
197196 $modalStack . close = function ( modalInstance , result ) {
198- var modal = openedWindows . get ( modalInstance ) ;
199- if ( modal ) {
200- modal . value . deferred . resolve ( result ) ;
197+ var modalWindow = openedWindows . get ( modalInstance ) . value ;
198+ if ( modalWindow ) {
199+ modalWindow . deferred . resolve ( result ) ;
201200 removeModalWindow ( modalInstance ) ;
202201 }
203202 } ;
0 commit comments