Commits

Christoffer Niska committed b797835

fixed dropdown item active

  • Participants
  • Parent commits fda0966
  • Branches bootstrap-2.0.2

Comments (0)

Files changed (3)

File widgets/BootBaseMenu.php

 			$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'] = '#';
 
 	}
 
 	/**
+	 * 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

File widgets/BootDropdown.php

 				if (isset($item['header']))
 					$class[] = 'nav-header';
 
+				if ($item['active'])
+					$class[] = 'active';
+
 				$cssClass = implode(' ', $class);
 				if(isset($item['itemOptions']['class']))
 					$item['itemOptions']['class'] .= $cssClass;
 			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);

File widgets/BootMenu.php

 
 				$class = array();
 
-				if (isset($item['header']))
-					$class[] = 'nav-header';
-
 				if ($item['active'] || (isset($item['items']) && $this->isChildActive($item['items'])))
 					$class[] = 'active';
 
 	}
 
 	/**
+	 * 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
 	}
 
 	/**
-	 * 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