diff --git a/themes/bootstrap3/templates/layout/layout.phtml b/themes/bootstrap3/templates/layout/layout.phtml index e10c16ce2108bbcfd1184aa2218ad8c7e4a2578d..65ab39a7fbd23edf5a06c4b8646357f92e763fc7 100644 --- a/themes/bootstrap3/templates/layout/layout.phtml +++ b/themes/bootstrap3/templates/layout/layout.phtml @@ -25,6 +25,9 @@ <?=$this->headLink()?> <?=$this->headStyle()?> <?php + // Collect small scripts together and append as one block: + $appendScripts = []; + if (!isset($this->renderingError)) { // Add translation strings $this->jsTranslations()->addStrings( @@ -72,21 +75,15 @@ $this->headScript()->appendFile("cart.js"); $domain = $cart->getCookieDomain(); if (!empty($domain)) { - $this->headScript()->appendScript( - 'VuFind.cart.setDomain("' . $domain . '");' - ); + $appendScripts[] = 'VuFind.cart.setDomain("' . $domain . '");'; } $cookiePath = $cart->getCookiePath(); if (!empty($cookiePath)) { - $this->headScript()->appendScript( - 'VuFind.cart.setCookiePath("' . $cookiePath . '");' - ); + $appendScripts[] = 'VuFind.cart.setCookiePath("' . $cookiePath . '");'; } $cookieSameSite = $cart->getCookieSameSite(); if (null !== $cookieSameSite) { - $this->headScript()->appendScript( - 'VuFind.cart.setCookieSameSite("' . $cookieSameSite . '");' - ); + $appendScripts[] = 'VuFind.cart.setCookieSameSite("' . $cookieSameSite . '");'; } $this->jsTranslations()->addStrings( [ @@ -110,8 +107,7 @@ // Session keep-alive if ($this->keepAlive()) { - $this->headScript()->appendScript('var keepAliveInterval = ' - . $this->keepAlive()); + $appendScripts[] = 'var keepAliveInterval = ' . $this->keepAlive() . ';'; $this->headScript()->appendFile("keep_alive.js"); } @@ -134,12 +130,13 @@ $root = rtrim($this->url('home'), '/'); $translations = $this->jsTranslations()->getJSON(); $dsb = DEFAULT_SEARCH_BACKEND; - $setupJS = <<<JS + $appendScripts[] = <<<JS VuFind.path = '{$root}'; VuFind.defaultSearchBackend = '{$dsb}'; VuFind.addTranslations({$translations}); JS; - $this->headScript()->appendScript($setupJS); + $this->headScript()->appendScript(implode("\n", $appendScripts)); + if ($this->config()->ajaxCoversEnabled()) { $this->headScript()->appendFile("covers.js"); }