Added progress bar class
This commit is contained in:
parent
a988babb77
commit
629114bac5
9 changed files with 114 additions and 110 deletions
110
JsPHP.php
110
JsPHP.php
|
|
@ -1,110 +0,0 @@
|
||||||
<?php
|
|
||||||
//created by Ziver koc. Nice hu
|
|
||||||
// Too make this work you must have echoed out html and the body tags
|
|
||||||
//********* GLOBAL **********************
|
|
||||||
$progressInit = false;
|
|
||||||
$progressNextId = 0;
|
|
||||||
//**************************************
|
|
||||||
// Example of use
|
|
||||||
echo"<html><body><center>";
|
|
||||||
progressBarInit(550, 16, "img/bar-grey.gif", "img/bar-life.gif");
|
|
||||||
progressBarInit(550, 16, "img/bar-grey.gif", "img/bar-mana.gif");
|
|
||||||
progressBarInit(550, 16, "img/bar-grey.gif", "img/bar-life.gif");
|
|
||||||
progressBarInit(550, 16, "img/bar-grey.gif", "img/bar-mana.gif");
|
|
||||||
for($i=0;$i<=100;$i+=2){
|
|
||||||
sleep(1);
|
|
||||||
progressSetValue($i);
|
|
||||||
progressSetText($i."%");
|
|
||||||
progressSetValue($i/2,1);
|
|
||||||
progressSetText(($i/2)."%",1);
|
|
||||||
progressSetValue($i/4,2);
|
|
||||||
progressSetText(($i/4)."%",2);
|
|
||||||
progressSetValue($i/3,3);
|
|
||||||
progressSetText(($i/3)."%",3);
|
|
||||||
//echo $i."% > ";
|
|
||||||
}
|
|
||||||
echo"</center></body></html>";
|
|
||||||
redirect("http://google.com");
|
|
||||||
|
|
||||||
function progressBarInit($width, $height, $imgBar, $imgProggress){
|
|
||||||
GLOBAL $progressInit, $progressNextId;
|
|
||||||
if(!$progressInit){
|
|
||||||
echo"
|
|
||||||
<script type='text/javascript'>
|
|
||||||
<!--
|
|
||||||
function setValue(id,value){
|
|
||||||
document.getElementById('progressValue'+id).style.width = value+'%';
|
|
||||||
}
|
|
||||||
function setText(id,text){
|
|
||||||
document.getElementById('progressText'+id).innerHTML = text;
|
|
||||||
}
|
|
||||||
//-->
|
|
||||||
</script>";
|
|
||||||
$progressInit = true;
|
|
||||||
}
|
|
||||||
$id = $progressNextId;
|
|
||||||
$progressNextId++;
|
|
||||||
echo"
|
|
||||||
<style type='text/css'>
|
|
||||||
.progress".$id."{
|
|
||||||
background: transparent url(".$imgBar.") repeat-x scroll 0%;
|
|
||||||
border: 1px solid black;
|
|
||||||
color: white;
|
|
||||||
height: ".$height."px;
|
|
||||||
margin: 5pt;
|
|
||||||
padding: 0pt;
|
|
||||||
position: relative;
|
|
||||||
text-align: center;
|
|
||||||
width: ".$width."px;
|
|
||||||
border-collapse: collapse;
|
|
||||||
}
|
|
||||||
#progressValue".$id."{
|
|
||||||
background: transparent url(".$imgProggress.") repeat-x scroll 0%;
|
|
||||||
float: left;
|
|
||||||
height: ".$height."px;
|
|
||||||
margin: 0pt;
|
|
||||||
padding: 0pt;
|
|
||||||
font-size: 11px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<div class='progress".$id."'>
|
|
||||||
<div id='progressValue".$id."' style='width: 0%' >
|
|
||||||
<span id='progressText".$id."'></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
";
|
|
||||||
flush();
|
|
||||||
return $id;
|
|
||||||
}
|
|
||||||
function progressSetValue($value,$id=0){
|
|
||||||
echo"
|
|
||||||
<script type='text/javascript'>
|
|
||||||
<!--
|
|
||||||
setValue(".$id.",".$value.");
|
|
||||||
//-->
|
|
||||||
</script>
|
|
||||||
";
|
|
||||||
flush();
|
|
||||||
}
|
|
||||||
function progressSetText($text,$id=0){
|
|
||||||
echo"
|
|
||||||
<script type='text/javascript'>
|
|
||||||
<!--
|
|
||||||
setText(".$id.",'".$text."');
|
|
||||||
//-->
|
|
||||||
</script>
|
|
||||||
";
|
|
||||||
flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
function redirect($url){
|
|
||||||
echo"
|
|
||||||
<script type='text/javascript'>
|
|
||||||
<!--
|
|
||||||
window.location = '".$url."';
|
|
||||||
//-->
|
|
||||||
</script>
|
|
||||||
";
|
|
||||||
flush();
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
91
class/PHPProgressBar.php
Normal file
91
class/PHPProgressBar.php
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
<?php
|
||||||
|
//created by Ziver koc. Nice hu
|
||||||
|
// Too make this work you must have echoed out html and the body tags
|
||||||
|
class PHPProgressBar{
|
||||||
|
//********* STATIC **********************
|
||||||
|
public static $progressInit = false;
|
||||||
|
public static $progressNextId = 0;
|
||||||
|
//**************************************
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
public function __construct($width, $height, $imgBar, $imgProggress){
|
||||||
|
if(!self::$progressInit){
|
||||||
|
echo"
|
||||||
|
<script type='text/javascript'>
|
||||||
|
<!--
|
||||||
|
function setValue(id,value){
|
||||||
|
document.getElementById('progressValue'+id).style.width = value+'%';
|
||||||
|
}
|
||||||
|
function setText(id,text){
|
||||||
|
document.getElementById('progressText'+id).innerHTML = text;
|
||||||
|
}
|
||||||
|
//-->
|
||||||
|
</script>";
|
||||||
|
self::$progressInit = true;
|
||||||
|
}
|
||||||
|
$this->id = self::$progressNextId;
|
||||||
|
self::$progressNextId++;
|
||||||
|
echo"
|
||||||
|
<style type='text/css'>
|
||||||
|
.progress".$this->id."{
|
||||||
|
background: transparent url(".$imgBar.") repeat-x scroll 0%;
|
||||||
|
border: 1px solid black;
|
||||||
|
color: white;
|
||||||
|
height: ".$height."px;
|
||||||
|
margin: 5pt;
|
||||||
|
padding: 0pt;
|
||||||
|
position: relative;
|
||||||
|
text-align: center;
|
||||||
|
width: ".$width."px;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
#progressValue".$this->id."{
|
||||||
|
background: transparent url(".$imgProggress.") repeat-x scroll 0%;
|
||||||
|
float: left;
|
||||||
|
height: ".$height."px;
|
||||||
|
margin: 0pt;
|
||||||
|
padding: 0pt;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div class='progress".$this->id."'>
|
||||||
|
<div id='progressValue".$this->id."' style='width: 0%' >
|
||||||
|
<span id='progressText".$this->id."'></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
";
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
public function setValue($value){
|
||||||
|
echo"
|
||||||
|
<script type='text/javascript'>
|
||||||
|
<!--
|
||||||
|
setValue(".$this->id.",".$value.");
|
||||||
|
//-->
|
||||||
|
</script>
|
||||||
|
";
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
public function setText($text){
|
||||||
|
echo"
|
||||||
|
<script type='text/javascript'>
|
||||||
|
<!--
|
||||||
|
setText(".$this->id.",'".$text."');
|
||||||
|
//-->
|
||||||
|
</script>
|
||||||
|
";
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function redirect($url){
|
||||||
|
echo"
|
||||||
|
<script type='text/javascript'>
|
||||||
|
<!--
|
||||||
|
window.location = '".$url."';
|
||||||
|
//-->
|
||||||
|
</script>
|
||||||
|
";
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
BIN
img/progressbarcenter.jpg
Normal file
BIN
img/progressbarcenter.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 657 B |
BIN
img/progressbarleft.jpg
Normal file
BIN
img/progressbarleft.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 676 B |
BIN
img/progressbarright.jpg
Normal file
BIN
img/progressbarright.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 676 B |
BIN
img/progresscenter.jpg
Normal file
BIN
img/progresscenter.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 661 B |
BIN
img/progressleft.jpg
Normal file
BIN
img/progressleft.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 637 B |
BIN
img/progressright.jpg
Normal file
BIN
img/progressright.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 637 B |
23
test/phpprogressbar.php
Normal file
23
test/phpprogressbar.php
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
require_once("../class/PHPProgressBar.php");
|
||||||
|
// Example of use
|
||||||
|
echo"<html><body><center>";
|
||||||
|
$p1 = new PHPProgressBar(550, 16, "../img/bar-grey.gif", "../img/bar-life.gif");
|
||||||
|
$p2 = new PHPProgressBar(550, 16, "../img/bar-grey.gif", "../img/bar-mana.gif");
|
||||||
|
$p3 = new PHPProgressBar(550, 16, "../img/bar-grey.gif", "../img/bar-life.gif");
|
||||||
|
$p4 = new PHPProgressBar(550, 16, "../img/bar-grey.gif", "../img/bar-mana.gif");
|
||||||
|
for($i=0;$i<=100;$i+=2){
|
||||||
|
sleep(1);
|
||||||
|
$p1->setValue($i);
|
||||||
|
$p1->setText($i."%");
|
||||||
|
$p2->setValue($i/2,1);
|
||||||
|
$p2->setText(($i/2)."%",1);
|
||||||
|
$p3->setValue($i/4,2);
|
||||||
|
$p3->setText(($i/4)."%",2);
|
||||||
|
$p4->setValue($i/3,3);
|
||||||
|
$p4->setText(($i/3)."%",3);
|
||||||
|
//echo $i."% > ";
|
||||||
|
}
|
||||||
|
echo"</center></body></html>";
|
||||||
|
$p1->redirect("http://google.com");
|
||||||
|
?>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue