Commit 84381e8c by Crisu83

minor widget improvements

parent fe59a455
......@@ -13,7 +13,6 @@
class TbBadge extends CWidget
{
// Badge types.
const TYPE_DEFAULT = '';
const TYPE_SUCCESS = 'success';
const TYPE_WARNING = 'warning';
const TYPE_IMPORTANT = 'important';
......@@ -22,9 +21,9 @@ class TbBadge extends CWidget
/**
* @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.
*/
......@@ -45,14 +44,19 @@ class TbBadge extends CWidget
{
$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);
......
......@@ -54,7 +54,7 @@ abstract class TbBaseMenu extends CMenu
if ($this->itemCssClass !== null)
$classes[] = $this->itemCssClass;
if ($classes !== array())
if (!empty($classes))
{
$classes = implode(' ', $classes);
if (!empty($options['class']))
......@@ -162,11 +162,14 @@ abstract class TbBaseMenu extends CMenu
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;
......
......@@ -24,7 +24,6 @@ class TbButton extends CWidget
const BUTTON_AJAXSUBMIT = 'ajaxSubmit';
// Button types.
const TYPE_NORMAL = '';
const TYPE_PRIMARY = 'primary';
const TYPE_INFO = 'info';
const TYPE_SUCCESS = 'success';
......@@ -45,9 +44,9 @@ class TbButton extends CWidget
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'.
......@@ -137,12 +136,14 @@ class TbButton extends CWidget
$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))
{
......
......@@ -28,7 +28,7 @@ class TbButtonGroup extends CWidget
* @var string the button type.
* @see BootButton::type
*/
public $type = TbButton::TYPE_NORMAL;
public $type;
/**
* @var string the button size.
* @see BootButton::size
......@@ -67,13 +67,18 @@ class TbButtonGroup extends CWidget
}
}
$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;
}
$validToggles = array(self::TOGGLE_CHECKBOX, self::TOGGLE_RADIO);
if (isset($this->toggle) && in_array($this->toggle, array(self::TOGGLE_CHECKBOX, self::TOGGLE_RADIO)))
if (isset($this->toggle) && in_array($this->toggle, $validToggles))
$this->htmlOptions['data-toggle'] = 'buttons-'.$this->toggle;
}
......
......@@ -59,12 +59,14 @@ class TbCarousel extends CWidget
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;
}
}
/**
......
......@@ -16,14 +16,13 @@ Yii::import('zii.widgets.CDetailView');
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);
/**
......@@ -41,19 +40,30 @@ class TbDetailView extends CDetailView
$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;
}
}
}
......@@ -17,16 +17,15 @@ Yii::import('bootstrap.widgets.TbDataColumn');
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'.
......@@ -52,16 +51,31 @@ class TbGridView extends CGridView
$classes = array('table');
if (is_string($this->type))
$this->type = explode(' ', $this->type);
$validTypes = array(self::TYPE_STRIPED, self::TYPE_BORDERED, self::TYPE_CONDENSED);
foreach ($this->type as $type)
if (in_array($type, $validTypes))
$classes[] = 'table-'.$type;
$this->itemsCssClass .= ' '.implode(' ', $classes);
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);
if (!empty($this->type))
{
foreach ($this->type as $type)
{
if (in_array($type, $validTypes))
$classes[] = 'table-'.$type;
}
}
}
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;
......
......@@ -32,11 +32,10 @@ class TbHeroUnit extends CWidget
*/
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);
......
......@@ -13,7 +13,6 @@
class TbLabel extends CWidget
{
// Label types.
const TYPE_DEFAULT = '';
const TYPE_SUCCESS = 'success';
const TYPE_WARNING = 'warning';
const TYPE_IMPORTANT = 'important';
......@@ -22,9 +21,9 @@ class TbLabel extends CWidget
/**
* @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.
*/
......@@ -45,14 +44,19 @@ class TbLabel extends CWidget
{
$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);
......
......@@ -12,14 +12,13 @@ Yii::import('bootstrap.widgets.TbBaseMenu');
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;
/**
......@@ -40,7 +39,9 @@ class TbMenu extends TbBaseMenu
$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)
......@@ -55,11 +56,14 @@ class TbMenu extends TbBaseMenu
}
}
$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']))
{
......
......@@ -14,9 +14,13 @@
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.
*/
......@@ -41,11 +45,19 @@ class TbModal extends CWidget
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;
}
......
......@@ -99,11 +99,14 @@ class TbNavbar extends CWidget
}
}
$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;
}
}
/**
......@@ -157,7 +160,7 @@ class TbNavbar extends CWidget
*/
protected function getCollapseTarget()
{
return $this->type === self::TYPE_DEFAULT ? 'nav-collapse' : 'subnav-collapse';
return !isset($this->type) ? 'nav-collapse' : 'subnav-collapse';
}
/**
......@@ -166,6 +169,6 @@ class TbNavbar extends CWidget
*/
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';
}
}
......@@ -13,7 +13,6 @@
class TbPager extends CLinkPager
{
// Pager alignments.
const ALIGNMENT_LEFT = '';
const ALIGNMENT_CENTER = 'centered';
const ALIGNMENT_RIGHT = 'right';
......@@ -21,7 +20,7 @@ class TbPager extends CLinkPager
* @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 '').
*/
......@@ -49,7 +48,9 @@ class TbPager extends CLinkPager
$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))
......
......@@ -14,7 +14,6 @@
class TbProgress extends CWidget
{
// Progress bar types.
const TYPE_DEFAULT = '';
const TYPE_INFO = 'info';
const TYPE_SUCCESS = 'success';
const TYPE_WARNING = 'warning';
......@@ -22,9 +21,9 @@ class TbProgress extends CWidget
/**
* @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.
*/
......@@ -49,8 +48,9 @@ class TbProgress extends CWidget
{
$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)
......@@ -59,11 +59,14 @@ class TbProgress extends CWidget
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;
......
......@@ -31,7 +31,7 @@ class TbTabbable extends CWidget
* @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.
*/
......@@ -57,11 +57,16 @@ class TbTabbable extends CWidget
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
......
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