Progress bar class: centralize buffer clear method
Because browsers buffer size increased again I centralized the buffer clear flow. It now sends a 1024*256 bytes empty string before it runs an ob_flush and flush call. This should work with most browsers out there. Tested on macOS firefox/safari/chrome
This commit is contained in:
@@ -19,6 +19,8 @@ class ProgressBar
|
|||||||
public $status = 'new'; // current status (new,show,hide)
|
public $status = 'new'; // current status (new,show,hide)
|
||||||
public $step = 0; // current step
|
public $step = 0; // current step
|
||||||
public $position = array(); // current bar position
|
public $position = array(); // current bar position
|
||||||
|
|
||||||
|
public $clear_buffer_size = 1024*256; // we need to send this before the lfush to get browser output
|
||||||
|
|
||||||
// public vars
|
// public vars
|
||||||
|
|
||||||
@@ -78,6 +80,13 @@ class ProgressBar
|
|||||||
|
|
||||||
// private functions
|
// private functions
|
||||||
|
|
||||||
|
private function _flushCache()
|
||||||
|
{
|
||||||
|
echo str_repeat(' ', $this->clear_buffer_size);
|
||||||
|
ob_flush();
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
private function _calculatePercent($step)
|
private function _calculatePercent($step)
|
||||||
{
|
{
|
||||||
// avoid divison through 0
|
// avoid divison through 0
|
||||||
@@ -298,7 +307,7 @@ class ProgressBar
|
|||||||
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.align="'.$this->label[$name]['align'].'";';
|
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.align="'.$this->label[$name]['align'].'";';
|
||||||
$output .= '</script>'."\n";
|
$output .= '</script>'."\n";
|
||||||
echo $output;
|
echo $output;
|
||||||
flush();
|
$this->_flushCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,7 +317,7 @@ class ProgressBar
|
|||||||
if ($this->status != 'new')
|
if ($this->status != 'new')
|
||||||
{
|
{
|
||||||
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.color="'.$color.'";</script>'."\n";
|
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.color="'.$color.'";</script>'."\n";
|
||||||
flush();
|
$this->_flushCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,7 +327,7 @@ class ProgressBar
|
|||||||
if ($this->status != 'new')
|
if ($this->status != 'new')
|
||||||
{
|
{
|
||||||
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.background="'.$color.'";</script>'."\n";
|
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.background="'.$color.'";</script>'."\n";
|
||||||
flush();
|
$this->_flushCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +358,7 @@ class ProgressBar
|
|||||||
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-weight="'.$this->label[$name]['font-weight'].'";';
|
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-weight="'.$this->label[$name]['font-weight'].'";';
|
||||||
$output .= '</script>'."\n";
|
$output .= '</script>'."\n";
|
||||||
echo $output;
|
echo $output;
|
||||||
flush();
|
$this->_flushCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,7 +369,7 @@ class ProgressBar
|
|||||||
if ($this->status != 'new')
|
if ($this->status != 'new')
|
||||||
{
|
{
|
||||||
echo '<script type="text/JavaScript">PBlabelText'.$this->code.'("'.$name.'","'.$this->label[$name]['value'].'");</script>'."\n";
|
echo '<script type="text/JavaScript">PBlabelText'.$this->code.'("'.$name.'","'.$this->label[$name]['value'].'");</script>'."\n";
|
||||||
flush();
|
$this->_flushCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,7 +379,7 @@ class ProgressBar
|
|||||||
if ($this->status != 'new')
|
if ($this->status != 'new')
|
||||||
{
|
{
|
||||||
echo '<script type="text/JavaScript">document.getElementById("pbar'.$this->code.'").style.background="'.$color.'";</script>'."\n";
|
echo '<script type="text/JavaScript">document.getElementById("pbar'.$this->code.'").style.background="'.$color.'";</script>'."\n";
|
||||||
flush();
|
$this->_flushCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +389,7 @@ class ProgressBar
|
|||||||
if ($this->status != 'new')
|
if ($this->status != 'new')
|
||||||
{
|
{
|
||||||
echo '<script type="text/JavaScript">document.getElementById("pbrd'.$this->code.'").style.background="'.$color.'";</script>'."\n";
|
echo '<script type="text/JavaScript">document.getElementById("pbrd'.$this->code.'").style.background="'.$color.'";</script>'."\n";
|
||||||
flush();
|
$this->_flushCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,7 +407,7 @@ class ProgressBar
|
|||||||
echo 'PBposition'.$this->code.'("width",'.$this->position['width'].');';
|
echo 'PBposition'.$this->code.'("width",'.$this->position['width'].');';
|
||||||
echo 'PBposition'.$this->code.'("height",'.$this->position['height'].');';
|
echo 'PBposition'.$this->code.'("height",'.$this->position['height'].');';
|
||||||
echo '</script>'."\n";
|
echo '</script>'."\n";
|
||||||
flush();
|
$this->_flushCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,7 +556,7 @@ class ProgressBar
|
|||||||
{
|
{
|
||||||
$this->status = 'show';
|
$this->status = 'show';
|
||||||
echo $this->getHtml();
|
echo $this->getHtml();
|
||||||
flush();
|
$this->_flushCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function moveStep($step)
|
public function moveStep($step)
|
||||||
@@ -603,7 +612,7 @@ class ProgressBar
|
|||||||
if ($js != '')
|
if ($js != '')
|
||||||
{
|
{
|
||||||
echo '<script type="text/JavaScript">'.$js.'</script>'."\n";
|
echo '<script type="text/JavaScript">'.$js.'</script>'."\n";
|
||||||
flush();
|
$this->_flushCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,7 +636,7 @@ class ProgressBar
|
|||||||
$output .= 'document.getElementById("pbm'.$this->code.'").style.visibility="hidden";document.getElementById("pbm'.$this->code.'").style.display="none";';
|
$output .= 'document.getElementById("pbm'.$this->code.'").style.visibility="hidden";document.getElementById("pbm'.$this->code.'").style.display="none";';
|
||||||
$output .= '</script>'."\n";
|
$output .= '</script>'."\n";
|
||||||
echo $output;
|
echo $output;
|
||||||
flush();
|
$this->_flushCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,7 +650,7 @@ class ProgressBar
|
|||||||
$output .= 'document.getElementById("pbm'.$this->code.'").style.visibility="visible";document.getElementById("pbm'.$this->code.'").style.visibility="block";';
|
$output .= 'document.getElementById("pbm'.$this->code.'").style.visibility="visible";document.getElementById("pbm'.$this->code.'").style.visibility="block";';
|
||||||
$output .= '</script>'."\n";
|
$output .= '</script>'."\n";
|
||||||
echo $output;
|
echo $output;
|
||||||
flush();
|
$this->_flushCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user