/** A progress bar is a widget that shows progress from 0% to 100% @constructor */ hui.ui.ProgressBar = function(o) { this.element = hui.get(o.element); this.name = o.name; /** @private */ this.WAITING = o.small ? 'hui_progressbar_small_waiting' : 'hui_progressbar_waiting'; /** @private */ this.COMPLETE = o.small ? 'hui_progressbar_small_complete' : 'hui_progressbar_complete'; /** @private */ this.options = o || {}; /** @private */ this.indicator = hui.get.firstByTag(this.element,'div'); hui.ui.extend(this); }; /** Creates a new progress bar: @param o {Object} Options : {small:false} */ hui.ui.ProgressBar.create = function(o) { o = o || {}; var e = o.element = hui.build('div',{'class':o.small ? 'hui_progressbar hui_progressbar_small' : 'hui_progressbar'}); e.appendChild(document.createElement('div')); return new hui.ui.ProgressBar(o); }; hui.ui.ProgressBar.prototype = { /** Set the progress value @param value {Number} A number between 0 and 1 */ setValue : function(value) { var el = this.element; if (this.waiting) { hui.cls.remove(el,this.WAITING); } hui.cls.set(el,this.COMPLETE,value==1); hui.animate(this.indicator,'width',(value*100)+'%',200); }, /** Mark progress as waiting */ setWaiting : function() { this.waiting = true; this.indicator.style.width=0; hui.cls.add(this.element,this.WAITING); }, /** Reset the progress bar */ reset : function() { var el = this.element; if (this.waiting) { hui.cls.remove(el,this.WAITING); } hui.cls.remove(el,this.COMPLETE); this.indicator.style.width='0%'; }, /** Hide the progress bar */ hide : function() { this.element.style.display = 'none'; }, /** Show the progress bar */ show : function() { this.element.style.display = 'block'; } };