@@ -259,8 +259,6 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
259
259
} ;
260
260
261
261
//Modal focus behavior
262
- var focusableElementList ;
263
- var focusIndex = 0 ;
264
262
var tababbleSelector = 'a[href], area[href], input:not([disabled]), ' +
265
263
'button:not([disabled]),select:not([disabled]), textarea:not([disabled]), ' +
266
264
'iframe, object, embed, *[tabindex], *[contenteditable=true]' ;
@@ -391,22 +389,23 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
391
389
break ;
392
390
}
393
391
case 9 : {
394
- $modalStack . loadFocusElementList ( modal ) ;
392
+ var list = $modalStack . loadFocusElementList ( modal ) ;
395
393
var focusChanged = false ;
396
394
if ( evt . shiftKey ) {
397
- if ( $modalStack . isFocusInFirstItem ( evt ) || $modalStack . isModalFocused ( evt , modal ) ) {
398
- focusChanged = $modalStack . focusLastFocusableElement ( ) ;
395
+ if ( $modalStack . isFocusInFirstItem ( evt , list ) || $modalStack . isModalFocused ( evt , modal ) ) {
396
+ focusChanged = $modalStack . focusLastFocusableElement ( list ) ;
399
397
}
400
398
} else {
401
- if ( $modalStack . isFocusInLastItem ( evt ) ) {
402
- focusChanged = $modalStack . focusFirstFocusableElement ( ) ;
399
+ if ( $modalStack . isFocusInLastItem ( evt , list ) ) {
400
+ focusChanged = $modalStack . focusFirstFocusableElement ( list ) ;
403
401
}
404
402
}
405
403
406
404
if ( focusChanged ) {
407
405
evt . preventDefault ( ) ;
408
406
evt . stopPropagation ( ) ;
409
407
}
408
+
410
409
break ;
411
410
}
412
411
}
@@ -476,8 +475,6 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
476
475
477
476
openedWindows . top ( ) . value . modalDomEl = angularDomEl ;
478
477
openedWindows . top ( ) . value . modalOpener = modalOpener ;
479
-
480
- $modalStack . clearFocusListCache ( ) ;
481
478
} ;
482
479
483
480
function broadcastClosing ( modalWindow , resultOrReason , closing ) {
@@ -524,16 +521,17 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
524
521
}
525
522
} ;
526
523
527
- $modalStack . focusFirstFocusableElement = function ( ) {
528
- if ( focusableElementList . length > 0 ) {
529
- focusableElementList [ 0 ] . focus ( ) ;
524
+ $modalStack . focusFirstFocusableElement = function ( list ) {
525
+ if ( list . length > 0 ) {
526
+ list [ 0 ] . focus ( ) ;
530
527
return true ;
531
528
}
532
529
return false ;
533
530
} ;
534
- $modalStack . focusLastFocusableElement = function ( ) {
535
- if ( focusableElementList . length > 0 ) {
536
- focusableElementList [ focusableElementList . length - 1 ] . focus ( ) ;
531
+
532
+ $modalStack . focusLastFocusableElement = function ( list ) {
533
+ if ( list . length > 0 ) {
534
+ list [ list . length - 1 ] . focus ( ) ;
537
535
return true ;
538
536
}
539
537
return false ;
@@ -549,32 +547,25 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
549
547
return false ;
550
548
} ;
551
549
552
- $modalStack . isFocusInFirstItem = function ( evt ) {
553
- if ( focusableElementList . length > 0 ) {
554
- return ( evt . target || evt . srcElement ) === focusableElementList [ 0 ] ;
550
+ $modalStack . isFocusInFirstItem = function ( evt , list ) {
551
+ if ( list . length > 0 ) {
552
+ return ( evt . target || evt . srcElement ) === list [ 0 ] ;
555
553
}
556
554
return false ;
557
555
} ;
558
556
559
- $modalStack . isFocusInLastItem = function ( evt ) {
560
- if ( focusableElementList . length > 0 ) {
561
- return ( evt . target || evt . srcElement ) === focusableElementList [ focusableElementList . length - 1 ] ;
557
+ $modalStack . isFocusInLastItem = function ( evt , list ) {
558
+ if ( list . length > 0 ) {
559
+ return ( evt . target || evt . srcElement ) === list [ list . length - 1 ] ;
562
560
}
563
561
return false ;
564
562
} ;
565
563
566
- $modalStack . clearFocusListCache = function ( ) {
567
- focusableElementList = [ ] ;
568
- focusIndex = 0 ;
569
- } ;
570
-
571
564
$modalStack . loadFocusElementList = function ( modalWindow ) {
572
- if ( focusableElementList === undefined || ! focusableElementList . length ) {
573
- if ( modalWindow ) {
574
- var modalDomE1 = modalWindow . value . modalDomEl ;
575
- if ( modalDomE1 && modalDomE1 . length ) {
576
- focusableElementList = modalDomE1 [ 0 ] . querySelectorAll ( tababbleSelector ) ;
577
- }
565
+ if ( modalWindow ) {
566
+ var modalDomE1 = modalWindow . value . modalDomEl ;
567
+ if ( modalDomE1 && modalDomE1 . length ) {
568
+ return modalDomE1 [ 0 ] . querySelectorAll ( tababbleSelector ) ;
578
569
}
579
570
}
580
571
} ;
0 commit comments