@@ -636,24 +636,27 @@ angular
636636 * MdPanelAnimation *
637637 *****************************************************************************/
638638
639-
640639/**
641640 * @ngdoc type
642641 * @name MdPanelAnimation
642+ * @module material.components.panel
643643 * @description
644644 * Animation configuration object. To use, create an MdPanelAnimation with the
645645 * desired properties, then pass the object as part of $mdPanel creation.
646646 *
647- * Example:
647+ * @usage
648648 *
649+ * <hljs lang="js">
649650 * var panelAnimation = new MdPanelAnimation()
650651 * .openFrom(myButtonEl)
652+ * .duration(1337)
651653 * .closeTo('.my-button')
652654 * .withAnimation($mdPanel.animation.SCALE);
653655 *
654656 * $mdPanel.create({
655657 * animation: panelAnimation
656658 * });
659+ * </hljs>
657660 */
658661
659662/**
@@ -702,6 +705,18 @@ angular
702705 * @returns {!MdPanelAnimation }
703706 */
704707
708+ /**
709+ * @ngdoc method
710+ * @name MdPanelAnimation#duration
711+ * @description
712+ * Specifies the duration of the animation in milliseconds. The `duration`
713+ * method accepts either a number or an object with separate open and close
714+ * durations.
715+ *
716+ * @param {number|{open: number, close: number} } duration
717+ * @returns {!MdPanelAnimation }
718+ */
719+
705720
706721/*****************************************************************************
707722 * IMPLEMENTATION *
@@ -1466,13 +1481,19 @@ MdPanelRef.prototype._createBackdrop = function() {
14661481 open : '_md-opaque-enter' ,
14671482 close : '_md-opaque-leave'
14681483 } ) ;
1484+
1485+ if ( this . config . animation ) {
1486+ backdropAnimation . duration ( this . config . animation . _rawDuration ) ;
1487+ }
1488+
14691489 var backdropConfig = {
14701490 animation : backdropAnimation ,
14711491 attachTo : this . config . attachTo ,
14721492 focusOnOpen : false ,
14731493 panelClass : '_md-panel-backdrop' ,
14741494 zIndex : this . config . zIndex - 1
14751495 } ;
1496+
14761497 this . _backdropRef = this . _$mdPanel . create ( backdropConfig ) ;
14771498 }
14781499 if ( ! this . _backdropRef . isAttached ) {
@@ -1610,7 +1631,7 @@ MdPanelRef.prototype._configureScrollListener = function() {
16101631 * @private
16111632 */
16121633MdPanelRef . prototype . _configureTrapFocus = function ( ) {
1613- // Focus doesn't remain instead of the panel without this.
1634+ // Focus doesn't remain inside of the panel without this.
16141635 this . panelEl . attr ( 'tabIndex' , '-1' ) ;
16151636 if ( this . config [ 'trapFocus' ] ) {
16161637 var element = this . panelEl ;
@@ -2449,6 +2470,15 @@ function MdPanelAnimation($injector) {
24492470
24502471 /** @private {string|{open: string, close: string}} */
24512472 this . _animationClass = '' ;
2473+
2474+ /** @private {number} */
2475+ this . _openDuration ;
2476+
2477+ /** @private {number} */
2478+ this . _closeDuration ;
2479+
2480+ /** @private {number|{open: number, close: number}} */
2481+ this . _rawDuration ;
24522482}
24532483
24542484
@@ -2496,6 +2526,30 @@ MdPanelAnimation.prototype.closeTo = function(closeTo) {
24962526 return this ;
24972527} ;
24982528
2529+ /**
2530+ * Specifies the duration of the animation in milliseconds.
2531+ * @param {number|{open: number, close: number} } duration
2532+ * @returns {!MdPanelAnimation }
2533+ */
2534+ MdPanelAnimation . prototype . duration = function ( duration ) {
2535+ if ( duration ) {
2536+ if ( angular . isNumber ( duration ) ) {
2537+ this . _openDuration = this . _closeDuration = toSeconds ( duration ) ;
2538+ } else if ( angular . isObject ( duration ) ) {
2539+ this . _openDuration = toSeconds ( duration . open ) ;
2540+ this . _closeDuration = toSeconds ( duration . close ) ;
2541+ }
2542+ }
2543+
2544+ // Save the original value so it can be passed to the backdrop.
2545+ this . _rawDuration = duration ;
2546+
2547+ return this ;
2548+
2549+ function toSeconds ( value ) {
2550+ if ( angular . isNumber ( value ) ) return value / 1000 ;
2551+ }
2552+ } ;
24992553
25002554/**
25012555 * Returns the element and bounds for the animation target.
@@ -2598,6 +2652,8 @@ MdPanelAnimation.prototype.animateOpen = function(panelEl) {
25982652 }
25992653 }
26002654
2655+ animationOptions . duration = this . _openDuration ;
2656+
26012657 return animator
26022658 . translate3d ( panelEl , openFrom , openTo , animationOptions ) ;
26032659} ;
@@ -2661,6 +2717,8 @@ MdPanelAnimation.prototype.animateClose = function(panelEl) {
26612717 }
26622718 }
26632719
2720+ reverseAnimationOptions . duration = this . _closeDuration ;
2721+
26642722 return animator
26652723 . translate3d ( panelEl , closeFrom , closeTo , reverseAnimationOptions ) ;
26662724} ;
0 commit comments