This repository was archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(progressLinear): sync logic, perf upgrades, fix animations #4454
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,13 @@ angular.module('material.components.progressCircular', [ | |
* not necessary to expose what's happening behind the scenes and how long it will take, use an | ||
* indeterminate indicator. | ||
* | ||
* @param {string} md-mode Select from one of two modes: **'determinate'** and **'indeterminate'**.<br/> | ||
* Note: if the `md-mode` value is undefined or not 1 of the two (2) valid modes, then `.ng-hide` | ||
* @param {string} md-mode Select from one of two modes: **'determinate'** and **'indeterminate'**. | ||
* | ||
* Note: if the `md-mode` value is set as undefined or specified as not 1 of the two (2) valid modes, then `.ng-hide` | ||
* will be auto-applied as a style to the component. | ||
* | ||
* Note: if not configured, the `md-mode="indeterminate"` will be auto injected as an attribute. | ||
* If `value=""` is also specified, however, then `md-mode="determinate"` would be auto-injected instead. | ||
* @param {number=} value In determinate mode, this number represents the percentage of the | ||
* circular progress. Default: 0 | ||
* @param {number=} md-diameter This specifies the diamter of the circular progress. The value | ||
|
@@ -46,7 +50,7 @@ angular.module('material.components.progressCircular', [ | |
* <md-progress-circular md-mode="indeterminate"></md-progress-circular> | ||
* </hljs> | ||
*/ | ||
function MdProgressCircularDirective($mdConstant, $mdTheming, $mdUtil) { | ||
function MdProgressCircularDirective($mdTheming, $mdUtil, $log) { | ||
var DEFAULT_PROGRESS_SIZE = 100; | ||
var DEFAULT_SCALING = 0.5; | ||
|
||
|
@@ -87,43 +91,68 @@ function MdProgressCircularDirective($mdConstant, $mdTheming, $mdUtil) { | |
function postLink(scope, element, attr) { | ||
$mdTheming(element); | ||
|
||
var circle = element[0]; | ||
var circle = element; | ||
var spinnerWrapper = angular.element(element.children()[0]); | ||
|
||
var lastMode, toVendorCSS = $mdUtil.dom.animator.toCss; | ||
|
||
// Update size/scaling of the progress indicator | ||
// Watch the "value" and "md-mode" attributes | ||
updateScale(); | ||
validateMode(); | ||
watchAttributes(); | ||
|
||
circle.style[$mdConstant.CSS.TRANSFORM] = 'scale(' + getDiameterRatio() + ')'; | ||
|
||
attr.$observe('value', function(value) { | ||
var percentValue = clamp(value); | ||
element.attr('aria-valuenow', percentValue); | ||
|
||
if (attr.mdMode == "determinate") { | ||
animateIndicator(percentValue); | ||
} | ||
}); | ||
/** | ||
* Watch the value and md-mode attributes | ||
*/ | ||
function watchAttributes() { | ||
attr.$observe('value', function(value) { | ||
var percentValue = clamp(value); | ||
element.attr('aria-valuenow', percentValue); | ||
|
||
if (mode() == MODE_DETERMINATE) { | ||
animateIndicator(percentValue); | ||
} | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a particular reason why the formatting has extra indentation here? Also, should it be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, contrary to what most of the JS world says, the Google JS styleguide uses |
||
attr.$observe('mdMode',function(mode){ | ||
switch( mode ) { | ||
case MODE_DETERMINATE: | ||
case MODE_INDETERMINATE: | ||
spinnerWrapper.removeClass('ng-hide'); | ||
spinnerWrapper.removeClass( lastMode ); | ||
spinnerWrapper.addClass( lastMode = "md-mode-" + mode ); | ||
break; | ||
default: | ||
spinnerWrapper.removeClass( lastMode ); | ||
spinnerWrapper.addClass('ng-hide'); | ||
lastMode = undefined; | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
attr.$observe('mdMode',function(mode){ | ||
switch( mode ) { | ||
case MODE_DETERMINATE: | ||
case MODE_INDETERMINATE: | ||
spinnerWrapper.removeClass('ng-hide'); | ||
/** | ||
* Update size/scaling of the progress indicator | ||
* Watch the "value" and "md-mode" attributes | ||
*/ | ||
function updateScale() { | ||
circle.css(toVendorCSS({ | ||
transform : $mdUtil.supplant('scale( {0} )',[getDiameterRatio()]) | ||
})); | ||
} | ||
|
||
// Inject class selector instead of attribute selector | ||
// (@see layout.js changes for IE performance issues) | ||
/** | ||
* Auto-defaults the mode to either `determinate` or `indeterminate` mode; if not specified | ||
*/ | ||
function validateMode() { | ||
if ( angular.isUndefined(attr.mdMode) ) { | ||
var hasValue = angular.isDefined(attr.value); | ||
var mode = hasValue ? MODE_DETERMINATE : MODE_INDETERMINATE; | ||
var info = "Auto-adding the missing md-mode='{0}' to the ProgressCircular element"; | ||
|
||
if ( lastMode ) spinnerWrapper.removeClass( lastMode ); | ||
lastMode = "md-mode-" + mode; | ||
if ( lastMode ) spinnerWrapper.addClass( lastMode ); | ||
$log.debug( $mdUtil.supplant(info, [mode]) ); | ||
|
||
break; | ||
default: | ||
spinnerWrapper.addClass('ng-hide'); | ||
element.attr("md-mode",mode); | ||
attr['mdMode'] = mode; | ||
} | ||
}); | ||
} | ||
|
||
var leftC, rightC, gap; | ||
|
||
|
@@ -136,6 +165,8 @@ function MdProgressCircularDirective($mdConstant, $mdTheming, $mdUtil) { | |
* - use attribute selectors which had poor performances in IE | ||
*/ | ||
function animateIndicator(value) { | ||
if ( !mode() ) return; | ||
|
||
leftC = leftC || angular.element(element[0].querySelector('.md-left > .md-half-circle')); | ||
rightC = rightC || angular.element(element[0].querySelector('.md-right > .md-half-circle')); | ||
gap = gap || angular.element(element[0].querySelector('.md-gap')); | ||
|
@@ -146,7 +177,7 @@ function MdProgressCircularDirective($mdConstant, $mdTheming, $mdUtil) { | |
}), | ||
leftStyles = removeEmptyValues({ | ||
transition: (value <= 50) ? "transform 0.1s linear" : "", | ||
transform: $mdUtil.supplant("rotate({0}deg)", [value <= 50 ? 135 : ((((value - 50) / 50) * 180) + 135)]) | ||
transform: $mdUtil.supplant("rotate({0}deg)", [value <= 50 ? 135 : (((value - 50) / 50 * 180) + 135)]) | ||
}), | ||
rightStyles = removeEmptyValues({ | ||
transition: (value >= 50) ? "transform 0.1s linear" : "", | ||
|
@@ -174,6 +205,25 @@ function MdProgressCircularDirective($mdConstant, $mdTheming, $mdUtil) { | |
// should return ratio; DEFAULT_PROGRESS_SIZE === 100px is default size | ||
return (value > 1) ? value / DEFAULT_PROGRESS_SIZE : value; | ||
} | ||
|
||
/** | ||
* Is the md-mode a valid option? | ||
*/ | ||
function mode() { | ||
var value = attr.mdMode; | ||
if ( value ) { | ||
switch(value) { | ||
case MODE_DETERMINATE : | ||
case MODE_INDETERMINATE : | ||
break; | ||
default: | ||
value = undefined; | ||
break; | ||
} | ||
} | ||
return value; | ||
} | ||
|
||
} | ||
|
||
/** | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought you could just add newlines in here rather than manually adding
<br/>
. I could be wrong, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.