Commits

Christoffer Niska  committed 73e6b36

minor widget improvements

  • Participants
  • Parent commits fe1a10e
  • Branches 1.0.0-wip

Comments (0)

Files changed (15)

File widgets/TbBadge.php

 class TbBadge extends CWidget
 {
 	// Badge types.
-	const TYPE_DEFAULT = '';
 	const TYPE_SUCCESS = 'success';
 	const TYPE_WARNING = 'warning';
 	const TYPE_IMPORTANT = 'important';
 
 	/**
 	 * @var string the badge type (defaults to '').
-	 * Valid types are '', 'success', 'warning', 'important', 'info' and 'inverse'.
+	 * Valid types are 'success', 'warning', 'important', 'info' and 'inverse'.
 	 */
-	public $type = self::TYPE_DEFAULT;
+	public $type;
 	/**
 	 * @var string the badge text.
 	 */
 	{
 		$classes = array('badge');
 
-		if (in_array($this->type, array(self::TYPE_SUCCESS, self::TYPE_WARNING, self::TYPE_IMPORTANT, self::TYPE_INFO, self::TYPE_INVERSE)))
+        $validTypes = array(self::TYPE_SUCCESS, self::TYPE_WARNING, self::TYPE_IMPORTANT, self::TYPE_INFO, self::TYPE_INVERSE);
+
+		if (isset($this->type) && in_array($this->type, $validTypes))
 			$classes[] = 'badge-'.$this->type;
 
-		$classes = implode(' ', $classes);
-		if (isset($this->htmlOptions['class']))
-			$this->htmlOptions['class'] .= ' '.$classes;
-		else
-			$this->htmlOptions['class'] = $classes;
+        if (!empty($classes))
+        {
+            $classes = implode(' ', $classes);
+            if (isset($this->htmlOptions['class']))
+                $this->htmlOptions['class'] .= ' '.$classes;
+            else
+                $this->htmlOptions['class'] = $classes;
+        }
 
 		if ($this->encodeLabel === true)
 			$this->label = CHtml::encode($this->label);

File widgets/TbBaseMenu.php

                     if ($this->itemCssClass !== null)
                         $classes[] = $this->itemCssClass;
 
-                    if ($classes !== array())
+                    if (!empty($classes))
                     {
                         $classes = implode(' ', $classes);
                         if (!empty($options['class']))
                 if (isset($item['items']))
                     $classes[] = 'dropdown';
 
-                $classes = implode($classes, ' ');
-                if (isset($item['itemOptions']['class']))
-                    $item['itemOptions']['class'] .= ' '.$classes;
-                else
-                    $item['itemOptions']['class'] = $classes;
+                if (!empty($classes))
+                {
+                    $classes = implode($classes, ' ');
+                    if (isset($item['itemOptions']['class']))
+                        $item['itemOptions']['class'] .= ' '.$classes;
+                    else
+                        $item['itemOptions']['class'] = $classes;
+                }
             }
 
             $items[$i] = $item;

File widgets/TbButton.php

 	const BUTTON_AJAXSUBMIT = 'ajaxSubmit';
 
 	// Button types.
-	const TYPE_NORMAL = '';
 	const TYPE_PRIMARY = 'primary';
 	const TYPE_INFO = 'info';
 	const TYPE_SUCCESS = 'success';
 	public $buttonType = self::BUTTON_LINK;
 	/**
 	 * @var string the button type.
-	 * Valid values are '', 'primary', 'info', 'success', 'warning', 'danger' and 'inverse'.
+	 * Valid values are 'primary', 'info', 'success', 'warning', 'danger' and 'inverse'.
 	 */
-	public $type = self::TYPE_NORMAL;
+	public $type;
 	/**
 	 * @var string the button size.
 	 * Valid values are '', 'small' and 'large'.
 			$this->htmlOptions['data-toggle'] = 'dropdown';
 		}
 
-		$classes = implode(' ', $classes);
-
-		if (isset($this->htmlOptions['class']))
-			$this->htmlOptions['class'] .= ' '.$classes;
-		else
-			$this->htmlOptions['class'] = $classes;
+        if (!empty($classes))
+        {
+            $classes = implode(' ', $classes);
+            if (isset($this->htmlOptions['class']))
+                $this->htmlOptions['class'] .= ' '.$classes;
+            else
+                $this->htmlOptions['class'] = $classes;
+        }
 
 		if (isset($this->icon))
 		{

File widgets/TbButtonGroup.php

 	 * @var string the button type.
 	 * @see BootButton::type
 	 */
-	public $type = TbButton::TYPE_NORMAL;
+	public $type;
 	/**
 	 * @var string the button size.
 	 * @see BootButton::size
             }
         }
 
-        $classes = implode(' ', $classes);
-		if (isset($this->htmlOptions['class']))
-			$this->htmlOptions['class'] .= ' '.$classes;
-		else
-			$this->htmlOptions['class'] = $classes;
+        if (!empty($classes))
+        {
+            $classes = implode(' ', $classes);
+            if (isset($this->htmlOptions['class']))
+                $this->htmlOptions['class'] .= ' '.$classes;
+            else
+                $this->htmlOptions['class'] = $classes;
+        }
 
-		if (isset($this->toggle) && in_array($this->toggle, array(self::TOGGLE_CHECKBOX, self::TOGGLE_RADIO)))
+        $validToggles = array(self::TOGGLE_CHECKBOX, self::TOGGLE_RADIO);
+
+        if (isset($this->toggle) && in_array($this->toggle, $validToggles))
 			$this->htmlOptions['data-toggle'] = 'buttons-'.$this->toggle;
 	}
 

File widgets/TbCarousel.php

         if ($this->slide === true)
             $classes[] = 'slide';
 
-		$classes = implode($classes, ' ');
-		if (isset($this->htmlOptions['class']))
-			$this->htmlOptions['class'] .= ' '.$classes;
-		else
-			$this->htmlOptions['class'] = $classes;
-
+        if (!empty($classes))
+        {
+            $classes = implode(' ', $classes);
+            if (isset($this->htmlOptions['class']))
+                $this->htmlOptions['class'] .= ' '.$classes;
+            else
+                $this->htmlOptions['class'] = $classes;
+        }
 	}
 
 	/**

File widgets/TbDetailView.php

 class TbDetailView extends CDetailView
 {
 	// Table types.
-	const TYPE_PLAIN = '';
 	const TYPE_STRIPED = 'striped';
 	const TYPE_BORDERED = 'bordered';
 	const TYPE_CONDENSED = 'condensed';
 
 	/**
 	 * @var string|array the table type.
-	 * Valid values are '', 'striped', 'bordered' and/or 'condensed'.
+	 * Valid values are 'striped', 'bordered' and/or 'condensed'.
 	 */
 	public $type = array(self::TYPE_STRIPED, self::TYPE_CONDENSED);
 	/**
 
 		$classes = array('table');
 
-		if (is_string($this->type))
-			$this->type = explode(' ', $this->type);
+        if (isset($this->type))
+        {
+            if (is_string($this->type))
+                $this->type = explode(' ', $this->type);
 
-		$validTypes = array(self::TYPE_STRIPED, self::TYPE_BORDERED, self::TYPE_CONDENSED);
+            $validTypes = array(self::TYPE_STRIPED, self::TYPE_BORDERED, self::TYPE_CONDENSED);
 
-		foreach ($this->type as $type)
-			if (in_array($type, $validTypes))
-				$classes[] = 'table-'.$type;
+            if (!empty($this->type))
+            {
+                foreach ($this->type as $type)
+                {
+                    if (in_array($type, $validTypes))
+                        $classes[] = 'table-'.$type;
+                }
+            }
+        }
 
-		$classes = implode(' ', $classes);
-		if (isset($this->htmlOptions['class']))
-			$this->htmlOptions['class'] .= ' '.$classes;
-		else
-			$this->htmlOptions['class'] = $classes;
+        if (!empty($classes))
+        {
+            $classes = implode(' ', $classes);
+            if (isset($this->htmlOptions['class']))
+                $this->htmlOptions['class'] .= ' '.$classes;
+            else
+                $this->htmlOptions['class'] = $classes;
+        }
 	}
 }

File widgets/TbGridView.php

 class TbGridView extends CGridView
 {
 	// Table types.
-	const TYPE_PLAIN = '';
 	const TYPE_STRIPED = 'striped';
 	const TYPE_BORDERED = 'bordered';
 	const TYPE_CONDENSED = 'condensed';
 
 	/**
 	 * @var string|array the table type.
-	 * Valid values are '', 'striped', 'bordered' and/or ' condensed'.
+	 * Valid values are 'striped', 'bordered' and/or ' condensed'.
 	 */
-	public $type = self::TYPE_PLAIN;
+	public $type;
 	/**
 	 * @var string the CSS class name for the pager container.
 	 * Defaults to 'pagination'.
 
 		$classes = array('table');
 
-		if (is_string($this->type))
-			$this->type = explode(' ', $this->type);
+        if (isset($this->type))
+        {
+            if (is_string($this->type))
+                $this->type = explode(' ', $this->type);
 
-		$validTypes = array(self::TYPE_STRIPED, self::TYPE_BORDERED, self::TYPE_CONDENSED);
+            $validTypes = array(self::TYPE_STRIPED, self::TYPE_BORDERED, self::TYPE_CONDENSED);
 
-		foreach ($this->type as $type)
-			if (in_array($type, $validTypes))
-				$classes[] = 'table-'.$type;
+            if (!empty($this->type))
+            {
+                foreach ($this->type as $type)
+                {
+                    if (in_array($type, $validTypes))
+                        $classes[] = 'table-'.$type;
+                }
+            }
+        }
 
-		$this->itemsCssClass .= ' '.implode(' ', $classes);
+        if (!empty($classes))
+        {
+            $classes = implode(' ', $classes);
+            if (isset($this->itemsCssClass))
+                $this->itemsCssClass .= ' '.$classes;
+            else
+                $this->itemsCssClass = $classes;
+        }
 
 		$popover = Yii::app()->bootstrap->popoverSelector;
 		$tooltip = Yii::app()->bootstrap->tooltipSelector;

File widgets/TbHeroUnit.php

 	 */
 	public function init()
 	{
-		$classes = 'hero-unit';
 		if (isset($this->htmlOptions['class']))
-			$this->htmlOptions['class'] .= ' '.$classes;
+			$this->htmlOptions['class'] .= ' hero-unit';
 		else
-			$this->htmlOptions['class'] = $classes;
+			$this->htmlOptions['class'] = 'hero-unit';
 
 		if ($this->encodeHeading)
 			$this->heading = CHtml::encode($this->heading);

File widgets/TbLabel.php

 class TbLabel extends CWidget
 {
 	// Label types.
-	const TYPE_DEFAULT = '';
 	const TYPE_SUCCESS = 'success';
 	const TYPE_WARNING = 'warning';
 	const TYPE_IMPORTANT = 'important';
 
 	/**
 	 * @var string the label type (defaults to '').
-	 * Valid types are '', 'success', 'warning', 'important', 'info' and 'inverse'.
+	 * Valid types are 'success', 'warning', 'important', 'info' and 'inverse'.
 	 */
-	public $type = self::TYPE_DEFAULT;
+	public $type;
 	/**
 	 * @var string the label text.
 	 */
 	{
 		$classes = array('label');
 
-		if (in_array($this->type, array(self::TYPE_SUCCESS, self::TYPE_WARNING, self::TYPE_IMPORTANT, self::TYPE_INFO, self::TYPE_INVERSE)))
+        $validTypes = array(self::TYPE_SUCCESS, self::TYPE_WARNING, self::TYPE_IMPORTANT, self::TYPE_INFO, self::TYPE_INVERSE);
+
+        if (isset($this->type) && in_array($this->type, $validTypes))
 			$classes[] = 'label-'.$this->type;
 
-		$classes = implode(' ', $classes);
-		if (isset($this->htmlOptions['class']))
-			$this->htmlOptions['class'] .= ' '.$classes;
-		else
-			$this->htmlOptions['class'] = $classes;
+        if (!empty($classes))
+        {
+            $classes = implode(' ', $classes);
+            if (isset($this->htmlOptions['class']))
+                $this->htmlOptions['class'] .= ' '.$classes;
+            else
+                $this->htmlOptions['class'] = $classes;
+        }
 
 		if ($this->encodeLabel === true)
 			$this->label = CHtml::encode($this->label);

File widgets/TbMenu.php

 class TbMenu extends TbBaseMenu
 {
     // Menu types.
-    const TYPE_UNSTYLED = '';
     const TYPE_TABS = 'tabs';
     const TYPE_PILLS = 'pills';
     const TYPE_LIST = 'list';
 
     /**
      * @var string the menu type.
-     * Valid values are '', 'tabs' and 'pills'. Defaults to ''.
+     * Valid values are 'tabs' and 'pills'. Defaults to ''.
      */
     public $type;
     /**
 
         $classes = array('nav');
 
-        if (isset($this->type) && in_array($this->type, array(self::TYPE_TABS, self::TYPE_PILLS, self::TYPE_LIST)))
+        $validTypes = array(self::TYPE_TABS, self::TYPE_PILLS, self::TYPE_LIST);
+
+        if (isset($this->type) && in_array($this->type, $validTypes))
             $classes[] = 'nav-'.$this->type;
 
         if ($this->type !== self::TYPE_LIST && $this->stacked)
             }
         }
 
-        $classes = implode(' ', $classes);
-        if (isset($this->htmlOptions['class']))
-            $this->htmlOptions['class'] .= ' '.$classes;
-        else
-            $this->htmlOptions['class'] = $classes;
+        if (!empty($classes))
+        {
+            $classes = implode(' ', $classes);
+            if (isset($this->htmlOptions['class']))
+                $this->htmlOptions['class'] .= ' '.$classes;
+            else
+                $this->htmlOptions['class'] = $classes;
+        }
 
         if (isset($this->scrollspy) && is_array($this->scrollspy) && isset($this->scrollspy['spy']))
         {

File widgets/TbModal.php

 class TbModal extends CWidget
 {
 	/**
-	 * @var boolean whether to automatically open the modal when initialized.
+	 * @var boolean indicates whether to automatically open the modal when initialized.
 	 */
 	public $autoOpen = false;
+    /**
+     * @var boolean indicates whether the modal should use transitions.
+     */
+    public $fade = true;
 	/**
 	 * @var array the options for the Bootstrap JavaScript plugin.
 	 */
 		if (!$this->autoOpen && !isset($this->options['show']))
 			$this->options['show'] = false;
 
-		$classes = 'modal fade';
-		if (isset($this->htmlOptions['class']))
-			$this->htmlOptions['class'] .= ' '.$classes;
-		else
-			$this->htmlOptions['class'] = $classes;
+        $classes = array('modal');
+
+        if ($this->fade === true)
+            $classes[] = 'fade';
+
+        if (!empty($classes))
+        {
+            $classes = implode(' ', $classes);
+            if (isset($this->htmlOptions['class']))
+                $this->htmlOptions['class'] .= ' '.$classes;
+            else
+                $this->htmlOptions['class'] = $classes;
+        }
 
 		echo CHtml::openTag('div', $this->htmlOptions).PHP_EOL;
 	}

File widgets/TbNavbar.php

             }
 		}
 
-		$classes = implode(' ', $classes);
-		if (isset($this->htmlOptions['class']))
-			$this->htmlOptions['class'] .= ' '.$classes;
-		else
-			$this->htmlOptions['class'] = $classes;
+        if (!empty($classes))
+        {
+            $classes = implode(' ', $classes);
+            if (isset($this->htmlOptions['class']))
+                $this->htmlOptions['class'] .= ' '.$classes;
+            else
+                $this->htmlOptions['class'] = $classes;
+        }
 	}
 
 	/**
      */
     protected function getCollapseTarget()
     {
-        return $this->type === self::TYPE_DEFAULT ? 'nav-collapse' : 'subnav-collapse';
+        return !isset($this->type) ? 'nav-collapse' : 'subnav-collapse';
     }
 
     /**
      */
     protected function getCollapseCssClass()
     {
-        return $this->type === self::TYPE_DEFAULT ? 'nav-collapse' : 'nav-collapse subnav-collapse';
+        return !isset($this->type) ? 'nav-collapse' : 'nav-collapse subnav-collapse';
     }
 }

File widgets/TbPager.php

 class TbPager extends CLinkPager
 {
 	// Pager alignments.
-	const ALIGNMENT_LEFT = '';
 	const ALIGNMENT_CENTER = 'centered';
 	const ALIGNMENT_RIGHT = 'right';
 
 	 * @var string the pager alignment (default to '').
 	 * Valid values are 'left', 'centered' and 'right'.
 	 */
-	public $alignment = self::ALIGNMENT_LEFT;
+	public $alignment;
 	/**
 	 * @var string the text shown before page buttons (defaults to '').
 	 */
 
 		$classes = array();
 
-		if (in_array($this->alignment, array(self::ALIGNMENT_LEFT, self::ALIGNMENT_CENTER, self::ALIGNMENT_RIGHT)))
+        $validAlignments = array(self::ALIGNMENT_CENTER, self::ALIGNMENT_RIGHT);
+
+        if (in_array($this->alignment, $validAlignments))
 			$classes[] = 'pagination-'.$this->alignment;
 
         if (!empty($classes))

File widgets/TbProgress.php

 class TbProgress extends CWidget
 {
 	// Progress bar types.
-	const TYPE_DEFAULT = '';
 	const TYPE_INFO = 'info';
 	const TYPE_SUCCESS = 'success';
 	const TYPE_WARNING = 'warning';
 
 	/**
 	 * @var string the bar type.
-	 * Valid values are '', 'info', 'success', and 'danger'.
+	 * Valid values are 'info', 'success', and 'danger'.
 	 */
-	public $type = self::TYPE_DEFAULT;
+	public $type;
 	/**
 	 * @var boolean whether the bar is striped.
 	 */
 	{
 		$classes = array('progress');
 
-		$validTypes = array(self::TYPE_DEFAULT, self::TYPE_INFO, self::TYPE_SUCCESS, self::TYPE_WARNING, self::TYPE_DANGER);
-		if ($this->type !== self::TYPE_DEFAULT && in_array($this->type, $validTypes))
+		$validTypes = array(self::TYPE_INFO, self::TYPE_SUCCESS, self::TYPE_WARNING, self::TYPE_DANGER);
+
+		if (isset($this->type) && in_array($this->type, $validTypes))
 			$classes[] = 'progress-'.$this->type;
 
 		if ($this->striped)
 		if ($this->animated)
 			$classes[] = 'active';
 
-		$classes = implode(' ', $classes);
-		if (isset($this->htmlOptions['class']))
-			$this->htmlOptions['class'] .= ' '.$classes;
-		else
-			$this->htmlOptions['class'] = $classes;
+        if (!empty($classes))
+        {
+            $classes = implode(' ', $classes);
+            if (isset($this->htmlOptions['class']))
+                $this->htmlOptions['class'] .= ' '.$classes;
+            else
+                $this->htmlOptions['class'] = $classes;
+        }
 
 		if ($this->percent < 0)
 			$this->percent = 0;

File widgets/TbTabbable.php

 	 * @var string the placement of the tabs.
 	 * Valid values are 'above', 'below', 'left' and 'right'.
 	 */
-	public $placement = self::PLACEMENT_ABOVE;
+	public $placement;
 	/**
 	 * @var array the tab configuration.
 	 */
 		if (!isset($this->htmlOptions['id']))
 			$this->htmlOptions['id'] = $this->getId();
 
-		$validPlacements = array(self::PLACEMENT_ABOVE, self::PLACEMENT_BELOW, self::PLACEMENT_LEFT, self::PLACEMENT_RIGHT);
+        $classes = array();
 
-		if (isset($this->placement) && in_array($this->placement, $validPlacements))
+        $validPlacements = array(self::PLACEMENT_ABOVE, self::PLACEMENT_BELOW, self::PLACEMENT_LEFT, self::PLACEMENT_RIGHT);
+
+        if (isset($this->placement) && in_array($this->placement, $validPlacements))
+            $classes[] = 'tabs-'.$this->placement;
+
+        if (!empty($classes))
 		{
-			$classes = 'tabs-'.$this->placement;
+			$classes = implode(' ', $classes);
 			if (isset($this->htmlOptions['class']))
 				$this->htmlOptions['class'] .= ' '.$classes;
 			else