[903] | 1 | // xp_progressbar
|
---|
| 2 | // Copyright 2004 Brian Gosselin of ScriptAsylum.com
|
---|
| 3 | //
|
---|
| 4 | // v1.0 - Initial release
|
---|
| 5 | // v1.1 - Added ability to pause the scrolling action (requires you to assign
|
---|
| 6 | // the bar to a unique arbitrary variable).
|
---|
| 7 | // - Added ability to specify an action to perform after a x amount of
|
---|
| 8 | // - bar scrolls. This requires two added arguments.
|
---|
| 9 | // v1.2 - Added ability to hide/show each bar (requires you to assign the bar
|
---|
| 10 | // to a unique arbitrary variable).
|
---|
| 11 |
|
---|
| 12 | // var xyz = createBar(
|
---|
| 13 | // total_width,
|
---|
| 14 | // total_height,
|
---|
| 15 | // background_color,
|
---|
| 16 | // border_width,
|
---|
| 17 | // border_color,
|
---|
| 18 | // block_color,
|
---|
| 19 | // scroll_speed,
|
---|
| 20 | // block_count,
|
---|
| 21 | // scroll_count,
|
---|
| 22 | // action_to_perform_after_scrolled_n_times
|
---|
| 23 | // )
|
---|
| 24 |
|
---|
| 25 | var w3c=(document.getElementById)?true:false;
|
---|
| 26 | var ie=(document.all)?true:false;
|
---|
| 27 | var N=-1;
|
---|
| 28 | var progressBar;
|
---|
| 29 |
|
---|
| 30 | function createBar(w,h,bgc,brdW,brdC,blkC,speed,blocks,count,action, top, left){
|
---|
| 31 |
|
---|
| 32 | if(ie||w3c){
|
---|
| 33 | var t='<div id="_xpbar'+(++N)+'" style="visibility:hidden; position:relative; overflow:hidden; width:'+w+'px; height:'+h+'px; background-color:'+bgc+'; border-color:'+brdC+'; top:'+top+';left:'+left+';border-width:'+brdW+'px; border-style:solid; font-size:1px;">';
|
---|
| 34 | t+='<span id="blocks'+N+'" style="left:-'+(h*2+1)+'px; position:absolute; font-size:1px">';
|
---|
| 35 | for(i=0;i<blocks;i++){
|
---|
| 36 | t+='<span style="background-color:'+blkC+'; left:-'+((h*i)+i)+'px; font-size:1px; position:absolute; width:'+h+'px; height:'+h+'px; '
|
---|
| 37 | t+=(ie)?'filter:alpha(opacity='+(100-i*(100/blocks))+')':'-Moz-opacity:'+((100-i*(100/blocks))/100);
|
---|
| 38 | t+='"></span>';
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | t+='</span></div>';
|
---|
| 42 | document.write(t);
|
---|
| 43 | var bA=(ie)?document.all['blocks'+N]:document.getElementById('blocks'+N);
|
---|
| 44 | bA.bar=(ie)?document.all['_xpbar'+N]:document.getElementById('_xpbar'+N);
|
---|
| 45 | bA.blocks=blocks;
|
---|
| 46 | bA.N=N;
|
---|
| 47 | bA.w=w;
|
---|
| 48 | bA.h=h;
|
---|
| 49 | bA.speed=speed;
|
---|
| 50 | bA.ctr=0;
|
---|
| 51 | bA.count=count;
|
---|
| 52 | bA.action=action;
|
---|
| 53 | bA.togglePause=togglePause;
|
---|
| 54 | bA.showBar=function(){
|
---|
| 55 | this.bar.style.visibility="visible";
|
---|
| 56 | }
|
---|
| 57 | bA.hideBar=function(){
|
---|
| 58 | this.bar.style.visibility="hidden";
|
---|
| 59 | }
|
---|
| 60 | bA.tid=setInterval('startBar('+N+')',speed);
|
---|
| 61 | this.progressBar = bA;
|
---|
| 62 | return bA;
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | function startBar(bn){
|
---|
| 67 | var t=(ie)?document.all['blocks'+bn]:document.getElementById('blocks'+bn);
|
---|
| 68 | if(parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w) {
|
---|
| 69 | t.style.left=-(t.h*2+1)+'px';
|
---|
| 70 | t.ctr++;
|
---|
| 71 | if(t.ctr>=t.count) {
|
---|
| 72 | eval(t.action);
|
---|
| 73 | t.ctr=0;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | else
|
---|
| 77 | t.style.left=(parseInt(t.style.left)+t.h+1)+'px';
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | function togglePause() {
|
---|
| 81 | if(this.tid==0) {
|
---|
| 82 | this.tid=setInterval('startBar('+this.N+')',this.speed);
|
---|
| 83 | }
|
---|
| 84 | else {
|
---|
| 85 | clearInterval(this.tid);
|
---|
| 86 | this.tid=0;
|
---|
| 87 | }
|
---|
| 88 | } |
---|