| 1 |
define([ |
| 2 |
"require", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/dom-class", |
| 5 |
"dojo/_base/lang", |
| 6 |
"dojo/number", |
| 7 |
"./_Widget", |
| 8 |
"./_TemplatedMixin", |
| 9 |
"dojo/text!./templates/ProgressBar.html" |
| 10 |
], function(require, declare, domClass, lang, number, _Widget, _TemplatedMixin, template){ |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
return declare("dijit.ProgressBar", [_Widget, _TemplatedMixin], { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
progress: "0", |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
value: "", |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
maximum: 100, |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
places: 0, |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
indeterminate: false, |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
label: "", |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
name: '', |
| 55 |
|
| 56 |
templateString: template, |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
_indeterminateHighContrastImagePath: require.toUrl("./themes/a11y/indeterminate_progress.gif"), |
| 61 |
|
| 62 |
postMixInProperties: function(){ |
| 63 |
this.inherited(arguments); |
| 64 |
|
| 65 |
|
| 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 |
|
| 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(attributes){ |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 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 |
|
| 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 |
|
| 148 |
this._set("indeterminate", indeterminate); |
| 149 |
this.update(); |
| 150 |
}, |
| 151 |
|
| 152 |
report: function(percent){ |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
return this.label ? this.label : |
| 160 |
(this.indeterminate ? " " : number.format(percent, { type: "percent", places: this.places, locale: this.lang })); |
| 161 |
}, |
| 162 |
|
| 163 |
onChange: function(){ |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
} |
| 169 |
}); |
| 170 |
}); |