source: trip-planner-front/node_modules/angular-material/modules/closure/progressLinear/progressLinear.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*!
2 * AngularJS Material Design
3 * https://github.com/angular/material
4 * @license MIT
5 * v1.2.3
6 */
7goog.provide('ngmaterial.components.progressLinear');
8goog.require('ngmaterial.core');
9/**
10 * @ngdoc module
11 * @name material.components.progressLinear
12 * @description Linear Progress module!
13 */
14MdProgressLinearDirective['$inject'] = ["$mdTheming", "$mdUtil", "$log"];
15angular.module('material.components.progressLinear', [
16 'material.core'
17])
18 .directive('mdProgressLinear', MdProgressLinearDirective);
19
20/**
21 * @ngdoc directive
22 * @name mdProgressLinear
23 * @module material.components.progressLinear
24 * @restrict E
25 *
26 * @description
27 * The linear progress directive is used to make loading content
28 * in your app as delightful and painless as possible by minimizing
29 * the amount of visual change a user sees before they can view
30 * and interact with content.
31 *
32 * Each operation should only be represented by one activity indicator
33 * For example: one refresh operation should not display both a
34 * refresh bar and an activity circle.
35 *
36 * For operations where the percentage of the operation completed
37 * can be determined, use a determinate indicator. They give users
38 * a quick sense of how long an operation will take.
39 *
40 * For operations where the user is asked to wait a moment while
41 * something finishes up, and it’s not necessary to expose what's
42 * happening behind the scenes and how long it will take, use an
43 * indeterminate indicator.
44 *
45 * @param {string} md-mode Select from one of four modes: determinate, indeterminate, buffer or query.
46 *
47 * Note: if the `md-mode` value is set as undefined or specified as 1 of the four (4) valid modes, then `indeterminate`
48 * will be auto-applied as the mode.
49 *
50 * Note: if not configured, the `md-mode="indeterminate"` will be auto injected as an attribute. If `value=""` is also specified, however,
51 * then `md-mode="determinate"` would be auto-injected instead.
52 * @param {number=} value In determinate and buffer modes, this number represents the percentage of the primary progress bar. Default: 0
53 * @param {number=} md-buffer-value In the buffer mode, this number represents the percentage of the secondary progress bar. Default: 0
54 * @param {boolean=} ng-disabled Determines whether to disable the progress element.
55 *
56 * @usage
57 * <hljs lang="html">
58 * <md-progress-linear md-mode="determinate" value="..."></md-progress-linear>
59 *
60 * <md-progress-linear md-mode="determinate" ng-value="..."></md-progress-linear>
61 *
62 * <md-progress-linear md-mode="indeterminate"></md-progress-linear>
63 *
64 * <md-progress-linear md-mode="buffer" value="..." md-buffer-value="..."></md-progress-linear>
65 *
66 * <md-progress-linear md-mode="query"></md-progress-linear>
67 * </hljs>
68 */
69function MdProgressLinearDirective($mdTheming, $mdUtil, $log) {
70 var MODE_DETERMINATE = "determinate";
71 var MODE_INDETERMINATE = "indeterminate";
72 var MODE_BUFFER = "buffer";
73 var MODE_QUERY = "query";
74 var DISABLED_CLASS = "_md-progress-linear-disabled";
75
76 return {
77 restrict: 'E',
78 template: '<div class="md-container">' +
79 '<div class="md-dashed"></div>' +
80 '<div class="md-bar md-bar1"></div>' +
81 '<div class="md-bar md-bar2"></div>' +
82 '</div>',
83 compile: compile
84 };
85
86 function compile(tElement, tAttrs, transclude) {
87 tElement.attr('aria-valuemin', 0);
88 tElement.attr('aria-valuemax', 100);
89 tElement.attr('role', 'progressbar');
90
91 return postLink;
92 }
93 function postLink(scope, element, attr) {
94 $mdTheming(element);
95
96 var lastMode;
97 var isDisabled = attr.hasOwnProperty('disabled');
98 var toVendorCSS = $mdUtil.dom.animator.toCss;
99 var bar1 = angular.element(element[0].querySelector('.md-bar1'));
100 var bar2 = angular.element(element[0].querySelector('.md-bar2'));
101 var container = angular.element(element[0].querySelector('.md-container'));
102
103 element
104 .attr('md-mode', mode())
105 .toggleClass(DISABLED_CLASS, isDisabled);
106
107 validateMode();
108 watchAttributes();
109
110 /**
111 * Watch the value, md-buffer-value, and md-mode attributes
112 */
113 function watchAttributes() {
114 attr.$observe('value', function(value) {
115 var percentValue = clamp(value);
116 element.attr('aria-valuenow', percentValue);
117
118 if (mode() != MODE_QUERY) animateIndicator(bar2, percentValue);
119 });
120
121 attr.$observe('mdBufferValue', function(value) {
122 animateIndicator(bar1, clamp(value));
123 });
124
125 attr.$observe('disabled', function(value) {
126 if (value === true || value === false) {
127 isDisabled = !!value;
128 } else {
129 isDisabled = angular.isDefined(value);
130 }
131
132 element.toggleClass(DISABLED_CLASS, isDisabled);
133 container.toggleClass(lastMode, !isDisabled);
134 });
135
136 attr.$observe('mdMode', function(mode) {
137 if (lastMode) container.removeClass(lastMode);
138
139 switch (mode) {
140 case MODE_QUERY:
141 case MODE_BUFFER:
142 case MODE_DETERMINATE:
143 case MODE_INDETERMINATE:
144 container.addClass(lastMode = "md-mode-" + mode);
145 break;
146 default:
147 container.addClass(lastMode = "md-mode-" + MODE_INDETERMINATE);
148 break;
149 }
150 });
151 }
152
153 /**
154 * Auto-defaults the mode to either `determinate` or `indeterminate` mode; if not specified
155 */
156 function validateMode() {
157 if (angular.isUndefined(attr.mdMode)) {
158 var hasValue = angular.isDefined(attr.value);
159 var mode = hasValue ? MODE_DETERMINATE : MODE_INDETERMINATE;
160 var info = "Auto-adding the missing md-mode='{0}' to the ProgressLinear element";
161 element.attr("md-mode", mode);
162 attr.mdMode = mode;
163 }
164 }
165
166 /**
167 * Is the md-mode a valid option?
168 */
169 function mode() {
170 var value = (attr.mdMode || "").trim();
171 if (value) {
172 switch (value) {
173 case MODE_DETERMINATE:
174 case MODE_INDETERMINATE:
175 case MODE_BUFFER:
176 case MODE_QUERY:
177 break;
178 default:
179 value = MODE_INDETERMINATE;
180 break;
181 }
182 }
183 return value;
184 }
185
186 /**
187 * Manually set CSS to animate the Determinate indicator based on the specified
188 * percentage value (0-100).
189 */
190 function animateIndicator(target, value) {
191 if (isDisabled || !mode()) return;
192
193 var to = $mdUtil.supplant("translateX({0}%) scale({1},1)", [(value-100)/2, value/100]);
194 var styles = toVendorCSS({ transform : to });
195 angular.element(target).css(styles);
196 }
197 }
198
199 /**
200 * Clamps the value to be between 0 and 100.
201 * @param {number} value The value to clamp.
202 * @returns {number}
203 */
204 function clamp(value) {
205 return Math.max(0, Math.min(value || 0, 100));
206 }
207}
208
209
210ngmaterial.components.progressLinear = angular.module("material.components.progressLinear");
Note: See TracBrowser for help on using the repository browser.