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

Commit 7cfef75

Browse files
committed
fix(panel): remove inline transforms after the close animation runs
- so that re-used panels don't accumulate transforms - improve type safety and JSDoc comments - remove unused variable and adjust code styles Fixes #11946
1 parent d7600f1 commit 7cfef75

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

Diff for: src/components/panel/panel.js

+28-31
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,7 @@ MdPanelRef.prototype.destroy = function() {
16311631
this.config.onDomRemoved = null;
16321632
this.config.onRemoving = null;
16331633
this.config.onOpenComplete = null;
1634-
this._interceptors = null;
1634+
this._interceptors = undefined;
16351635
};
16361636

16371637

@@ -1705,7 +1705,7 @@ MdPanelRef.prototype.hide = function() {
17051705
};
17061706
var removeFromGroupOpen = function() {
17071707
if (self.config.groupName) {
1708-
var group, index;
1708+
var index;
17091709
angular.forEach(self.config.groupName, function(group) {
17101710
group = self._$mdPanel._groups[group];
17111711
index = group.openPanels.indexOf(self);
@@ -2320,34 +2320,34 @@ MdPanelRef.prototype._animateOpen = function() {
23202320

23212321
/**
23222322
* Animate the panel closing.
2323-
* @returns {!Q.IPromise} A promise that is resolved when the panel has
2324-
* animated closed.
2323+
* @returns {!Q.IPromise} A promise that is resolved when the panel has animated closed.
23252324
* @private
23262325
*/
23272326
MdPanelRef.prototype._animateClose = function() {
2327+
var self = this;
23282328
var animationConfig = this.config['animation'];
2329+
23292330
if (!animationConfig) {
23302331
this.panelContainer.removeClass('md-panel-is-showing');
23312332
this.panelContainer.removeClass('_md-panel-shown');
23322333
return this._$q.when(this);
2333-
}
2334-
2335-
var self = this;
2336-
return this._$q(function(resolve) {
2337-
var done = function() {
2338-
self.panelContainer.removeClass('md-panel-is-showing');
2339-
resolve(self);
2340-
};
2341-
var warnAndClose = function() {
2342-
self._$log.warn(
2343-
'mdPanel: MdPanel Animations failed. ' +
2344-
'Hiding panel without animating.');
2345-
done();
2346-
};
2334+
} else {
2335+
return this._$q(function (resolve) {
2336+
var done = function () {
2337+
self.panelContainer.removeClass('md-panel-is-showing');
2338+
// Remove the transform so that re-used panels don't accumulate transforms.
2339+
self.panelEl.css('transform', '');
2340+
resolve(self);
2341+
};
2342+
var warnAndClose = function () {
2343+
self._$log.warn(
2344+
'mdPanel: MdPanel Animations failed. Hiding panel without animating.');
2345+
done();
2346+
};
23472347

2348-
animationConfig.animateClose(self.panelEl)
2349-
.then(done, warnAndClose);
2350-
});
2348+
animationConfig.animateClose(self.panelEl).then(done, warnAndClose);
2349+
});
2350+
}
23512351
};
23522352

23532353

@@ -2468,7 +2468,7 @@ MdPanelRef.prototype._simpleBind = function(callback, self) {
24682468

24692469

24702470
/**
2471-
* @param {function} callback
2471+
* @param {function|IQResolveReject} callback
24722472
* @param {!Object} self
24732473
* @return {function} Callback function with a self param.
24742474
*/
@@ -2883,7 +2883,7 @@ MdPanelPosition.prototype.getRight = function() {
28832883

28842884
/**
28852885
* Gets the value of `transform` for the panel.
2886-
* @returns {string}
2886+
* @returns {string} representation of the translateX and translateY rules and values
28872887
*/
28882888
MdPanelPosition.prototype.getTransform = function() {
28892889
var translateX = this._reduceTranslateValues('translateX', this._translateX);
@@ -3370,8 +3370,7 @@ MdPanelAnimation.prototype.animateOpen = function(panelEl) {
33703370
/**
33713371
* Animate the panel close.
33723372
* @param {!JQLite} panelEl
3373-
* @returns {!Q.IPromise} A promise that resolves when the close
3374-
* animation is complete.
3373+
* @returns {!Q.IPromise} A promise that resolves when the close animation is complete.
33753374
*/
33763375
MdPanelAnimation.prototype.animateClose = function(panelEl) {
33773376
var animator = this._$mdUtil.dom.animator;
@@ -3392,8 +3391,7 @@ MdPanelAnimation.prototype.animateClose = function(panelEl) {
33923391
transitionOutClass: '_md-panel-animate-enter _md-panel-animate-leave'
33933392
};
33943393

3395-
var closeSlide = animator.calculateSlideToOrigin(
3396-
panelEl, this._closeTo) || '';
3394+
var closeSlide = animator.calculateSlideToOrigin(panelEl, this._closeTo) || '';
33973395
closeTo = animator.toTransformCss(closeSlide + ' ' + panelTransform);
33983396
break;
33993397

@@ -3403,8 +3401,7 @@ MdPanelAnimation.prototype.animateClose = function(panelEl) {
34033401
transitionOutClass: '_md-panel-animate-scale-out _md-panel-animate-enter _md-panel-animate-leave'
34043402
};
34053403

3406-
var closeScale = animator.calculateZoomToOrigin(
3407-
panelEl, this._closeTo) || '';
3404+
var closeScale = animator.calculateZoomToOrigin(panelEl, this._closeTo) || '';
34083405
closeTo = animator.toTransformCss(panelTransform + ' ' + closeScale);
34093406
break;
34103407

@@ -3493,9 +3490,9 @@ function getElement(el) {
34933490

34943491
/**
34953492
* Gets the computed values for an element's translateX and translateY in px.
3496-
* @param {!JQLite|!Element} el
3493+
* @param {!JQLite|!Element} el the element to evaluate
34973494
* @param {string} property
3498-
* @return {{x: number, y: number}}
3495+
* @return {{x: number, y: number}} an element's translateX and translateY in px
34993496
*/
35003497
function getComputedTranslations(el, property) {
35013498
// The transform being returned by `getComputedStyle` is in the format:

Diff for: src/core/util/animation/animate.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function AnimateDomUtils($mdUtil, $q, $timeout, $mdConstant, $animateCss) {
2929
duration: options.duration
3030
})
3131
.start()
32-
.then(function(){
32+
.then(function() {
3333
// Resolve with reverser function...
3434
return reverseTranslate;
3535
});
@@ -199,6 +199,10 @@ function AnimateDomUtils($mdUtil, $q, $timeout, $mdConstant, $animateCss) {
199199

200200
/**
201201
* Convert the translate CSS value to key/value pair(s).
202+
* @param {string} transform
203+
* @param {boolean=} addTransition
204+
* @param {string=} transition
205+
* @return {Object} object containing CSS translate key/value pair(s)
202206
*/
203207
toTransformCss: function (transform, addTransition, transition) {
204208
var css = {};

Diff for: src/core/util/constant.js

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ function MdConstantFactory() {
1212
var isWebkit = /webkit/i.test(vendorPrefix);
1313
var SPECIAL_CHARS_REGEXP = /([:\-_]+(.))/g;
1414

15+
/**
16+
* @param {string} name CSS property name
17+
* @return {string} the property name supported by the browser
18+
*/
1519
function vendorProperty(name) {
1620
// Add a dash between the prefix and name, to be able to transform the string into camelcase.
1721
var prefixedName = vendorPrefix + '-' + name;
@@ -27,6 +31,10 @@ function MdConstantFactory() {
2731
return angular.isDefined(testElement.style[property]);
2832
}
2933

34+
/**
35+
* @param {!string} input value to convert to camelCase
36+
* @return {string} camelCased version of the input string
37+
*/
3038
function camelCase(input) {
3139
return input.replace(SPECIAL_CHARS_REGEXP, function(matches, separator, letter, offset) {
3240
return offset ? letter.toUpperCase() : letter;

0 commit comments

Comments
 (0)