Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit e552e56

Browse files
committed
feat(panel): Allows centering to be used with animation transforms.
1 parent 0a32577 commit e552e56

File tree

1 file changed

+48
-41
lines changed

1 file changed

+48
-41
lines changed

src/components/panel/panel.js

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,40 +1128,29 @@ MdPanelRef.prototype._createPanel = function() {
11281128

11291129
/**
11301130
* Adds the styles for the panel, such as positioning and z-index.
1131-
* @return {!angular.$q.Promise}
1131+
* @return {!angular.$q.Promise<MdPanelRef>}
11321132
* @private
11331133
*/
11341134
MdPanelRef.prototype._addStyles = function() {
1135-
this._panelContainer.css('z-index', this._config['zIndex']);
1136-
this._panelEl.css('z-index', this._config['zIndex'] + 1);
1137-
1138-
1139-
if (this._config['fullscreen']) {
1140-
this._panelEl.addClass('_md-panel-fullscreen');
1141-
return this._$q.resolve(this); // Don't setup positioning.
1142-
}
1143-
1144-
return this._configurePosition();
1145-
};
1146-
1147-
1148-
/**
1149-
* Configure the position of the panel.
1150-
* @return {!angular.$q.Promise}
1151-
* @private
1152-
*/
1153-
MdPanelRef.prototype._configurePosition = function() {
1154-
var positionConfig = this._config['position'];
1155-
if (!positionConfig) {
1156-
return this._$q.resolve(this);
1157-
}
1158-
11591135
var self = this;
11601136
return this._$q(function(resolve) {
1137+
self._panelContainer.css('z-index', self._config['zIndex']);
1138+
self._panelEl.css('z-index', self._config['zIndex'] + 1);
1139+
1140+
if (self._config['fullscreen']) {
1141+
self._panelEl.addClass('_md-panel-fullscreen');
1142+
return resolve(self); // Don't setup positioning.
1143+
}
1144+
1145+
var positionConfig = self._config['position'];
1146+
if (!positionConfig) {
1147+
return resolve(self); // Don't setup positioning.
1148+
}
1149+
11611150
// Wait for angular to finish processing the template, then position it
1162-
// correctly. This is necessary so that the panel will have a defined
1163-
// height and width.
1164-
return self._$rootScope['$$postDigest'](function () {
1151+
// correctly. This is necessary so that the panel will have a defined height
1152+
// and width.
1153+
self._$rootScope['$$postDigest'](function() {
11651154
self._panelEl.css('top', positionConfig.getTop(self._panelEl));
11661155
self._panelEl.css('bottom', positionConfig.getBottom(self._panelEl));
11671156
self._panelEl.css('left', positionConfig.getLeft(self._panelEl));
@@ -1171,7 +1160,7 @@ MdPanelRef.prototype._configurePosition = function() {
11711160
var prefixedTransform = self._$mdConstant.CSS.TRANSFORM;
11721161
self._panelEl.css(prefixedTransform, positionConfig.getTransform());
11731162

1174-
return resolve(self);
1163+
resolve(self);
11751164
});
11761165
});
11771166
};
@@ -1960,10 +1949,14 @@ MdPanelAnimation.prototype.animateOpen = function(panelEl, animator) {
19601949
this._fixBounds(panelEl);
19611950
var animationOptions = {};
19621951
var reverseAnimationOptions = {};
1963-
var openFrom = animator.toTransformCss("");
1964-
var openTo = animator.toTransformCss("");
1965-
var closeFrom = animator.toTransformCss("");
1966-
var closeTo = animator.toTransformCss("");
1952+
1953+
// Include the panel transformations when calculating the animations.
1954+
var panelTransform = panelEl[0].style.transform || '';
1955+
1956+
var openFrom = animator.toTransformCss(panelTransform);
1957+
var openTo = animator.toTransformCss(panelTransform);
1958+
var closeFrom = animator.toTransformCss(panelTransform);
1959+
var closeTo = animator.toTransformCss(panelTransform);
19671960

19681961
switch (this._animationClass) {
19691962
case MdPanelAnimation.animation.SLIDE:
@@ -1976,23 +1969,33 @@ MdPanelAnimation.prototype.animateOpen = function(panelEl, animator) {
19761969
reverseAnimationOptions = {
19771970
transitionInClass: '_md-panel-animate-leave'
19781971
};
1979-
openFrom = animator.toTransformCss(animator.calculateSlideToOrigin(
1980-
panelEl, this._openFrom) || "");
1981-
closeTo = animator.toTransformCss(animator.calculateSlideToOrigin(
1982-
panelEl, this._closeTo));
1972+
1973+
var openSlide = animator.calculateSlideToOrigin(
1974+
panelEl, this._openFrom) || '';
1975+
openFrom = animator.toTransformCss(openSlide + ' ' + panelTransform);
1976+
1977+
var closeSlide = animator.calculateSlideToOrigin(
1978+
panelEl, this._closeTo) || '';
1979+
closeTo = animator.toTransformCss(closeSlide + ' ' + panelTransform);
19831980
break;
1981+
19841982
case MdPanelAnimation.animation.SCALE:
19851983
animationOptions = {
19861984
transitionInClass: '_md-panel-animate-enter'
19871985
};
19881986
reverseAnimationOptions = {
19891987
transitionInClass: '_md-panel-animate-scale-out _md-panel-animate-leave'
19901988
};
1991-
openFrom = animator.toTransformCss(animator.calculateZoomToOrigin(
1992-
panelEl, this._openFrom) || "");
1993-
closeTo = animator.toTransformCss(animator.calculateZoomToOrigin(
1994-
panelEl, this._closeTo));
1989+
1990+
var openScale = animator.calculateZoomToOrigin(
1991+
panelEl, this._openFrom) || '';
1992+
openFrom = animator.toTransformCss(openScale + ' ' + panelTransform);
1993+
1994+
var closeScale = animator.calculateZoomToOrigin(
1995+
panelEl, this._closeTo) || '';
1996+
closeTo = animator.toTransformCss(closeScale + ' ' + panelTransform);
19951997
break;
1998+
19961999
case MdPanelAnimation.animation.FADE:
19972000
animationOptions = {
19982001
transitionInClass: '_md-panel-animate-enter'
@@ -2001,6 +2004,7 @@ MdPanelAnimation.prototype.animateOpen = function(panelEl, animator) {
20012004
transitionInClass: '_md-panel-animate-fade-out _md-panel-animate-leave'
20022005
};
20032006
break;
2007+
20042008
default:
20052009
if (angular.isString(this._animationClass)) {
20062010
animationOptions = {
@@ -2019,6 +2023,9 @@ MdPanelAnimation.prototype.animateOpen = function(panelEl, animator) {
20192023
transitionOutClass: this._animationClass['open']
20202024
};
20212025
}
2026+
2027+
// TODO(ErinCoughlan): Combine the user's custom transforms with the
2028+
// panel transform.
20222029
}
20232030

20242031
var self = this;

0 commit comments

Comments
 (0)