From adcfaf5fa07a11c6ecd2cc8b67803b5819ba1452 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 13 Apr 2017 14:28:43 +0900 Subject: [PATCH] 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 --- www/libs/Class.Progressbar.inc | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/www/libs/Class.Progressbar.inc b/www/libs/Class.Progressbar.inc index f0f92106..ecc4436e 100644 --- a/www/libs/Class.Progressbar.inc +++ b/www/libs/Class.Progressbar.inc @@ -19,6 +19,8 @@ class ProgressBar public $status = 'new'; // current status (new,show,hide) public $step = 0; // current step 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 @@ -78,6 +80,13 @@ class ProgressBar // private functions + private function _flushCache() + { + echo str_repeat(' ', $this->clear_buffer_size); + ob_flush(); + flush(); + } + private function _calculatePercent($step) { // avoid divison through 0 @@ -298,7 +307,7 @@ class ProgressBar $output .= 'document.getElementById("plbl'.$name.$this->code.'").style.align="'.$this->label[$name]['align'].'";'; $output .= ''."\n"; echo $output; - flush(); + $this->_flushCache(); } } @@ -308,7 +317,7 @@ class ProgressBar if ($this->status != 'new') { echo ''."\n"; - flush(); + $this->_flushCache(); } } @@ -318,7 +327,7 @@ class ProgressBar if ($this->status != 'new') { echo ''."\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 .= ''."\n"; echo $output; - flush(); + $this->_flushCache(); } } @@ -360,7 +369,7 @@ class ProgressBar if ($this->status != 'new') { echo ''."\n"; - flush(); + $this->_flushCache(); } } @@ -370,7 +379,7 @@ class ProgressBar if ($this->status != 'new') { echo ''."\n"; - flush(); + $this->_flushCache(); } } @@ -380,7 +389,7 @@ class ProgressBar if ($this->status != 'new') { echo ''."\n"; - flush(); + $this->_flushCache(); } } @@ -398,7 +407,7 @@ class ProgressBar echo 'PBposition'.$this->code.'("width",'.$this->position['width'].');'; echo 'PBposition'.$this->code.'("height",'.$this->position['height'].');'; echo ''."\n"; - flush(); + $this->_flushCache(); } } @@ -547,7 +556,7 @@ class ProgressBar { $this->status = 'show'; echo $this->getHtml(); - flush(); + $this->_flushCache(); } public function moveStep($step) @@ -603,7 +612,7 @@ class ProgressBar if ($js != '') { echo ''."\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 .= ''."\n"; 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 .= ''."\n"; echo $output; - flush(); + $this->_flushCache(); } }