Commit ce0f0851 by niskac

fixed dropdown item active

parent 3ea779af
......@@ -53,17 +53,6 @@ abstract class BootBaseMenu extends BootWidget
$item['label'] = '<i class="'.$item['icon'].'"></i> '.$item['label'];
}
if (isset($item['items']) && !empty($item['items']))
{
if (isset($item['linkOptions']['class']))
$item['linkOptions']['class'] .= ' dropdown-toggle';
else
$item['linkOptions']['class'] = 'dropdown-toggle';
$item['linkOptions']['data-toggle'] = 'dropdown';
$item['label'] .= ' <span class="caret"></span>';
}
if (!isset($item['header']) && !isset($item['url']))
$item['url'] = '#';
......@@ -74,6 +63,27 @@ abstract class BootBaseMenu extends BootWidget
}
/**
* Checks whether a menu item is active.
* @param array $item the menu item to be checked
* @param string $route the route of the current request
* @return boolean the result
*/
protected function isItemActive($item, $route)
{
if (isset($item['url']) && is_array($item['url']) && !strcasecmp(trim($item['url'][0], '/'), $route))
{
if (count($item['url']) > 1)
foreach (array_splice($item['url'], 1) as $name=>$value)
if (!isset($_GET[$name]) || $_GET[$name] != $value)
return false;
return true;
}
return false;
}
/**
* Renders the items in this menu.
* @abstract
* @param array $items the menu items
......
......@@ -48,6 +48,9 @@ class BootDropdown extends BootBaseMenu
if (isset($item['header']))
$class[] = 'nav-header';
if ($item['active'])
$class[] = 'active';
$cssClass = implode(' ', $class);
if(isset($item['itemOptions']['class']))
$item['itemOptions']['class'] .= $cssClass;
......@@ -95,6 +98,9 @@ class BootDropdown extends BootBaseMenu
if (($this->encodeLabel && !isset($item['encodeLabel']))
|| (isset($item['encodeLabel']) && $item['encodeLabel'] !== false))
$items[$i]['label'] = CHtml::encode($item['label']);
if (!isset($item['active']))
$items[$i]['active'] = $this->isItemActive($item, $route);
}
return array_values($items);
......
......@@ -94,9 +94,6 @@ class BootMenu extends BootBaseMenu
$class = array();
if (isset($item['header']))
$class[] = 'nav-header';
if ($item['active'] || (isset($item['items']) && $this->isChildActive($item['items'])))
$class[] = 'active';
......@@ -134,6 +131,30 @@ class BootMenu extends BootBaseMenu
}
/**
* Renders a single item in the menu.
* @param array $item the item configuration
* @return string the rendered item
*/
protected function renderItem($item)
{
if (!isset($item['linkOptions']))
$item['linkOptions'] = array();
if (isset($item['items']) && !empty($item['items']))
{
if (isset($item['linkOptions']['class']))
$item['linkOptions']['class'] .= ' dropdown-toggle';
else
$item['linkOptions']['class'] = 'dropdown-toggle';
$item['linkOptions']['data-toggle'] = 'dropdown';
$item['label'] .= ' <span class="caret"></span>';
}
return parent::renderItem($item);
}
/**
* Normalizes the items in this menu.
* @param array $items the items to be normalized
* @param string $route the route of the current request
......@@ -175,27 +196,6 @@ class BootMenu extends BootBaseMenu
}
/**
* Checks whether a menu item is active.
* @param array $item the menu item to be checked
* @param string $route the route of the current request
* @return boolean the result
*/
protected function isItemActive($item, $route)
{
if (isset($item['url']) && is_array($item['url']) && !strcasecmp(trim($item['url'][0], '/'), $route))
{
if (count($item['url']) > 1)
foreach (array_splice($item['url'], 1) as $name=>$value)
if (!isset($_GET[$name]) || $_GET[$name] != $value)
return false;
return true;
}
return false;
}
/**
* Returns whether a child item is active.
* @param array $items the items to check
* @return boolean the result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment