source: Dev/trunk/src/client/dijit/ProgressBar.js @ 525

Last change on this file since 525 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 5.3 KB
Line 
1define([
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                        domClass.toggle(this.domNode, "dijitProgressBarRtl", val == "rtl");
81                        this.inherited(arguments);
82                },
83
84                update: function(/*Object?*/attributes){
85                        // summary:
86                        //              Internal method to change attributes of ProgressBar, similar to set(hash).  Users should call
87                        //              set("value", ...) rather than calling this method directly.
88                        // attributes:
89                        //              May provide progress and/or maximum properties on this parameter;
90                        //              see attribute specs for details.
91                        // example:
92                        //      |       myProgressBar.update({'indeterminate': true});
93                        //      |       myProgressBar.update({'progress': 80});
94                        //      |       myProgressBar.update({'indeterminate': true, label:"Loading ..." })
95                        // tags:
96                        //              private
97
98                        // TODO: deprecate this method and use set() instead
99
100                        lang.mixin(this, attributes || {});
101                        var tip = this.internalProgress, ap = this.domNode;
102                        var percent = 1;
103                        if(this.indeterminate){
104                                ap.removeAttribute("aria-valuenow");
105                        }else{
106                                if(String(this.progress).indexOf("%") != -1){
107                                        percent = Math.min(parseFloat(this.progress) / 100, 1);
108                                        this.progress = percent * this.maximum;
109                                }else{
110                                        this.progress = Math.min(this.progress, this.maximum);
111                                        percent = this.maximum ? this.progress / this.maximum : 0;
112                                }
113                                ap.setAttribute("aria-valuenow", this.progress);
114                        }
115
116                        // Even indeterminate ProgressBars should have these attributes
117                        ap.setAttribute("aria-labelledby", this.labelNode.id);
118                        ap.setAttribute("aria-valuemin", 0);
119                        ap.setAttribute("aria-valuemax", this.maximum);
120
121                        this.labelNode.innerHTML = this.report(percent);
122
123                        domClass.toggle(this.domNode, "dijitProgressBarIndeterminate", this.indeterminate);
124                        tip.style.width = (percent * 100) + "%";
125                        this.onChange();
126                },
127
128                _setValueAttr: function(v){
129                        this._set("value", v);
130                        if(v == Infinity){
131                                this.update({indeterminate: true});
132                        }else{
133                                this.update({indeterminate: false, progress: v});
134                        }
135                },
136
137                _setLabelAttr: function(label){
138                        this._set("label", label);
139                        this.update();
140                },
141
142                _setIndeterminateAttr: function(indeterminate){
143                        // Deprecated, use set("value", ...) instead
144                        this._set("indeterminate", indeterminate);
145                        this.update();
146                },
147
148                report: function(/*float*/percent){
149                        // summary:
150                        //              Generates HTML message to show inside progress bar (normally indicating amount of task completed).
151                        //              May be overridden.
152                        // tags:
153                        //              extension
154
155                        return this.label ? this.label :
156                                (this.indeterminate ? "&#160;" : number.format(percent, { type: "percent", places: this.places, locale: this.lang }));
157                },
158
159                onChange: function(){
160                        // summary:
161                        //              Callback fired when progress updates.
162                        // tags:
163                        //              extension
164                }
165        });
166});
Note: See TracBrowser for help on using the repository browser.