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

Commit

Permalink
chore(progressCircular): remove dead code, minor refactoring, add com…
Browse files Browse the repository at this point in the history
…ments.
  • Loading branch information
jelbourn committed Mar 16, 2015
1 parent dc2d204 commit a61def3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 51 deletions.
74 changes: 28 additions & 46 deletions src/components/progressCircular/progressCircular.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ angular.module('material.components.progressCircular', [
* @restrict E
*
* @description
* The circular progress directive is used to make loading content in your app as delightful and painless as possible by minimizing the amount of visual change a user sees before they can view and interact with content.
* The circular progress directive is used to make loading content in your app as delightful and
* painless as possible by minimizing the amount of visual change a user sees before they can view
* and interact with content.
*
* For operations where the percentage of the operation completed can be determined, use a determinate indicator. They give users a quick sense of how long an operation will take.
* For operations where the percentage of the operation completed can be determined, use a
* determinate indicator. They give users a quick sense of how long an operation will take.
*
* For operations where the user is asked to wait a moment while something finishes up, and it’s not necessary to expose what's happening behind the scenes and how long it will take, use an indeterminate indicator.
* For operations where the user is asked to wait a moment while something finishes up, and it’s
* 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.
* @param {number=} value In determinate mode, this number represents the percentage of the circular progress. Default: 0
* @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. Default: 48
*
* @usage
Expand All @@ -39,21 +45,12 @@ angular.module('material.components.progressCircular', [
* <md-progress-circular md-mode="indeterminate"></md-progress-circular>
* </hljs>
*/
function MdProgressCircularDirective($$rAF, $mdConstant, $mdTheming) {
var fillRotations = new Array(101),
fixRotations = new Array(101);

for (var i = 0; i < 101; i++) {
var percent = i / 100;
var rotation = Math.floor(percent * 180);

fillRotations[i] = 'rotate(' + rotation.toString() + 'deg)';
fixRotations[i] = 'rotate(' + (rotation * 2).toString() + 'deg)';
}

function MdProgressCircularDirective($mdConstant, $mdTheming) {
return {
restrict: 'E',
template:
// The progress 'circle' is composed of two half-circles: the left side and the right
// side. Each side has CSS applied to 'fill-in' the half-circle to the appropriate progress.
'<div class="md-spinner-wrapper">' +
'<div class="md-inner">' +
'<div class="md-gap"></div>' +
Expand All @@ -68,7 +65,9 @@ function MdProgressCircularDirective($$rAF, $mdConstant, $mdTheming) {
compile: compile
};

function compile(tElement, tAttrs, transclude) {
function compile(tElement) {
// The javascript in this file is mainly responsible for setting the correct aria attributes.
// The animation of the progress spinner is done entirely with just CSS.
tElement.attr('aria-valuemin', 0);
tElement.attr('aria-valuemax', 100);
tElement.attr('role', 'progressbar');
Expand All @@ -78,43 +77,26 @@ function MdProgressCircularDirective($$rAF, $mdConstant, $mdTheming) {

function postLink(scope, element, attr) {
$mdTheming(element);
var circle = element[0],
fill = circle.querySelectorAll('.md-fill, .md-mask.md-full'),
fix = circle.querySelectorAll('.md-fill.md-fix'),
i, clamped, fillRotation, fixRotation;
var circle = element[0];

// Scale the progress circle based on the default diameter.
var diameter = attr.mdDiameter || 48;
var scale = diameter/48;

circle.style[$mdConstant.CSS.TRANSFORM] = 'scale(' + scale.toString() + ')';
var scale = diameter / 48;
circle.style[$mdConstant.CSS.TRANSFORM] = 'scale(' + scale + ')';

attr.$observe('value', function(value) {
clamped = clamp(value);
fillRotation = fillRotations[clamped];
fixRotation = fixRotations[clamped];

element.attr('aria-valuenow', clamped);

for (i = 0; i < fill.length; i++) {
fill[i].style[$mdConstant.CSS.TRANSFORM] = fillRotation;
}

for (i = 0; i < fix.length; i++) {
fix[i].style[$mdConstant.CSS.TRANSFORM] = fixRotation;
}
var percentValue = clamp(value);
element.attr('aria-valuenow', percentValue);
});
}

/**
* Clamps the value to be between 0 and 100.
* @param {number} value The value to clamp.
* @returns {number}
*/
function clamp(value) {
if (value > 100) {
return 100;
}

if (value < 0) {
return 0;
}

return Math.ceil(value || 0);
return Math.max(0, Math.min(value || 0, 100));
}
}
})();
10 changes: 5 additions & 5 deletions src/components/progressCircular/progressCircular.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ md-progress-circular {
width: $progress-circular-size;
height: $progress-circular-size;
box-sizing: border-box;
border-width: 5px;
border-style: solid;
border-color: black black transparent;
border: 5px solid black;
border-bottom-color: transparent;
border-radius: 50%;
}
}
Expand All @@ -82,6 +81,8 @@ md-progress-circular {
}
}

// TODO: This while-loop generates about 2 kilobytes of css after gzip.
// Refactor progressCircular to animate with javascript.
$i: 0;
@while $i <= 100 {
&[value="#{$i}"] {
Expand Down Expand Up @@ -109,8 +110,7 @@ md-progress-circular {
}
}
.md-gap {
border-bottom-width: 5px;
border-bottom-style: solid;
border-bottom: 5px solid;
@if $i <= 50 {
border-bottom-color: transparent !important;
} @else {
Expand Down

0 comments on commit a61def3

Please sign in to comment.