@@ -492,7 +492,7 @@ function(SERVICES, COMPONENTS, DEMOS, PAGES, $location, $rootScope, $http, $wind
492
492
} ;
493
493
} )
494
494
495
- . directive ( 'menuToggle' , [ '$timeout ' , '$mdUtil ' , function ( $timeout , $mdUtil ) {
495
+ . directive ( 'menuToggle' , [ '$mdUtil' , '$animateCss ' , '$$rAF ' , function ( $mdUtil , $animateCss , $$rAF ) {
496
496
return {
497
497
scope : {
498
498
section : '='
@@ -501,59 +501,56 @@ function(SERVICES, COMPONENTS, DEMOS, PAGES, $location, $rootScope, $http, $wind
501
501
link : function ( $scope , $element ) {
502
502
var controller = $element . parent ( ) . controller ( ) ;
503
503
504
+ // Used for toggling the visibility of the accordion's content, after
505
+ // all of the animations are completed. This prevents users from being
506
+ // allowed to tab through to the hidden content.
507
+ $scope . renderContent = false ;
508
+
504
509
$scope . isOpen = function ( ) {
505
510
return controller . isOpen ( $scope . section ) ;
506
511
} ;
512
+
507
513
$scope . toggle = function ( ) {
508
514
controller . toggleOpen ( $scope . section ) ;
509
515
} ;
510
516
511
517
$mdUtil . nextTick ( function ( ) {
512
- $scope . $watch (
513
- function ( ) {
514
- return controller . isOpen ( $scope . section ) ;
515
- } ,
516
- function ( open ) {
517
- // We must run this in a next tick so that the getTargetHeight function is correct
518
- $mdUtil . nextTick ( function ( ) {
519
- var $ul = $element . find ( 'ul' ) ;
518
+ $scope . $watch ( function ( ) {
519
+ return controller . isOpen ( $scope . section ) ;
520
+ } , function ( open ) {
521
+ var $ul = $element . find ( 'ul' ) ;
522
+ var $li = $ul [ 0 ] . querySelector ( 'a.active' ) ;
523
+
524
+ if ( open ) {
525
+ $scope . renderContent = true ;
526
+ }
527
+
528
+ $$rAF ( function ( ) {
529
+ var targetHeight = open ? $ul [ 0 ] . scrollHeight : 0 ;
530
+
531
+ $animateCss ( $ul , {
532
+ easing : 'cubic-bezier(0.35, 0, 0.25, 1)' ,
533
+ to : { height : targetHeight + 'px' } ,
534
+ duration : 0.75 // seconds
535
+ } ) . start ( ) . then ( function ( ) {
520
536
var $li = $ul [ 0 ] . querySelector ( 'a.active' ) ;
521
- var docsMenuContent = document . querySelector ( '.docs-menu' ) . parentNode ;
522
- var targetHeight = open ? getTargetHeight ( ) : 0 ;
523
-
524
- $timeout ( function ( ) {
525
- // Set the height of the list
526
- $ul . css ( { height : targetHeight + 'px' } ) ;
527
-
528
- // If we are open and the user has not scrolled the content div; scroll the active
529
- // list item into view.
530
- if ( open && $li && $li . offsetParent && $ul [ 0 ] . scrollTop === 0 ) {
531
- $timeout ( function ( ) {
532
- var activeHeight = $li . scrollHeight ;
533
- var activeOffset = $li . offsetTop ;
534
- var parentOffset = $li . offsetParent . offsetTop ;
535
-
536
- // Reduce it a bit (2 list items' height worth) so it doesn't touch the nav
537
- var negativeOffset = activeHeight * 2 ;
538
- var newScrollTop = activeOffset + parentOffset - negativeOffset ;
539
-
540
- $mdUtil . animateScrollTo ( docsMenuContent , newScrollTop ) ;
541
- } , 350 , false ) ;
542
- }
543
- } , 0 , false ) ;
544
-
545
- function getTargetHeight ( ) {
546
- var targetHeight ;
547
- $ul . addClass ( 'no-transition' ) ;
548
- $ul . css ( 'height' , '' ) ;
549
- targetHeight = $ul . prop ( 'clientHeight' ) ;
550
- $ul . css ( 'height' , 0 ) ;
551
- $ul . removeClass ( 'no-transition' ) ;
552
- return targetHeight ;
537
+
538
+ $scope . renderContent = open ;
539
+
540
+ if ( open && $li && $ul [ 0 ] . scrollTop === 0 ) {
541
+ var activeHeight = $li . scrollHeight ;
542
+ var activeOffset = $li . offsetTop ;
543
+ var parentOffset = $li . offsetParent . offsetTop ;
544
+
545
+ // Reduce it a bit (2 list items' height worth) so it doesn't touch the nav
546
+ var negativeOffset = activeHeight * 2 ;
547
+ var newScrollTop = activeOffset + parentOffset - negativeOffset ;
548
+
549
+ $mdUtil . animateScrollTo ( document . querySelector ( '.docs-menu' ) . parentNode , newScrollTop ) ;
553
550
}
554
- } , false ) ;
555
- }
556
- ) ;
551
+ } ) ;
552
+ } ) ;
553
+ } ) ;
557
554
} ) ;
558
555
559
556
var parentNode = $element [ 0 ] . parentNode . parentNode . parentNode ;
0 commit comments