Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Eworm/big-kahuna
Browse files Browse the repository at this point in the history
  • Loading branch information
Eworm committed Nov 15, 2019
2 parents 6de30aa + e8093fe commit ff07654
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 73 deletions.
152 changes: 79 additions & 73 deletions BigKahuna/BigKahunaTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,79 +26,85 @@ public function index()
*
* @return html
*/
private function getItems($pages, $locale, $root = true)
{
$menu = ($this->getParam('menu')) ? ' ' . $this->getParam('menu') : "";
$id = ($this->getParam('id')) ? $this->getParam('id') : "";
$class = ($this->getParam('class')) ? $this->getParam('class') : "nav";
$itemClass = ($this->getParam('item_class')) ? $this->getParam('item_class') : "nav__item";
$parentClass = ($this->getParam('parent_class')) ? $this->getParam('parent_class') : "nav__item--parent";
$submenu_class = ($this->getParam('submenu_class')) ? $this->getParam('submenu_class') : "submenu";
$submenu_item_class = ($this->getParam('submenu_item_class')) ? $this->getParam('submenu_item_class') : "submenu__item";
$activeClass = ($this->getParam('active_class')) ? $this->getParam('active_class') : "is--active";

$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

$html = '';

if ($root == true) {
// The root list
$html .= '<ul id="' . $id . '" class="' . $class . $menu . '">';
} else {
// A submenu list
$itemClass = $submenu_item_class;
$html .= '<ul class="' . $submenu_class . '">';
}

foreach ($pages as $page) {
$id = $page['id'];
$myClassname = ' ' . $page['classname'];
$isParent = $page['items'] ? ' ' . $parentClass : '';

if ($page['linktitle'] != '') {
$myLinkTitle = $page['linktitle'];
} else {
$myLinkTitle = $page['title'];
}
$content = Content::find($id);

if ($page['type'] == 'Custom') {
// A custom link
$html .= '<li class="' . $itemClass . $isParent . $myClassname .'">';
} else {
if ($content) {
$isactive = '';
if ($content->in($locale)->absoluteUrl() == $actual_link || $this->getChildActiveStatus($page, $actual_link)) {
$isactive = ' ' . $activeClass;
}
$html .= '<li class="' . $itemClass . $isParent . $isactive . $myClassname . '">';
}
}

if ($page['type'] == 'Custom') {
// A custom link
$html .= '<a href="' . $page['url'] . '" title="' . $myLinkTitle . '" rel="external">';
} else {
// An internal link
if ($content) {
$html .= '<a href="' . $content->in($locale)->absoluteUrl() . '" title="' . $myLinkTitle . '">';
}
}
if ($content || $page['type'] == 'Custom') {
$html .= $page['title'];
$html .= '</a>';
}
if ($page['items']) {
// Return the submenu html
$html .= $this->getItems($page['items'], false);
}

$html .= '</li>';
}

$html .= '</ul>';
return $html;
}
private function getItems($pages, $locale, $root = true)
{
$menu = ($this->getParam('menu')) ? ' ' . $this->getParam('menu') : "";
$id = ($this->getParam('id')) ? $this->getParam('id') : "";
$class = ($this->getParam('class')) ? $this->getParam('class') : "nav";
$itemClass = ($this->getParam('item_class')) ? $this->getParam('item_class') : "nav__item";
$linkClass = ($this->getParam('link_class')) ? $this->getParam('link_class') : "nav__link";
$parentClass = ($this->getParam('parent_class')) ? $this->getParam('parent_class') : "nav__item--parent";
$parentLinkClass = ($this->getParam('parent_link_class')) ? $this->getParam('parent_link_class') : "nav__item--toggle";
$submenu_class = ($this->getParam('submenu_class')) ? $this->getParam('submenu_class') : "submenu";
$submenu_item_class = ($this->getParam('submenu_item_class')) ? $this->getParam('submenu_item_class') : "submenu__item";
$activeClass = ($this->getParam('active_class')) ? $this->getParam('active_class') : "is--active";

$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

$html = '';

if ($root == true) {
// The root list
$html .= '<ul id="' . $id . '" class="' . $class . $menu . '">';
} else {
// A submenu list
$itemClass = $submenu_item_class;
$html .= '<ul class="' . $submenu_class . '">';
}

foreach ($pages as $page) {
$id = $page['id'];
$myClassname = ' ' . $page['classname'];
$isParent = $page['items'] ? ' ' . $parentClass : '';
$isParentLink = $page['items'] ? ' ' . $parentLinkClass: '';
$parentAttributes = $page['items'] ? ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"': '';

if ($page['linktitle'] != '') {
$myLinkTitle = $page['linktitle'];
} else {
$myLinkTitle = $page['title'];
}
$content = Content::find($id);

if ($page['type'] == 'Custom') {
// A custom link
$html .= '<li class="' . $itemClass . $isParent . $myClassname .'">';
} else {
if ($content) {
$isactive = '';
if ($content->in($locale)->absoluteUrl() == $actual_link || $this->getChildActiveStatus($page, $actual_link)) {
$isactive = ' ' . $activeClass;
}
}
$html .= '<li class="' . $itemClass . $isParent . $isactive . $myClassname . '">';
}

if ($page['type'] == 'Custom') {
// A custom link
$html .= '<a class="' . $linkClass . $isParentLink . '"' . $parentAttributes . ' href="' . $page['url'] . '" title="' . $myLinkTitle . '" rel="external">';
} else {
// An internal link
if ($content) {
$html .= '<a class="' . $linkClass . $isParentLink . '"' . $parentAttributes . ' href="' . $content->in($locale)->absoluteUrl() . '" title="' . $myLinkTitle . '">';
}
}

if ($content || $page['type'] == 'Custom') {
$html .= $page['title'];
$html .= '</a>';
}

if ($page['items']) {
// Return the submenu html
$html .= $this->getItems($page['items'], $locale, false);
}

$html .= '</li>';
}

$html .= '</ul>';
return $html;
}

public function getChildActiveStatus($page, $actual_link)
{
Expand Down
7 changes: 7 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ The class for feedback for the current page. Defaults to 'is--active'. This clas
**item\_class**
The class for every root li. Defaults to 'nav__item'.

**link\_class**
The class for every link items. Defaults to 'nav__link'.

**parent\_class**
The class for li items with a submenu. Defaults to 'nav__item--parent'.

**parent\_link\_class**
The class for link items with a submenu. Defaults to 'nav__item--toggle'.

### A submenu list
**submenu\_class**
The class for every ul element inside a list item following a link. The default is 'submenu'.
Expand All @@ -71,4 +77,5 @@ The class for every li element in a submenu. The default is 'submenu__item'.

### Stuff not on the menu
* Custom links to external sites get a `rel="external"` on the link tag.
* Links with submenu items get a `data-toggle="dropdown"` to support Bootstrap dropdown menus.
* Since the 'is--active' class is added to an li, it's best to use something like `.is--active > a` in your stylesheet for feedback classes. That way the submenu links don't inherit the active style.

0 comments on commit ff07654

Please sign in to comment.