Skip to content

Commit

Permalink
Merge cbc374e into 6599c51
Browse files Browse the repository at this point in the history
  • Loading branch information
gcw07 committed Feb 20, 2014
2 parents 6599c51 + cbc374e commit 3c1cae1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/SpiffyNavigation/View/Helper/NavigationMenu.php
Expand Up @@ -40,14 +40,20 @@ public function renderMenu($container = null, array $options = array())
$prevDepth = -1;
foreach($iterator as $page) {
$depth = $iterator->getDepth();
$pageAttributes = $page->getAttributes();

if ($depth == $options->getMinDepth()) {
$prevDepth = $depth;
continue;
}

if ($depth > $prevDepth) {
$html .= sprintf('<ul%s>', $prevDepth == $options->getMinDepth() ? ' class="' . $options->getUlClass() .'"' : '');
if ($prevDepth == $options->getMinDepth()) {
$ulId = $options->getUlId() ? ' id="' . $options->getUlId() . '"' : '';
$html .= sprintf('<ul%s>', ' class="' . $options->getUlClass() . '"' . $ulId);
} else {
$html .= sprintf('<ul%s>', $options->getUlSubClass() ? ' class="' . $options->getUlSubClass() . '"' : '');
}
} elseif ($prevDepth > $depth) {
for ($i = $prevDepth; $i > $depth; $i--) {
$html .= '</li>';
Expand All @@ -58,8 +64,14 @@ public function renderMenu($container = null, array $options = array())
$html .= '</li>';
}

$liClass = $this->navigation->isActive($page) ? ' class="' . $options->getActiveClass() . '"' : '';
$html .= sprintf('<li%s>%s', $liClass, $this->htmlify($page));
if ($this->navigation->isActive($page)) {
$liExtraClass = isset($pageAttributes['liClass']) ? $pageAttributes['liClass'] : '';
$liClass = ' class="' . $options->getActiveClass() . ' ' . $liExtraClass . '"';
} else {
$liClass = isset($pageAttributes['liClass']) ? ' class="' . $pageAttributes['liClass'] . '"' : '';
}

$html .= sprintf('<li%s>%s', $liClass, $this->htmlify($page));

$prevDepth = $depth;
}
Expand Down Expand Up @@ -151,6 +163,8 @@ protected function htmlify(Page $page)
$element = 'span';
}

unset($attribs['liClass']);

return sprintf('<%s%s>%s</%s>', $element, $this->htmlAttribs($attribs), $label, $element);
}
}
48 changes: 48 additions & 0 deletions src/SpiffyNavigation/View/Helper/NavigationMenuOptions.php
Expand Up @@ -27,6 +27,18 @@ class NavigationMenuOptions extends AbstractOptions
*/
protected $ulClass = 'nav';

/**
* Attribute id of the base ul element.
* @var string
*/
protected $ulId = '';

/**
* Class of the sub ul element.
* @var string
*/
protected $ulSubClass = '';

/**
* @param string $ulClass
* @return NavigationMenu
Expand All @@ -45,6 +57,42 @@ public function getUlClass()
return $this->ulClass;
}

/**
* @param string $ulId
* @return NavigationMenu
*/
public function setUlId($ulId)
{
$this->ulId = $ulId;
return $this;
}

/**
* @return string
*/
public function getUlId()
{
return $this->ulId;
}

/**
* @param string $ulSubClass
* @return NavigationMenu
*/
public function setUlSubClass($ulSubClass)
{
$this->ulSubClass = $ulSubClass;
return $this;
}

/**
* @return string
*/
public function getUlSubClass()
{
return $this->ulSubClass;
}

/**
* @param $minDepth
* @return NavigationMenu
Expand Down

0 comments on commit 3c1cae1

Please sign in to comment.