2150 |
mathias |
1 |
if(!dojo._hasResource["dijit.ProgressBar"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dijit.ProgressBar"] = true;
|
|
|
3 |
dojo.provide("dijit.ProgressBar");
|
|
|
4 |
|
|
|
5 |
dojo.require("dojo.fx");
|
|
|
6 |
dojo.require("dojo.number");
|
|
|
7 |
|
|
|
8 |
dojo.require("dijit._Widget");
|
|
|
9 |
dojo.require("dijit._Templated");
|
|
|
10 |
|
|
|
11 |
dojo.declare("dijit.ProgressBar", [dijit._Widget, dijit._Templated], {
|
|
|
12 |
// summary:
|
|
|
13 |
// a progress widget
|
|
|
14 |
//
|
|
|
15 |
// usage:
|
|
|
16 |
// <div dojoType="ProgressBar"
|
|
|
17 |
// places="0"
|
|
|
18 |
// progress="..." maximum="..."></div>
|
|
|
19 |
|
|
|
20 |
// progress: String (Percentage or Number)
|
|
|
21 |
// initial progress value.
|
|
|
22 |
// with "%": percentage value, 0% <= progress <= 100%
|
|
|
23 |
// or without "%": absolute value, 0 <= progress <= maximum
|
|
|
24 |
progress: "0",
|
|
|
25 |
|
|
|
26 |
// maximum: Float
|
|
|
27 |
// max sample number
|
|
|
28 |
maximum: 100,
|
|
|
29 |
|
|
|
30 |
// places: Number
|
|
|
31 |
// number of places to show in values; 0 by default
|
|
|
32 |
places: 0,
|
|
|
33 |
|
|
|
34 |
// indeterminate: Boolean
|
|
|
35 |
// false: show progress
|
|
|
36 |
// true: show that a process is underway but that the progress is unknown
|
|
|
37 |
indeterminate: false,
|
|
|
38 |
|
|
|
39 |
templateString:"<div class=\"dijitProgressBar dijitProgressBarEmpty\"\n\t><div waiRole=\"progressbar\" tabindex=\"0\" dojoAttachPoint=\"internalProgress\" class=\"dijitProgressBarFull\"\n\t\t><div class=\"dijitProgressBarTile\"></div\n\t\t><span style=\"visibility:hidden\"> </span\n\t></div\n\t><div dojoAttachPoint=\"label\" class=\"dijitProgressBarLabel\" id=\"${id}_label\"> </div\n\t><img dojoAttachPoint=\"inteterminateHighContrastImage\" class=\"dijitProgressBarIndeterminateHighContrastImage\"\n\t></img\n></div>\n",
|
|
|
40 |
|
|
|
41 |
_indeterminateHighContrastImagePath:
|
|
|
42 |
dojo.moduleUrl("dijit", "themes/a11y/indeterminate_progress.gif"),
|
|
|
43 |
|
|
|
44 |
// public functions
|
|
|
45 |
postCreate: function(){
|
|
|
46 |
this.inherited("postCreate",arguments);
|
|
|
47 |
this.inteterminateHighContrastImage.setAttribute("src",
|
|
|
48 |
this._indeterminateHighContrastImagePath);
|
|
|
49 |
this.update();
|
|
|
50 |
},
|
|
|
51 |
|
|
|
52 |
update: function(/*Object?*/attributes){
|
|
|
53 |
// summary: update progress information
|
|
|
54 |
//
|
|
|
55 |
// attributes: may provide progress and/or maximum properties on this parameter,
|
|
|
56 |
// see attribute specs for details.
|
|
|
57 |
dojo.mixin(this, attributes||{});
|
|
|
58 |
var percent = 1, classFunc;
|
|
|
59 |
if(this.indeterminate){
|
|
|
60 |
classFunc = "addClass";
|
|
|
61 |
dijit.removeWaiState(this.internalProgress, "valuenow");
|
|
|
62 |
dijit.removeWaiState(this.internalProgress, "valuemin");
|
|
|
63 |
dijit.removeWaiState(this.internalProgress, "valuemax");
|
|
|
64 |
}else{
|
|
|
65 |
classFunc = "removeClass";
|
|
|
66 |
if(String(this.progress).indexOf("%") != -1){
|
|
|
67 |
percent = Math.min(parseFloat(this.progress)/100, 1);
|
|
|
68 |
this.progress = percent * this.maximum;
|
|
|
69 |
}else{
|
|
|
70 |
this.progress = Math.min(this.progress, this.maximum);
|
|
|
71 |
percent = this.progress / this.maximum;
|
|
|
72 |
}
|
|
|
73 |
var text = this.report(percent);
|
|
|
74 |
this.label.firstChild.nodeValue = text;
|
|
|
75 |
dijit.setWaiState(this.internalProgress, "describedby", this.label.id);
|
|
|
76 |
dijit.setWaiState(this.internalProgress, "valuenow", this.progress);
|
|
|
77 |
dijit.setWaiState(this.internalProgress, "valuemin", 0);
|
|
|
78 |
dijit.setWaiState(this.internalProgress, "valuemax", this.maximum);
|
|
|
79 |
}
|
|
|
80 |
dojo[classFunc](this.domNode, "dijitProgressBarIndeterminate");
|
|
|
81 |
this.internalProgress.style.width = (percent * 100) + "%";
|
|
|
82 |
this.onChange();
|
|
|
83 |
},
|
|
|
84 |
|
|
|
85 |
report: function(/*float*/percent){
|
|
|
86 |
// Generates message to show; may be overridden by user
|
|
|
87 |
return dojo.number.format(percent, {type: "percent", places: this.places, locale: this.lang});
|
|
|
88 |
},
|
|
|
89 |
|
|
|
90 |
onChange: function(){}
|
|
|
91 |
});
|
|
|
92 |
|
|
|
93 |
}
|