Skip to content

Commit

Permalink
pkp/pkp-lib#5199 Set the current page on the top menu - OJS 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
israelcefrin committed Jan 26, 2024
1 parent 88fd319 commit d0081f8
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/pkp
65 changes: 63 additions & 2 deletions plugins/themes/default/DefaultThemePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @file plugins/themes/default/DefaultThemePlugin.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class DefaultThemePlugin
Expand All @@ -19,6 +19,13 @@
use PKP\config\Config;
use PKP\session\SessionManager;

use APP\facades\Repo;
use APP\issue\Collector;
use APP\services\NavigationMenuService;
use PKP\plugins\ThemePlugin;
use PKP\plugins\Hook;


class DefaultThemePlugin extends \PKP\plugins\ThemePlugin
{
/**
Expand Down Expand Up @@ -210,6 +217,9 @@ public function init()

// Add navigation menu areas for this theme
$this->addMenuArea(['primary', 'user']);


Hook::add('TemplateManager::display', array($this, 'checkCurrentPage'));
}

/**
Expand Down Expand Up @@ -253,6 +263,57 @@ public function getDescription()
{
return __('plugins.themes.default.description');
}

/**
* @param $hookname string
* @param $args array
*/
public function checkCurrentPage($hookname, $args) {
$templateMgr = $args[0];
// TODO check the issue with multiple calls of the hook on settings/website
if (!isset($templateMgr->registered_plugins["function"]["default_item_active"])) {
$templateMgr->registerPlugin('function', 'default_item_active', array($this, 'isActiveItem'));
}

}

/**
* @param $params array
* @param $smarty Smarty_Internal_Template
* @return string
*/
public function isActiveItem($params, $smarty) {

$navigationMenuItem = $params['item'];
$emptyMarker = '';
$activeMarker = ' active';

// Get URL of the current page
$request = $this->getRequest();
$currentUrl = $request->getCompleteUrl();
$currentPage = $request->getRequestedPage();

// Do not add an active marker if it's a dropdown menu
if ($navigationMenuItem->getIsChildVisible()) return $emptyMarker;

// Retrieve URL and its components for a menu item
$itemUrl = $navigationMenuItem->getUrl();

// Check whether menu item points to the current page
$context = $request->getContext();
if ($context) {
$currentIssue = Repo::issue()->getCurrent($context->getId());
if ($navigationMenuItem->getType() === NavigationMenuService::NMI_TYPE_CURRENT) {
$issue = $smarty->getTemplateVars('issue');
if ($issue && ($issue->getId() === $currentIssue->getId()) && $currentPage == "issue") return $activeMarker;
}
}

if ($currentUrl === $itemUrl) return $activeMarker;

return $emptyMarker;
}

}

if (!PKP_STRICT_MODE) {
Expand Down
30 changes: 28 additions & 2 deletions plugins/themes/default/styles/head.less
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@

a {
display: inline-block;
padding: 0.125rem 0;
padding: 0.86rem 0;
color: @text-bg-base;
text-decoration: none;

Expand All @@ -127,6 +127,18 @@
text-decoration: underline;
}
}
@media (max-width: @screen-desktop) {

.active {
background-color: @bg-base-border-color;

}
.active a {
font-weight: bold;

}
}


#siteNav {
position: absolute;
Expand Down Expand Up @@ -358,6 +370,19 @@
}
}

// Visualy highlighting the current menu item
> li.active {
> a {
//background: @primary-lift;
border-color: @text-bg-base;
outline: 0;
}
&:hover {
color: @bg-base;
border-color: red;
}
}

// Reproduce positioning of dropdown menu from Popper.js
> li:hover ul {
position: absolute;
Expand All @@ -377,7 +402,8 @@
}

.dropdown-menu a:focus,
.dropdown-menu a:hover {
.dropdown-menu a:hover,
.dropdown-menu li.active a {
border-color: @primary;
}

Expand Down

0 comments on commit d0081f8

Please sign in to comment.