Exemplo n.º 1
0
 /**
  * Renders the content to be inserted at the end of the body section.
  * The content is rendered using the registered JS code blocks and files.
  * @param boolean $ajaxMode whether the view is rendering in AJAX mode.
  * If true, the JS scripts registered at [[POS_READY]] and [[POS_LOAD]] positions
  * will be rendered at the end of the view like normal scripts.
  * @return string the rendered content
  */
 protected function renderBodyEndHtml($ajaxMode)
 {
     $lines = [];
     if (!empty($this->jsFiles[self::POS_END])) {
         $lines[] = implode("\n", $this->jsFiles[self::POS_END]);
     }
     if ($ajaxMode) {
         $scripts = [];
         if (!empty($this->js[self::POS_END])) {
             $scripts[] = implode("\n", $this->js[self::POS_END]);
         }
         if (!empty($this->js[self::POS_READY])) {
             $scripts[] = implode("\n", $this->js[self::POS_READY]);
         }
         if (!empty($this->js[self::POS_LOAD])) {
             $scripts[] = implode("\n", $this->js[self::POS_LOAD]);
         }
         if (!empty($scripts)) {
             $lines[] = Html::script(implode("\n", $scripts), ['type' => 'text/javascript']);
         }
     } else {
         if (!empty($this->js[self::POS_END])) {
             $lines[] = Html::script(implode("\n", $this->js[self::POS_END]), ['type' => 'text/javascript']);
         }
         if (!empty($this->js[self::POS_READY])) {
             $js = "jQuery(document).ready(function () {\n" . implode("\n", $this->js[self::POS_READY]) . "\n});";
             $lines[] = Html::script($js, ['type' => 'text/javascript']);
         }
         if (!empty($this->js[self::POS_LOAD])) {
             $js = "jQuery(window).load(function () {\n" . implode("\n", $this->js[self::POS_LOAD]) . "\n});";
             $lines[] = Html::script($js, ['type' => 'text/javascript']);
         }
     }
     return empty($lines) ? '' : implode("\n", $lines);
 }