Commits

Christoffer Niska committed 313c205

refactored dropup logic

  • Participants
  • Parent commits c1d61f6
  • Branches 1.0.0-wip

Comments (0)

Files changed (2)

File widgets/TbButtonGroup.php

 	 * @var boolean indicates whether to enable button toggling.
 	 */
 	public $toggle;
+	/**
+	 * @var boolean indicates whether dropdowns should be dropups instead.
+	 */
+	public $dropup = false;
 
 	/**
 	 * Initializes the widget.
 	{
 		$classes = array('btn-group');
 
-        foreach ($this->buttons as $button)
-        {
-            if ($this->hasDropdown($button) && $this->isDropup($button))
-            {
-                $classes[] = 'dropup';
-                break;
-            }
-        }
+        if ($this->dropup === true)
+			$classes[] = 'dropup';
 
         if (!empty($classes))
         {
 
 		echo '</div>';
 	}
-
-    /**
-     * Returns whether the given button has a dropdown.
-     * @param array $button the button configuration
-     * @return boolean the result
-     */
-    protected function hasDropdown($button)
-    {
-        return isset($button['items']) && !empty($button['items']);
-    }
-
-    /**
-     * Returns whether the given item is a dropup.
-     * @param array $button the button configuration
-     * @return boolean the result
-     */
-    protected function isDropup($button)
-    {
-        return isset($button['dropup']) && $button['dropup'] === true;
-    }
 }

File widgets/TbMenu.php

      */
     public $type;
     /**
-     * @var boolean whether to stack navigation items.
+     * @var boolean indicates whether to stack navigation items.
      */
     public $stacked = false;
     /**
      * @var array the scroll-spy configuration.
      */
     public $scrollspy;
+	/**
+	 * @var boolean indicates whether dropdowns should be dropups instead.
+	 */
+	public $dropup = false;
 
     /**
      * Initializes the widget.
         if (isset($this->type) && in_array($this->type, $validTypes))
             $classes[] = 'nav-'.$this->type;
 
-        if ($this->type !== self::TYPE_LIST && $this->stacked)
+        if ($this->stacked && $this->type !== self::TYPE_LIST)
             $classes[] = 'nav-stacked';
 
-        foreach ($this->items as $item)
-        {
-            if ($this->hasDropdown($item) && $this->isDropup($item))
-            {
-                $classes[] = 'dropup';
-                break;
-            }
-        }
+    	if ($this->dropup === true)
+			$classes[] = 'dropup';
 
         if (!empty($classes))
         {
     }
 
     /**
-     * Returns whether the given item has a dropdown.
-     * @param array $item the item configuration
-     * @return boolean the result
-     */
-    protected function hasDropdown($item)
-    {
-        return isset($item['items']) && !empty($item['items']);
-    }
-
-    /**
-     * Returns whether the given item is a dropup.
-     * @param array $item the item configuration
-     * @return boolean the result
-     */
-    protected function isDropup($item)
-    {
-        return isset($item['dropup']) && $item['dropup'] === true;
-    }
-
-    /**
      * Returns the divider css class.
      * @return string the class name
      */