Debian Codegraph @

dijit/ProgressBar.js

raw symbols SCIP
1 define([
2 "require", // require.toUrl
3 "dojo/_base/declare", // declare
4 "dojo/dom-class", // domClass.toggle
5 "dojo/_base/lang", // lang.mixin
6 "dojo/number", // number.format
7 "./_Widget",
8 "./_TemplatedMixin",
9 "dojo/text!./templates/ProgressBar.html"
10 ], function(require, declare, domClass, lang, number, _Widget, _TemplatedMixin, template){
11
12 // module:
13 // dijit/ProgressBar
14
15 return declare("dijit.ProgressBar", [_Widget, _TemplatedMixin], {
16 // summary:
17 // A progress indication widget, showing the amount completed
18 // (often the percentage completed) of a task.
19
20 // progress: [const] String (Percentage or Number)
21 // Number or percentage indicating amount of task completed.
22 // Deprecated. Use "value" instead.
23 progress: "0",
24
25 // value: String (Percentage or Number)
26 // Number or percentage indicating amount of task completed.
27 // With "%": percentage value, 0% <= progress <= 100%, or
28 // without "%": absolute value, 0 <= progress <= maximum.
29 // Infinity means that the progress bar is indeterminate.
30 value: "",
31
32 // maximum: [const] Float
33 // Max sample number
34 maximum: 100,
35
36 // places: [const] Number
37 // Number of places to show in values; 0 by default
38 places: 0,
39
40 // indeterminate: [const] Boolean
41 // If false: show progress value (number or percentage).
42 // If true: show that a process is underway but that the amount completed is unknown.
43 // Deprecated. Use "value" instead.
44 indeterminate: false,
45
46 // label: String?
47 // HTML label on progress bar. Defaults to percentage for determinate progress bar and
48 // blank for indeterminate progress bar.
49 label: "",
50
51 // name: String
52 // this is the field name (for a form) if set. This needs to be set if you want to use
53 // this widget in a dijit/form/Form widget (such as dijit/Dialog)
54 name: '',
55
56 templateString: template,
57
58 // _indeterminateHighContrastImagePath: [private] URL
59 // URL to image to use for indeterminate progress bar when display is in high contrast mode
60 _indeterminateHighContrastImagePath: require.toUrl("./themes/a11y/indeterminate_progress.gif"),
61
62 postMixInProperties: function(){
63 this.inherited(arguments);
64
65 // Back-compat for when constructor specifies indeterminate or progress, rather than value. Remove for 2.0.
66 if(!(this.params && "value" in this.params)){
67 this.value = this.indeterminate ? Infinity : this.progress;
68 }
69 },
70
71 buildRendering: function(){
72 this.inherited(arguments);
73 this.indeterminateHighContrastImage.setAttribute("src",
74 this._indeterminateHighContrastImagePath.toString());
75 this.update();
76 },
77
78 _setDirAttr: function(val){
79 // Normally _CssStateMixin takes care of this, but we aren't extending it
80 var rtl = val.toLowerCase() == "rtl";
81 domClass.toggle(this.domNode, "dijitProgressBarRtl", rtl);
82 domClass.toggle(this.domNode, "dijitProgressBarIndeterminateRtl", this.indeterminate && rtl);
83 this.inherited(arguments);
84 },
85
86 update: function(/*Object?*/attributes){
87 // summary:
88 // Internal method to change attributes of ProgressBar, similar to set(hash). Users should call
89 // set("value", ...) rather than calling this method directly.
90 // attributes:
91 // May provide progress and/or maximum properties on this parameter;
92 // see attribute specs for details.
93 // example:
94 // | myProgressBar.update({'indeterminate': true});
95 // | myProgressBar.update({'progress': 80});
96 // | myProgressBar.update({'indeterminate': true, label:"Loading ..." })
97 // tags:
98 // private
99
100 // TODO: deprecate this method and use set() instead
101
102 lang.mixin(this, attributes || {});
103 var tip = this.internalProgress, ap = this.domNode;
104 var percent = 1;
105 if(this.indeterminate){
106 ap.removeAttribute("aria-valuenow");
107 }else{
108 if(String(this.progress).indexOf("%") != -1){
109 percent = Math.min(parseFloat(this.progress) / 100, 1);
110 this.progress = percent * this.maximum;
111 }else{
112 this.progress = Math.min(this.progress, this.maximum);
113 percent = this.maximum ? this.progress / this.maximum : 0;
114 }
115 ap.setAttribute("aria-valuenow", this.progress);
116 }
117
118 // Even indeterminate ProgressBars should have these attributes
119 ap.setAttribute("aria-labelledby", this.labelNode.id);
120 ap.setAttribute("aria-valuemin", 0);
121 ap.setAttribute("aria-valuemax", this.maximum);
122
123 this.labelNode.innerHTML = this.report(percent);
124
125 domClass.toggle(this.domNode, "dijitProgressBarIndeterminate", this.indeterminate);
126 domClass.toggle(this.domNode, "dijitProgressBarIndeterminateRtl", this.indeterminate && !this.isLeftToRight());
127
128 tip.style.width = (percent * 100) + "%";
129 this.onChange();
130 },
131
132 _setValueAttr: function(v){
133 this._set("value", v);
134 if(v == Infinity){
135 this.update({indeterminate: true});
136 }else{
137 this.update({indeterminate: false, progress: v});
138 }
139 },
140
141 _setLabelAttr: function(label){
142 this._set("label", label);
143 this.update();
144 },
145
146 _setIndeterminateAttr: function(indeterminate){
147 // Deprecated, use set("value", ...) instead
148 this._set("indeterminate", indeterminate);
149 this.update();
150 },
151
152 report: function(/*float*/percent){
153 // summary:
154 // Generates HTML message to show inside progress bar (normally indicating amount of task completed).
155 // May be overridden.
156 // tags:
157 // extension
158
159 return this.label ? this.label :
160 (this.indeterminate ? "&#160;" : number.format(percent, { type: "percent", places: this.places, locale: this.lang }));
161 },
162
163 onChange: function(){
164 // summary:
165 // Callback fired when progress updates.
166 // tags:
167 // extension
168 }
169 });
170 });