Commits

Christoffer Niska  committed d38a570

added support for dropups

  • Participants
  • Parent commits 020ec09
  • Branches 1.0.0-wip

Comments (0)

Files changed (2)

File widgets/TbButtonGroup.php

 	 */
 	public function init()
 	{
-		$classes = 'btn-group';
+		$classes = array('btn-group');
+
+        foreach ($this->buttons as $button)
+        {
+            if ($this->hasDropdown($button) && $this->isDropup($button))
+            {
+                $classes[] = 'dropup';
+                break;
+            }
+        }
+
+        $classes = implode(' ', $classes);
 		if (isset($this->htmlOptions['class']))
 			$this->htmlOptions['class'] .= ' '.$classes;
 		else
 			$this->htmlOptions['class'] = $classes;
 
-		$validToggles = array(self::TOGGLE_CHECKBOX, self::TOGGLE_RADIO);
-
-		if (isset($this->toggle) && in_array($this->toggle, $validToggles))
+		if (isset($this->toggle) && in_array($this->toggle, array(self::TOGGLE_CHECKBOX, self::TOGGLE_RADIO)))
 			$this->htmlOptions['data-toggle'] = 'buttons-'.$this->toggle;
 	}
 
 
 		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

         if ($this->type !== self::TYPE_LIST && $this->stacked)
             $classes[] = 'nav-stacked';
 
+        foreach ($this->items as $item)
+        {
+            if ($this->hasDropdown($item) && $this->isDropup($item))
+            {
+                $classes[] = 'dropup';
+                break;
+            }
+        }
+
         $classes = implode(' ', $classes);
         if (isset($this->htmlOptions['class']))
             $this->htmlOptions['class'] .= ' '.$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
      */