From cdcab5593311b4bdec2b54c070d9f6133b95aaa7 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Fri, 13 May 2016 21:50:30 +0200 Subject: Multiple updates --- include/classes/BigPipe/BigPipe.php | 22 ++++++++++++---------- include/classes/BigPipe/Pagelet.php | 30 +++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 19 deletions(-) (limited to 'include/classes/BigPipe') diff --git a/include/classes/BigPipe/BigPipe.php b/include/classes/BigPipe/BigPipe.php index 39a812d..8cdda0b 100755 --- a/include/classes/BigPipe/BigPipe.php +++ b/include/classes/BigPipe/BigPipe.php @@ -33,21 +33,23 @@ class BigPipe { # Prints a single pagelet response #=============================================================================== private static function singleResponse(Pagelet $Pagelet, $last = FALSE) { - $data = [ + $pageletJSON = [ 'ID' => $Pagelet->getID(), 'RESOURCES' => ['CSS' => $Pagelet->getCSSFiles(), 'JS' => $Pagelet->getJSFiles(), 'JS_CODE' => removeLineBreaksAndTabs($Pagelet->getJSCode())], - 'PHASES' => (object) $Pagelet->getPhaseDoneJS(), + 'PHASES' => (object) $Pagelet->getPhaseDoneJS() ]; if($last) { - $data['IS_LAST'] = true; + $pageletJSON['IS_LAST'] = true; } - $pageletHTML = str_replace('--', '--', removeLineBreaksAndTabs($Pagelet->getHTML())); - $pageletJSON = json_encode($data, (self::$debug ? JSON_PRETTY_PRINT : FALSE)); + $pageletHTML = removeLineBreaksAndTabs($Pagelet->getHTML()); + $pageletHTML = str_replace('--', '--', $pageletHTML); + + $pageletJSON = json_encode($pageletJSON, (self::$debug ? JSON_PRETTY_PRINT : NULL)); echo "getID()}\">\n"; - echo "\n\n"; + echo "\n\n"; } #=============================================================================== @@ -71,15 +73,15 @@ class BigPipe { foreach($pagelets as $Pagelet) { if(!self::isEnabled()) { foreach($Pagelet->getCSSFiles() as $CSSFile) { - echo ''."\n"; + echo "\n"; } foreach($Pagelet->getJSFiles() as $JSFile) { - echo ''."\n"; + echo "\n"; } - if($Pagelet->getJSCode()) { - echo ''."\n"; + foreach($Pagelet->getJSCode() as $JSCode) { + echo "\n"; } } diff --git a/include/classes/BigPipe/Pagelet.php b/include/classes/BigPipe/Pagelet.php index 36b13ea..22aadce 100755 --- a/include/classes/BigPipe/Pagelet.php +++ b/include/classes/BigPipe/Pagelet.php @@ -4,10 +4,11 @@ namespace BigPipe; class Pagelet { private $ID = NULL; private $HTML = ''; - private $JSCode = ''; + private $JSCode = []; private $JSFiles = []; private $CSSFiles = []; private $phaseDoneJS = []; + private $tagname = 'div'; private static $count = 0; #=============================================================================== @@ -29,7 +30,7 @@ class Pagelet { const PHASE_EXECJS = 4; # After the static JS code has been executed public function __construct($customID = NULL, $priority = self::PRIORITY_NORMAL) { - $this->phaseDoneJS = array_pad([], 5, []); + $this->phaseDoneJS = array_pad($this->phaseDoneJS, 5, []); $this->ID = is_string($customID) ? $customID : 'P'.++self::$count; BigPipe::addPagelet($this, $priority); @@ -80,22 +81,22 @@ class Pagelet { #=============================================================================== # Attach a CSS resource #=============================================================================== - public function addCSS($file) { - return $this->CSSFiles[] = $file; + public function addCSS($href) { + return $this->CSSFiles[] = $href; } #=============================================================================== # Attach a JS resource #=============================================================================== - public function addJS($file) { - return $this->JSFiles[] = $file; + public function addJS($href) { + return $this->JSFiles[] = $href; } #=============================================================================== - # Add JS code or attach more + # Attach a main JS code part #=============================================================================== public function addJSCode($code) { - return $this->JSCode .= $code; + return $this->JSCode[] = $code; } #=============================================================================== @@ -112,10 +113,21 @@ class Pagelet { return $this->phaseDoneJS; } + #=============================================================================== + # Set custom placeholder tagname + #=============================================================================== + public function setTagname($tagname) { + return $this->tagname = $tagname; + } + #=============================================================================== # Magic method: __toString() #=============================================================================== public function __toString() { - return '
'.((!BigPipe::isEnabled()) ? $this->getHTML() : NULL).'
'; + $pageletHTML = "<{$this->tagname} id=\"{$this->getID()}\">"; + $pageletHTML .= !BigPipe::isEnabled() ? $this->getHTML() : NULL; + $pageletHTML .= "tagname}>"; + + return $pageletHTML; } } \ No newline at end of file -- cgit v1.2.3