Changeset 7504
- Timestamp:
- 03/01/07 12:02:26 (21 months ago)
- Location:
- dijit/trunk
- Files:
-
- 3 modified
-
ProgressBar.js (modified) (9 diffs)
-
templates/ProgressBar.html (modified) (1 diff)
-
tests/test_ProgressBar.html (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dijit/trunk/ProgressBar.js
r7501 r7504 37 37 // places="0" width="..." height="..." dataSource="..." 38 38 // pollInterval="..." 39 // numeric="true|false" orientation="vertical"39 // annotate="true|false" orientation="vertical" 40 40 // progress="..." maximum="..."></div> 41 41 … … 62 62 color: "", 63 63 64 // numeric: Boolean65 // if true, the percent label is visible66 numeric: false,67 68 64 // orientation: String 69 65 // whether bar grows along the x-axis (default) or y- axis (vertical) 70 66 orientation: "", 71 67 68 // annotate: Boolean 69 // if true, the percent label is visible 70 annotate: false, 71 72 72 // places: Number 73 // number of places to show in percentvalues; 0 by default73 // number of places to show in values; 0 by default 74 74 places: 0, 75 75 76 76 // dataSource: String 77 77 // dataSource uri for server polling … … 88 88 templatePath: dojo.uri.moduleUri("dijit", "templates/ProgressBar.html"), 89 89 90 _percent: 0.0,91 _animationStopped: true,92 93 90 // public functions 94 91 postCreate: function(){ … … 99 96 dojo.html.setClass(this.internalProgress, "dojoProgressBarFull"); 100 97 } 101 dojo.html.setClass(this.containerNode, "dojoProgressBarEmpty");102 98 if(this.orientation == "vertical"){ 103 99 dojo.html.addClass(this.containerNode, "dojoProgressBarVertical"); … … 112 108 this.domNode.style.height = this.height + "px"; 113 109 this.domNode.style.width = this.width + "px"; 114 this.setMaximum(this.maximum, true); 115 this.setProgress(this.progress, true); 116 this.showLabel(this.numeric); 117 this.render(); 118 }, 119 showLabel: function(/*Boolean*/visible){ 120 // summary: shows or hides the labels 121 var display = visible ? "block" : "none"; 122 this.backLabel.style.display=display; 123 this.frontLabel.style.display=display; 124 this.numeric = visible; 125 }, 110 this.update(); 111 }, 112 113 update: function(/*Object*/attributes){ 114 // summary: update progress information 115 // 116 // attributes: may provide progress and/or maximum properties on this parameter, 117 // see attribute specs for details. 118 dojo.lang.mixin(this, attributes); 119 var percent; 120 if(String(this.progress).indexOf("%") != -1){ 121 percent = Math.min(parseFloat(this.progress)/100, 1); 122 this.progress = percent * this.maximum; 123 }else{ 124 this.progress = Math.min(this.progress, this.maximum); 125 percent = this.progress / this.maximum; 126 } 127 128 if(!this._animationStopped){return;} 129 130 var pixels = percent * this[this._dimension]; 131 this.internalProgress.style[this._dimension] = pixels + 'px'; 132 133 var display = this.annotate ? "block" : "none"; 134 dojo.lang.forEach(["front", "back"], function(name){ 135 var labelNode = this[name+"Label"]; 136 dojo.dom.textContent(labelNode, this.report(percent)); 137 138 labelNode.style.display = display; 139 140 var dim = dojo.html.getContentBox(labelNode); 141 var labelLeft = (this.width - dim.width)/2; 142 var labelBottom = (this.height - dim.height)/2; 143 labelNode.style.left = labelLeft + "px"; 144 labelNode.style.bottom = labelBottom + "px"; 145 }, this); 146 147 this.onChange(); 148 }, 149 150 report: function(/*float*/percent){ 151 // Generates percentage to overlay; may be overridden by user 152 return dojo.number.format(percent, {type: "percent", places: this.places}); 153 }, 154 155 _animationStopped: true, 156 126 157 _setupAnimation: function(){ 127 158 var self = this; 128 159 this._animation = dojo.lfx.html.slideTo(this.internalProgress, 129 160 {top: 0, left: parseInt(this.width)-parseInt(this.internalProgress.style.width)}, parseInt(this.duration), null, 130 function(){ 131 var _backAnim = dojo.lfx.html.slideTo(self.internalProgress, 132 { top: 0, left: 0 }, parseInt(self.duration)); 133 dojo.event.connect(_backAnim, "onEnd", function(){ 134 if(!self._animationStopped){ 135 self._animation.play(); 136 } 137 }); 161 function(){ 162 var backAnim = dojo.lfx.html.slideTo(self.internalProgress, 163 { top: 0, left: 0 }, parseInt(self.duration)); 164 dojo.event.connect(backAnim, "onEnd", function(){ 138 165 if(!self._animationStopped){ 139 _backAnim.play();166 self._animation.play(); 140 167 } 141 _backAnim = null; // <-- to avoid memory leaks in IE 168 }); 169 if(!self._animationStopped){ 170 backAnim.play(); 142 171 } 143 ); 144 }, 145 setMaximum: function(/*Number*/maximum, /*Boolean?*/noRender){ 146 // summary: sets the maximum 147 // if noRender is true, only sets the internal max progress value 148 if(!this._animationStopped){ 149 return; 150 } 151 this.maximum = maximum; 152 this.setProgress(this.progress, true); 153 if(!noRender){ 154 this.render(); 155 } 156 }, 157 setProgress: function(/*String|Number*/value, /*Boolean?*/noRender){ 158 // summary: sets the progress 159 // if value ends width "%", does a normalization 160 // if noRender is true, only sets the internal value: useful if 161 // there is a setMaximum call 162 if(!this._animationStopped){ 163 return; 164 } 165 if(String(value).indexOf("%") != -1){ 166 this._percent = Math.min(parseFloat(value)/100, 1); 167 this.progress = this._percent * this.maximum; 168 }else{ 169 this.progress = Math.min(value, this.maximum); 170 this._percent = value / this.maximum; 171 } 172 if(!noRender){ 173 this.render(); 174 } 175 }, 176 start: function(){ 177 // summary: starts the server polling 178 var _showFunction = dojo.lang.hitch(this, this._showRemoteProgress); 179 this._timer = setInterval(_showFunction, this.pollInterval); 180 }, 172 backAnim = null; // <-- to avoid memory leaks in IE 173 }); 174 }, 175 181 176 startAnimation: function(){ 182 177 // summary: starts the left-right animation, useful when 183 178 // the user doesn't know how much time the operation will last 184 179 if(this._animationStopped){ 185 this._backup = {progress: this.progress, numeric: this.numeric};186 this. setProgress("10%");180 this._backup = {progress: this.progress, annotate: this.annotate}; 181 this.update({progress: "10%", annotate: false}); 187 182 this._animationStopped = false; 188 183 this._setupAnimation(); 189 this.showLabel(false);190 184 this.internalProgress.style.height="105%"; 191 185 this._animation.play(); … … 200 194 this.internalProgress.style.left = "0px"; 201 195 dojo.lang.mixin(this, this._backup); 202 this.setProgress(this.progress); 203 this.showLabel(this.numeric); 204 this._positionLabels(); 205 } 206 }, 196 this.update(); 197 } 198 }, 199 200 start: function(){ 201 // summary: starts the server polling 202 var _showFunction = dojo.lang.hitch(this, this._showRemoteProgress); 203 this._timer = setInterval(_showFunction, this.pollInterval); 204 }, 205 207 206 _showRemoteProgress: function(){ 208 207 var self = this; … … 210 209 clearInterval(this._timer); 211 210 this._timer = null; 212 this. setProgress("100%");211 this.update({progress: "100%"}); 213 212 return; 214 213 } … … 221 220 }, 222 221 load: function(type, data, evt){ 223 self. setProgress(self._timer ? data.progress : "100%");222 self.update({progress: self._timer ? data.progress : "100%"}); 224 223 } 225 224 }; … … 227 226 }, 228 227 229 render: function(){230 // summary: renders the ProgressBar, based on current values231 232 this._updateLabels(this._percent);233 234 var pixels = this._percent * this[this._dimension];235 this.internalProgress.style[this._dimension] = pixels + 'px';236 this.onChange();237 238 this._positionLabels();239 },240 241 _positionLabels: function(){242 dojo.lang.forEach(["front", "back"], function(name){243 var labelNode = this[name+"Label"];244 var dim = dojo.html.getContentBox(labelNode);245 var labelLeft = (this.width - dim.width)/2;246 var labelBottom = (this.height - dim.height)/2;247 labelNode.style.left = labelLeft + "px";248 labelNode.style.bottom = labelBottom + "px";249 }, this);250 },251 _updateLabels: function(/*float*/percent){252 dojo.lang.forEach(["front", "back"], function(name){253 var labelNode = this[name+"Label"];254 dojo.dom.textContent(labelNode, dojo.number.format(percent, {type: "percent", places: this.places}));255 }, this);256 },257 228 onChange: function(){ 258 229 } -
dijit/trunk/templates/ProgressBar.html
r7501 r7504 1 <div dojoAttachPoint="containerNode" >1 <div dojoAttachPoint="containerNode" class="dojoProgressBarEmpty"> 2 2 <div style="position:absolute;display:none;width:100%;text-align:center" dojoAttachPoint="backLabel" class="dojoProgressBarBackLabel"></div> 3 3 <div style="position:absolute;overflow:hidden;width:100%;height:100%" dojoAttachPoint="internalProgress"> -
dijit/trunk/tests/test_ProgressBar.html
r7501 r7504 14 14 dojo.require("dojo.io.*"); 15 15 dojo.require("dojo.io.IframeIO"); 16 dojo.require("dojo.string.extras"); 16 17 dojo.hostenv.writeIncludes(); 17 18 </script> … … 20 21 dojo.addOnLoad(go); 21 22 function go(){ 22 var theBar = dijit.byId("testBar"); 23 //TODO: it's a little strange that id must be specified again? 24 var theBar = new dijit.ProgressBar({id: "testBar", width: 400, annotate: true, maximum: 256, duration: 2000, 25 report:function(percent){ 26 return dojo.string.substitute("${0} out of ${1} max chars", [this.progress, this.maximum]); 27 } 28 }, dojo.byId("testBar")); 23 29 dojo.event.connect(dojo.byId("start"), "onclick", dojo.lang.hitch(theBar,theBar.startAnimation)); 24 30 dojo.event.connect(dojo.byId("stop"), "onclick", dojo.lang.hitch(theBar,theBar.stopAnimation)); … … 48 54 } 49 55 function setParameters(){ 50 dijit.byId("setTestBar").setMaximum(dojo.byId("maximum").value, true); 51 dijit.byId("setTestBar").setProgress(dojo.byId("progressValue").value, true); 52 dijit.byId("setTestBar").render(); 56 dijit.byId("setTestBar").update({maximum: dojo.byId("maximum").value, progress: dojo.byId("progressValue").value}); 53 57 } 54 58 function keyUpHandler(){ 55 dijit.byId("testBar"). setProgress(dojo.byId("test").value.length);56 dijit.byId("testBarInt"). setProgress(dojo.byId("test").value.length);57 dijit.byId("testBar2"). setProgress(dojo.byId("test").value.length);58 dijit.byId("smallTestBar"). setProgress(dojo.byId("test").value.length);59 dijit.byId("testBar").update({progress:dojo.byId("test").value.length}); 60 dijit.byId("testBarInt").update({progress:dojo.byId("test").value.length}); 61 dijit.byId("testBar2").update({progress:dojo.byId("test").value.length}); 62 dijit.byId("smallTestBar").update({progress:dojo.byId("test").value.length}); 59 63 } 60 64 </script> … … 69 73 <input type="button" name="set" id="set" value="set!" /> 70 74 <br /> 71 <div width="400" numeric="true"72 maximum="200" id="setTestBar" progress="20" dojoType="dijit.ProgressBar"></div> 75 <div width="400" annotate="true" 76 maximum="200" id="setTestBar" progress="20" dojoType="dijit.ProgressBar"></div> 73 77 <br /> 74 78 <br /> … … 77 81 <br /> 78 82 <br /> 79 <div width="400" numeric="true" 80 maximum="256" id="testBar" duration="2000" dojoType="dijit.ProgressBar"></div> 83 <div id="testBar"></div> 81 84 <input type="button" name="start" id="start" value="start" /> 82 85 <input type="button" name="stop" id="stop" value="stop" /> … … 88 91 <br /> 89 92 Show decimal place: 90 <div places="1" width="400" numeric="true" orientation="horizontal"91 maximum="256" id="testBarInt" dojoType="dijit.ProgressBar"></div> 93 <div places="1" width="400" annotate="true" orientation="horizontal" 94 maximum="256" id="testBarInt" dojoType="dijit.ProgressBar"></div> 92 95 <br /> 93 96 <div style="position:absolute;top:70px;left:530px"> 94 97 Vertical: 95 <div progress="0" height="420" width="50" numeric="true" orientation="vertical"98 <div progress="0" height="420" width="50" annotate="true" orientation="vertical" 96 99 maximum="256" id="testBar2" dojoType="dijit.ProgressBar"></div> 97 100 </div> 98 101 <h3>Test 3</h3> 99 102 No explicit maximum (both 25%) 100 <div width="400" numeric="true"103 <div width="400" annotate="true" 101 104 id="implied1" progress="25" dojoType="dijit.ProgressBar"></div> 102 <div width="400" numeric="true" 105 <br /> 106 <div width="400" annotate="true" 103 107 id="implied2" progress="25%" dojoType="dijit.ProgressBar"></div> 104 108 </body>