Skip to content

Commit

Permalink
Merge pull request #34 from rizkysyazuli/bootstrap-support
Browse files Browse the repository at this point in the history
Additional classes and data attributes on link items
  • Loading branch information
Eworm authored Nov 6, 2019
2 parents 133d6fa + d882f8d commit 07ff20e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 9 additions & 5 deletions BigKahuna/BigKahunaTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ private function getItems($pages, $locale, $root = true)
$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";
Expand All @@ -51,9 +53,11 @@ private function getItems($pages, $locale, $root = true)
}

foreach ($pages as $page) {
$id = $page['id'];
$myClassname = ' ' . $page['classname'];
$isParent = $page['items'] ? ' ' . $parentClass : '';
$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'];
Expand All @@ -76,10 +80,10 @@ private function getItems($pages, $locale, $root = true)

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

$html .= $page['title'];
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 07ff20e

Please sign in to comment.