HTML_Progress
[ class tree: HTML_Progress ] [ index: HTML_Progress ] [ all elements ]
Prev Next

setScript Manual

defines the external JavaScript file to manage the progress bar

by by Laurent Laville
mailto:pear@laurent-laville.org
November 2003, Laurent Laville
(HTML_Progress 1.0+)

Synopsis

void setScript( $url )

Attributes

Name Type Default
url  file ressource   Null  

$url is an URL that identify a JavaScript file target.

Description

The setScript() method is used to identify an external JavaScript file, that will used to replace the default internal code, to manage the progress bar. If you have provided a custom javascript and want to revert to the built-in-behavior, set the URL back to null.

Example

Example below will produced a horizontal progress bar custom cell contents. It's a dynamic example, the progress bar will run.

  1. <?php
  2. require_once ('HTML/Progress.php');
  3.  
  4. $bar = new HTML_Progress();
  5. $bar->setAnimSpeed(100);
  6. $bar->setIncrement(10);
  7. $bar->setBorderPainted(true);
  8.  
  9. $ui =$bar->getUI();
  10. $ui->setCellAttributes(array(
  11.     'active-color' => '#3874B4',
  12.     'inactive-color' => '#EEEECC',
  13.     'width' => 10
  14. ));
  15. $ui->setBorderAttributes('width=1 color=navy');
  16. $ui->setStringAttributes(array(
  17.     'width' => 60,
  18.     'font-size' => 14,
  19.     'background-color' => '#EEEEEE',
  20.     'align' => 'center'
  21. ));
  22. $ui->setScript('progress.js');
  23.  
  24. foreach (range(0,2as $index{
  25.     $ui->setCellAttributes('color=silver'$index);
  26. }
  27. foreach (range(3,6as $index{
  28.     $ui->setCellAttributes('color=yellow'$index);
  29. }
  30. foreach (range(7,9as $index{
  31.     $ui->setCellAttributes('color=orange'$index);
  32. }
  33.  
  34. ?>
  35. <!DOCTYPE html
  36.     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  37.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  38.  
  39. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  40. <head>
  41. <title>Progress example</title>
  42. <style type="text/css">
  43. <!--
  44. <?php echo $bar->getStyle()?>
  45.  
  46. body {
  47.     background-color: #EEEEEE;
  48.     color: #000000;
  49.     font-family: Verdana, Arial;
  50. }
  51. // -->
  52. </style>
  53. <script type="text/javascript" src="<?php echo $bar->getScript()?>"></script>
  54. </head>
  55. <body>
  56.  
  57. <?php 
  58. echo $bar->toHtml()
  59.  
  60. do {
  61.     $bar->display();
  62.     if ($bar->getPercentComplete(== 1{
  63.         break;   // the progress bar has reached 100%
  64.     }
  65.     $bar->incValue();
  66. while(1);
  67. ?>
  68.  
  69. </body>
  70. </html>

JavaScript external code from file progress.js
var isDom = document.getElementById?true:false;
var isIE  = document.all?true:false;
var isNS4 = document.layers?true:false;
var cellCount = 10;

function setprogress(pIdent, pValue, pString, pDeterminate)
{
        if (isDom)
            prog = document.getElementById(pIdent+'installationProgress');
        if (isIE)
            prog = document.all[pIdent+'installationProgress'];
        if (isNS4)
            prog = document.layers[pIdent+'installationProgress'];
	if (prog != null) 
	    prog.innerHTML = pString;

        if (pValue == pDeterminate) {
	    for (i=0; i < cellCount; i++) {
                showCell(i, pIdent, "hidden");	
            }}
        if ((pDeterminate > 0) && (pValue > 0)) {
            i = (pValue-1) % cellCount;
            showCell(i, pIdent, "visible");	
        } else {
            for (i=pValue-1; i >=0; i--) {
                showCell(i, pIdent, "visible");	
                if (isDom)
                    document.getElementById(pIdent+'progressCell'+i+'A').innerHTML = i;
                if (isIE)
                    document.all[pIdent+'progressCell'+i+'A'].innerHTML = i;
                if (isNS4)
                    document.layers[pIdent+'progressCell'+i+'A'].innerHTML = i;
            }}
}

function showCell(pCell, pIdent, pVisibility)
{
	if (isDom)
	    document.getElementById(pIdent+'progressCell'+pCell+'A').style.visibility = pVisibility;
	if (isIE)
	    document.all[pIdent+'progressCell'+pCell+'A'].style.visibility = pVisibility;
	if (isNS4)
	    document.layers[pIdent+'progressCell'+pCell+'A'].style.visibility = pVisibility;

}
   

See Also

The HTML_Progress_UI::getScript() method is an easy way to build the default internal JavaScript code, that will manage the progress bar.

Prev   Next
setProgressAttributes Manual setStringPainted Manual

Documentation generated on Mon, 11 Mar 2019 10:15:06 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.