From 98f53bfb20f85b9af35246ec02e9b7fa43eac5e7 Mon Sep 17 00:00:00 2001 From: Vitaliy Bezsheiko Date: Wed, 6 Jan 2021 11:45:08 +0200 Subject: [PATCH] #126 Fix fatal error on adding js to article page --- OldGreggThemePlugin.inc.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/OldGreggThemePlugin.inc.php b/OldGreggThemePlugin.inc.php index 37a642e..5c61ffb 100755 --- a/OldGreggThemePlugin.inc.php +++ b/OldGreggThemePlugin.inc.php @@ -67,12 +67,6 @@ public function init() $this->addScript('fontawesome', 'resources/js/fontawesome-all.min.js'); $this->addScript('main', 'resources/js/main.js'); - $request = $this->getRequest(); - if ($request->getRequestedPage() == "article" && (is_array($request->getRequestedArgs()) && count($request->getRequestedArgs()) == 1)) { - $this->addScript("article", "resources/js/article.js"); - } - - $this->addStyle( 'my-custom-font1', '//fonts.googleapis.com/css?family=Lora', @@ -97,6 +91,7 @@ public function init() HookRegistry::register('TemplateManager::display', array($this, 'journalDescription'), HOOK_SEQUENCE_NORMAL); HookRegistry::register('TemplateManager::display', array($this, 'categoriesJournalIndex'), HOOK_SEQUENCE_NORMAL); HookRegistry::register('TemplateManager::display', array($this, 'articleSection')); + HookRegistry::register('TemplateManager::display', array($this, 'articleJs')); } @@ -151,7 +146,7 @@ public function browseLatest($hookName, $args) function sitewideData($hookName, $args) { $smarty = $args[0]; - $orcidImagePath = $this->request->getBaseUrl() . DIRECTORY_SEPARATOR . $this->getTemplatePath() . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . "orcid.png"; + $orcidImagePath = $this->getRequest()->getBaseUrl() . DIRECTORY_SEPARATOR . $this->getTemplatePath() . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . "orcid.png"; $smarty->assign('orcidImagePath', $orcidImagePath); } @@ -373,6 +368,21 @@ public function articleSection($hookName, $args) { 'section' => $section ]); } + + /** + * @param $hookName + * @param $args + * Adds javascript file to the article landing page & (temporary) galley page + */ + public function articleJs($hookName, $args) { + $templateMgr = $args[0]; + $template = $args[1]; + + if ($template != 'frontend/pages/article.tpl' && $template != 'plugins-plugins-generic-jatsParser-generic-jatsParser:articleGalleyView.tpl') return; + + $request = $this->getRequest(); + $templateMgr->addJavascript('article', $request->getBaseUrl() . '/' . $this->getPluginPath() . '/resources/js/article.js'); + } } ?>