Exemple #1
0
 /**
  * Allow event listeners to add scripts to
  * - </head> : onPageDisplay_headClose
  * - <body>  : onPageDisplay_bodyOpen
  * - </body> : onPageDisplay_bodyClose.
  *
  * @param Events\PageDisplayEvent $event
  */
 public function onPageDisplay(Events\PageDisplayEvent $event)
 {
     $content = $event->getContent();
     // Get scripts to insert before </head>
     ob_start();
     $this->assetsHelper->outputScripts('onPageDisplay_headClose');
     $headCloseScripts = ob_get_clean();
     if ($headCloseScripts) {
         $content = str_ireplace('</head>', $headCloseScripts . "\n</head>", $content);
     }
     // Get scripts to insert after <body>
     ob_start();
     $this->assetsHelper->outputScripts('onPageDisplay_bodyOpen');
     $bodyOpenScripts = ob_get_clean();
     if ($bodyOpenScripts) {
         preg_match('/(<body[a-z=\\s\\-_:"\']*>)/i', $content, $matches);
         $content = str_ireplace($matches[0], $matches[0] . "\n" . $bodyOpenScripts, $content);
     }
     // Get scripts to insert before </body>
     ob_start();
     $this->assetsHelper->outputScripts('onPageDisplay_bodyClose');
     $bodyCloseScripts = ob_get_clean();
     if ($bodyCloseScripts) {
         $content = str_ireplace('</body>', $bodyCloseScripts . "\n</body>", $content);
     }
     $event->setContent($content);
 }
Exemple #2
0
 public function outputScripts($name)
 {
     ob_start();
     $this->assetsHelper->outputScripts($name);
     return ob_get_clean();
 }