示例#1
0
文件: Queue.php 项目: atiarda/bolt
 /**
  * Process the JavaScript asset queue.
  *
  * @param FileAssetInterface $asset
  * @param string             $html
  *
  * @return string
  */
 protected function processJsAssets(FileAssetInterface $asset, $html)
 {
     if ($asset->isLate()) {
         return $this->injector->inject($asset, Target::END_OF_BODY, $html);
     } else {
         return $this->injector->inject($asset, Target::AFTER_JS, $html);
     }
 }
示例#2
0
文件: Queue.php 项目: johndotcat/bolt
 /**
  * Insert a snippet of Javascript to fetch the actual widget's contents.
  *
  * @param WidgetAssetInterface $widget
  * @param Response             $response
  */
 protected function addDeferredJavaScript(WidgetAssetInterface $widget, Response $response)
 {
     if ($this->deferAdded) {
         return;
     }
     $javaScript = $this->render->render('widgetjavascript.twig', ['widget' => $widget]);
     $snippet = (new Snippet())->setLocation(Target::AFTER_BODY_JS)->setCallback((string) $javaScript);
     $this->deferAdded = true;
     $this->injector->inject($snippet, Target::AFTER_BODY_JS, $response);
 }
示例#3
0
文件: Queue.php 项目: d-m-/bolt
 /**
  * Process a single asset.
  *
  * @param FileAssetInterface $asset
  * @param Request            $request
  * @param Response           $response
  */
 protected function processAsset(FileAssetInterface $asset, Request $request, Response $response)
 {
     if ($asset->getZone() !== Zone::get($request)) {
         return;
     } elseif ($asset->isLate()) {
         $this->injector->inject($asset, Target::END_OF_BODY, $response);
     } elseif ($asset->getType() === 'stylesheet') {
         $this->injector->inject($asset, Target::BEFORE_CSS, $response);
     } elseif ($asset->getType() === 'javascript') {
         $this->injector->inject($asset, Target::AFTER_JS, $response);
     }
 }
示例#4
0
文件: Queue.php 项目: bolt/bolt
 /**
  * Insert jQuery, if it's not inserted already.
  *
  * Some of the patterns that 'match' are:
  * - jquery.js
  * - jquery.min.js
  * - jquery-latest.js
  * - jquery-latest.min.js
  * - jquery-1.8.2.min.js
  * - jquery-1.5.js
  *
  * @param Request  $request
  * @param Response $response
  */
 protected function addJquery(Request $request, Response $response)
 {
     if (!$this->config->get('general/add_jquery', false) && !$this->config->get('theme/add_jquery', false)) {
         return;
     }
     if (Zone::isFrontend($request) === false) {
         return;
     }
     $html = $response->getContent();
     $regex = '/<script(.*)jquery(-latest|-[0-9\\.]*)?(\\.min)?\\.js/';
     if (!preg_match($regex, $html)) {
         $jqueryfile = $this->resources->getPath('app/view/js/jquery-2.2.4.min.js');
         $asset = (new Snippet())->setLocation(Target::BEFORE_JS)->setCallback('<script src="' . $jqueryfile . '"></script>');
         $this->injector->inject($asset, $asset->getLocation(), $response);
     }
 }
示例#5
0
文件: Queue.php 项目: gandalf3/bolt
 /**
  * Process a single asset.
  *
  * @param FileAssetInterface $asset
  * @param Request            $request
  * @param Response           $response
  */
 protected function processAsset(FileAssetInterface $asset, Request $request, Response $response)
 {
     if ($asset->getZone() !== Zone::get($request)) {
         return;
     } elseif ($asset->isLate()) {
         if ($asset->getLocation() === null) {
             $location = Target::END_OF_BODY;
         } else {
             $location = $asset->getLocation();
         }
     } elseif ($asset->getLocation() !== null) {
         $location = $asset->getLocation();
     } else {
         $location = Target::END_OF_HEAD;
     }
     $this->injector->inject($asset, $location, $response);
 }
示例#6
0
文件: Queue.php 项目: atiarda/bolt
 /**
  * Insert jQuery, if it's not inserted already.
  *
  * Some of the patterns that 'match' are:
  * - jquery.js
  * - jquery.min.js
  * - jquery-latest.js
  * - jquery-latest.min.js
  * - jquery-1.8.2.min.js
  * - jquery-1.5.js
  *
  * @param string $html
  *
  * @return string HTML
  */
 protected function addJquery($html)
 {
     if (!$this->config->get('general/add_jquery', false) && !$this->config->get('theme/add_jquery', false)) {
         return $html;
     }
     $zone = Zone::FRONTEND;
     if ($request = $this->requestStack->getCurrentRequest()) {
         $zone = Zone::get($request);
     }
     $regex = '/<script(.*)jquery(-latest|-[0-9\\.]*)?(\\.min)?\\.js/';
     if ($zone === Zone::FRONTEND && !preg_match($regex, $html)) {
         $jqueryfile = $this->resources->getPath('app/view/js/jquery-2.1.4.min.js');
         $asset = (new Snippet())->setLocation(Target::BEFORE_JS)->setCallback('<script src="' . $jqueryfile . '"></script>');
         $html = $this->injector->inject($asset, $asset->getLocation(), $html);
     }
     return $html;
 }