« | Home | »

jsProgressBarHandler 0.3.3

jsprogressbarhandlerajax.jpgA new version of jsProgressBarHandler is available. Changes are two bugfixes, an update of the Prototype loading mechanism and the addition of image preloading and the support for a callback function (named onTick

What is jsProgressBarHandler all about?

jsProgressBarHandler is a Javascript based Percentage Bar / Progress Bar, inspired upon JS-code by WebAppers and CSS-code by Bare Naked App. Version 0.1 was a mere rewrite to PrototypeJS of the version by WebAppers whilst version 0.2 was a full structural rewrite. Version 0.3 builds upon 0.2 by making it all more robust.

So, what has changed?

This release adds a few new features such as the support to preloading the used images (see extra note below) and the addition of a a callback function. This callback function (named onTick and passed in via the options Object) is called whenever the value of the progressBar has changed, allowing you - the user - to hook your own functionality to progressBars whenever a certain value is passed/reached.

An example of an onTick function would be this one:

JavaScript:
  1. demoPB = new JS_BRAMUS.jsProgressBar(
  2.     $('theElementToReplace'), // the element to create the progressbar in
  3.     0, // initial percentage
  4.     { // options
  5.         onTick : function(pbObj) { // options.onTick
  6.  
  7.             switch(pbObj.getPercentage()) {
  8.  
  9.                 case 50:
  10.                     alert('Halfway');
  11.                 break;
  12.  
  13.                 case 95:
  14.                     alert('Nearly full!');
  15.                 break;
  16.  
  17.                 case 99:
  18.                     return false;
  19.                 break;
  20.  
  21.             }
  22.  
  23.             // important to return true or counting will stop!
  24.             return true;
  25.         }
  26.     }
  27. );

When the progressBar is now set to 100% (and with animation on) a warning will be shown at 50% and at 95%. Above that the 100 mark will not be reached, as false is returned at 99% (yes, it's possible for you to break the counting/ticking from within the onTick callback). When animation is off and setPercentage is called to 100, it will immediately skip to 100%.

Regarding the preloading feature, it should be noted that after having spent several hours in all IEs (6 up to 8b2) and all other browsers I've decided to ditch the preloading aspect in IE, as it's really quirky. Yes that's correct: preloading only works in all browsers but IE (viz. it works in Firefox, Safari, Opera, ...)

Next to that two bugs that were found (thank you commenters Kevin and Jack) were fixed, improving compatibility with IE and preventing a possible infinite loop.

Anything else has changed?

Internally, the code that is used to attach the progressBars to the page was moved from the window its load event to the Prototype's implementation of the dom:loaded event of the document. As a result the progressBars get inited faster.

Above that some extra styling options were added: the outputted percentage image now has a class percentImage and the outputted percentage text now has class percentText, allowing you to style them easily.

Whatever happened to 0.3.2?

Work on the preloading feature once started in April 2008, but was never finished (as IE decided to throw in some errors and time was short). Now - 7 months later - I found time again to work on the project and finish what I started back then. With this I decided to skip a version as the previous work already was archived as 0.3.2

Cool, is there a demo?

jsProgressBarHandler Demo

TIP: At the multicolor bar at the bottom, click that -icon a few times to see the internal queue in effect ;)

Please note that next to the demo above even an AJAX demo exists!

Where can I download it?

Right here:

Wow, you're going to fast: I have a question, I need help, I need more info, how do I configure this thing?

Spread the word!

  • del.icio.us
  • digg
  • Ma.gnolia

About this entry

Best of Bram.us