webglade

JavaScript library to dynamically create XUL GUI from Glade XML files
git clone https://logand.com/git/webglade.git/
Log | Files | Refs | README | LICENSE

ProgressBar.js (2459B)


      1 /**
      2 *
      3 * Undetermined Progress Meter have to be emulated using the determined one,
      4 * because it doesn't work correctly in every platform and with every skins.
      5 * Ie: FireFox 0.8 doesn't have the undetermined progressmeter.
      6 *
      7 * @FileName: ProgressBar.js
      8 * @$LastChangedDate: 2004-06-26 13:51:10 +0200 (Sat, 26 Jun 2004) $
      9 * @Author: Fabio Serra AKA Faser - faser@faser.net
     10 * @Copyright: Fabio Serra
     11 * @Licenze: MPL 1.1
     12 *
     13 */
     14 
     15 function ProgressBar(elProgressMeter,busyCursor) {
     16 	//Reference to the ProgressMeter widget
     17 	this.guiMeter = elProgressMeter;
     18 
     19 	//Automatically activate Busy Cursor
     20 	if(!busyCursor) {
     21 		this.busyCursor = false;
     22 	} else {
     23 		this.busyCursor = true;
     24 	}
     25 	this.refresh = 500;
     26 	this.timeStart = null;
     27 	this.timeStop = null;
     28 }
     29 
     30 ProgressBar.prototype.start = function() {
     31 	this.timeStart = new Date();
     32 	if(this.busyCursor) {
     33 		this.setBusyCursor(true);
     34 	}
     35 
     36 	this.intervalID =  setInterval(this.increment,this.refresh);
     37 }
     38 
     39 //Increment the ProgressMeter. When it arrives to 100 back to 10
     40 ProgressBar.prototype.increment = function() {
     41 	var curValue = parseInt(this.guiMeter.getAttribute('value'));
     42 
     43 	if(curValue >= 100) {
     44 		curValue = 10;
     45 
     46 	}else{
     47 		curValue +=10;
     48 	}
     49 
     50 	this.guiMeter.setAttribute('value',curValue + "%");
     51 }
     52 
     53 //Stop ProgressMeter. Fill in all the bar and then go to 0%
     54 ProgressBar.prototype.stop = function() {
     55 
     56 	if(this.busyCursor) {this.setBusyCursor(false);}
     57 
     58 	if(!this.intervalID) {
     59 		this.guiMeter.setAttribute('value',0+"%");
     60 		return;
     61 	}
     62 
     63 	clearInterval(this.intervalID);
     64 
     65 	this.guiMeter.setAttribute('value',100+"%");
     66 
     67 	var resetProgressMeter = function() {
     68 		this.guiMeter.setAttribute('value',0+"%");
     69 	}
     70 	setTimeout(resetProgressMeter,this.refresh);
     71 	this.timeStop = new Date();
     72 }
     73 
     74 //Return elapsed time from the start to the final stop in seconds
     75 ProgressBar.prototype.getElapsedTime = function() {
     76 	if(!this.timeStart || !this.timeStop) return false;
     77 	var elapsedTime = ((this.timeStop  - this.timeStart) + this.refresh)/1000;
     78 	return elapsedTime;
     79 }
     80 
     81 ProgressBar.prototype.setBusyCursor = function(enable) {
     82 	if((typeof window.setCursor == "undefined") || (typeof window.setCursor != "function"))	 {
     83 		return false;
     84 	}
     85 
     86 	var numFrames = window.frames.length;
     87 	for(var i = 0; i < numFrames; i++) {
     88 		if(enable) {
     89 			window.frames[i].setCursor("wait");
     90 		}else{
     91 			window.frames[i].setCursor("auto");
     92 		}
     93 	}
     94 
     95 	return true;
     96  }