2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo
._hasResource
["dijit.ProgressBar"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo
._hasResource
["dijit.ProgressBar"] = true;
10 dojo
.provide("dijit.ProgressBar");
11 dojo
.require("dojo.fx");
12 dojo
.require("dojo.number");
13 dojo
.require("dijit._Widget");
14 dojo
.require("dijit._Templated");
17 dojo
.declare("dijit.ProgressBar", [dijit
._Widget
, dijit
._Templated
], {
19 // A progress indication widget, showing the amount completed
20 // (often the percentage completed) of a task.
23 // | <div dojoType="ProgressBar"
25 // | value="..." maximum="...">
28 // progress: [const] String (Percentage or Number)
29 // Number or percentage indicating amount of task completed.
30 // Deprecated. Use "value" instead.
33 // value: String (Percentage or Number)
34 // Number or percentage indicating amount of task completed.
35 // With "%": percentage value, 0% <= progress <= 100%, or
36 // without "%": absolute value, 0 <= progress <= maximum.
37 // Infinity means that the progress bar is indeterminate.
40 // maximum: [const] Float
44 // places: [const] Number
45 // Number of places to show in values; 0 by default
48 // indeterminate: [const] Boolean
49 // If false: show progress value (number or percentage).
50 // If true: show that a process is underway but that the amount completed is unknown.
51 // Deprecated. Use "value" instead.
55 // Label on progress bar. Defaults to percentage for determinate progress bar and
56 // blank for indeterminate progress bar.
60 // this is the field name (for a form) if set. This needs to be set if you want to use
61 // this widget in a dijit.form.Form widget (such as dijit.Dialog)
64 templateString
: dojo
.cache("dijit", "templates/ProgressBar.html", "<div class=\"dijitProgressBar dijitProgressBarEmpty\" role=\"progressbar\"\n\t><div dojoAttachPoint=\"internalProgress\" class=\"dijitProgressBarFull\"\n\t\t><div class=\"dijitProgressBarTile\" role=\"presentation\"></div\n\t\t><span style=\"visibility:hidden\"> </span\n\t></div\n\t><div dojoAttachPoint=\"labelNode\" class=\"dijitProgressBarLabel\" id=\"${id}_label\"></div\n\t><img dojoAttachPoint=\"indeterminateHighContrastImage\" class=\"dijitProgressBarIndeterminateHighContrastImage\" alt=\"\"\n/></div>\n"),
66 // _indeterminateHighContrastImagePath: [private] dojo._URL
67 // URL to image to use for indeterminate progress bar when display is in high contrast mode
68 _indeterminateHighContrastImagePath
:
69 dojo
.moduleUrl("dijit", "themes/a11y/indeterminate_progress.gif"),
71 postMixInProperties: function(){
72 this.inherited(arguments
);
73 if(!("value" in this.params
)){
74 this.value
= this.indeterminate
? Infinity
: this.progress
;
78 buildRendering: function(){
79 this.inherited(arguments
);
80 this.indeterminateHighContrastImage
.setAttribute("src",
81 this._indeterminateHighContrastImagePath
.toString());
85 update: function(/*Object?*/attributes
){
87 // Internal method to change attributes of ProgressBar, similar to set(hash). Users should call
88 // set("value", ...) rather than calling this method directly.
90 // May provide progress and/or maximum properties on this parameter;
91 // see attribute specs for details.
93 // | myProgressBar.update({'indeterminate': true});
94 // | myProgressBar.update({'progress': 80});
95 // | myProgressBar.update({'indeterminate': true, label:"Loading ..." })
99 // TODO: deprecate this method and use set() instead
101 dojo
.mixin(this, attributes
|| {});
102 var tip
= this.internalProgress
, ap
= this.domNode
;
104 if(this.indeterminate
){
105 dijit
.removeWaiState(ap
, "valuenow");
106 dijit
.removeWaiState(ap
, "valuemin");
107 dijit
.removeWaiState(ap
, "valuemax");
109 if(String(this.progress
).indexOf("%") != -1){
110 percent
= Math
.min(parseFloat(this.progress
)/100, 1);
111 this.progress
= percent
* this.maximum
;
113 this.progress
= Math
.min(this.progress
, this.maximum
);
114 percent
= this.progress
/ this.maximum
;
117 dijit
.setWaiState(ap
, "describedby", this.labelNode
.id
);
118 dijit
.setWaiState(ap
, "valuenow", this.progress
);
119 dijit
.setWaiState(ap
, "valuemin", 0);
120 dijit
.setWaiState(ap
, "valuemax", this.maximum
);
122 this.labelNode
.innerHTML
= this.report(percent
);
124 dojo
.toggleClass(this.domNode
, "dijitProgressBarIndeterminate", this.indeterminate
);
125 tip
.style
.width
= (percent
* 100) + "%";
129 _setValueAttr: function(v
){
130 this._set("value", v
);
132 this.update({indeterminate
:true});
134 this.update({indeterminate
:false, progress
:v
});
138 _setLabelAttr: function(label
){
139 this._set("label", label
);
143 _setIndeterminateAttr: function(indeterminate
){
144 // Deprecated, use set("value", ...) instead
145 this.indeterminate
= indeterminate
;
149 report: function(/*float*/percent
){
151 // Generates message to show inside progress bar (normally indicating amount of task completed).
152 // May be overridden.
156 return this.label
? this.label
:
157 (this.indeterminate
? " " : dojo
.number
.format(percent
, { type
: "percent", places
: this.places
, locale
: this.lang
}));
160 onChange: function(){
162 // Callback fired when progress updates.