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
url file ressource

$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. <!DOCTYPE html
  35.     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  36.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  37.  
  38. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  39. <head>
  40. <title>setScript example</title>
  41. <style type="text/css">
  42. <!--
  43. <?php echo $bar->getStyle()?>
  44.  
  45. body {
  46.     background-color: #EEEEEE;
  47.     color: #000000;
  48.     font-family: Verdana, Arial;
  49. }
  50. // -->
  51. </style>
  52. <script type="text/javascript" src="<?php echo $bar->getScript()?>"></script>
  53. </head>
  54. <body>
  55.  
  56. <?php 
  57. echo $bar->toHtml()
  58.  
  59. do {
  60.     $bar->display();
  61.     if ($bar->getPercentComplete(== 1{
  62.         break;   // the progress bar has reached 100%
  63.     }
  64.     $bar->incValue();
  65. while(1);
  66. ?>
  67.  
  68. </body>
  69. </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

getScript Manual

Prev Up Next
getScript Manual Reference Guides getStyle Manual

Documentation generated on Mon, 11 Mar 2019 13:52:35 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.