/** * 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); } }
/** * 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); }
/** * 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); } }
/** * 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); } }
/** * 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); }
/** * 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; }