function ProgressBar(steps, parent, styling){ this.parent = parent ? parent : null; this.steps = steps; this.styling = ProgressBar.styling; if(styling){ Object.extend(this.styling, styling); } this.stepWidthErr = 0; this.stepCount = 0; this.stepLeft = 0; this.stepWidth = this.styling.width / this.steps; this.onstep = new DOMEvent(); this.complete = false; this.oncomplete = new DOMEvent(); this.oncomplete.register("default-complete", ProgressBar.defOnComplete.bind(this)); this.visible = this.parent ? true : false; } ProgressBar.prototype.init = function(){ if(this.visible){ this.createBar(); this.createTextDiv(); } } ProgressBar.prototype.createBar = function(){ this.bar = Element('DIV', this.styling); this.parent.appendChild(this.bar); } ProgressBar.prototype.createTextDiv = function(){ var tDivStyle = { width: "100%", height: "100%", position: "relative", "z-index": "1000" } this.textDiv = Element("DIV", tDivStyle); this.textDiv.appendChild(document.createTextNode(ProgressBar.loadingText)); this.bar.appendChild(this.textDiv); } ProgressBar.prototype.createStep = function(){ var width = Math.floor(this.stepWidth); var err = this.stepWidth - width; this.stepWidthErr += err; if(this.stepWidthErr > 1){ width++; this.stepWidthErr -= 1; } var stepStyling = { width: width, left: this.stepLeft } Object.extend(stepStyling, ProgressBar.stepStyling); var step = Element("DIV", stepStyling); this.bar.appendChild(step); this.stepLeft += width; } ProgressBar.prototype.nextStep = function(){ if(this.visible && !this.bar){ this.init(); } if(this.stepCount == this.steps && this.complete) return; if(this.visible){ this.createStep(); } this.stepCount ++; this.onstep.fire(); if(this.stepCount == this.steps){ this.complete = true; this.oncomplete.fire(); } } ProgressBar.prototype.f = function(){ } ProgressBar.stepStyling = { height: "100%", position: "absolute", "background-color": "green", top: 0 } ProgressBar.styling = { width: 150, height: 25, color: "red", border: "solid 1px yellow", "background-color": "blue", font: "12px Arial", position: "relative", "text-align": "center" } ProgressBar.defOnComplete = function(objInt){ if(objInt){ clearInterval(objInt); } if(this.visible){ this.textDiv.removeChild(this.textDiv.firstChild); this.textDiv.appendChild(document.createTextNode(ProgressBar.completeText)); } } ProgressBar.loadingText = "loading..."; ProgressBar.completeText = "Complete!";