Commit 770fab69 by Crisu83

reviewed and refactored all widgets

parent 80d276db
......@@ -282,25 +282,6 @@ class Bootstrap extends CApplicationComponent
}
/**
* Sets the target element for the scrollspy.
* @param string $selector the CSS selector
* @param string $target the target CSS selector
* @param string $offset the offset
*/
public function spyOn($selector, $target = null, $offset = null)
{
$script = "jQuery('{$selector}').attr('data-spy', 'scroll');";
if (isset($target))
$script .= "jQuery('{$selector}').attr('data-target', '{$target}');";
if (isset($offset))
$script .= "jQuery('{$selector}').attr('data-offset', '{$offset}');";
Yii::app()->clientScript->registerScript(__CLASS__.'.spyOn.'.$selector, $script, CClientScript::POS_BEGIN);
}
/**
* Registers a Bootstrap JavaScript plugin.
* @param string $name the name of the plugin
* @param string $selector the CSS selector
......
......@@ -74,35 +74,27 @@ section {
}
}
#bootNavbar .navbar-inner > .container {
#tbNavbar .navbar-inner > .container {
width: auto;
}
#bootMenu .menuCol {
#tbMenu .menuCol {
min-height: 140px;
}
#bootTabbable .tabbable {
#tbTabs .togglable-tabs {
margin-bottom: 20px;
.tab-content {
width: auto;
}
&.tabbable-placed {
width: 340px;
}
}
#bootThumbnails .list-view {
#tbThumbnails .list-view {
padding-top: 30px;
}
#bootActiveForm .form-vertical .control-group > label {
#tbActiveForm .form-vertical .control-group > label {
font-weight: bold;
}
#bootHero .hero-unit {
#tbHero .hero-unit {
width: 650px;
h1 {
......@@ -118,7 +110,7 @@ section {
}
}
#bootCarousel .carousel {
#tbCarousel .carousel {
width: 770px;
.carousel-caption p {
......@@ -126,7 +118,7 @@ section {
}
}
#bootTypeahead input {
#tbTypeahead input {
margin-bottom: 0;
}
......
......@@ -662,10 +662,10 @@ Yii::app()->clientScript->registerScript('ConsolePolyfill', "
<h3>Sub navigation</h3>
<?php $this->widget('bootstrap.widgets.TbNavbar', array(
'type'=>'subnav',
'fixed'=>false,
'brand'=>false,
'collapse'=>true, // requires bootstrap-responsive.css
'subnav'=>true,
'items'=>array(
array(
'class'=>'bootstrap.widgets.TbMenu',
......@@ -706,10 +706,10 @@ Yii::app()->clientScript->registerScript('ConsolePolyfill', "
<h4>Source code</h4>
<?php echo $phpLighter->highlight("<?php \$this->widget('bootstrap.widgets.TbNavbar', array(
'type'=>'subnav',
'fixed'=>false,
'brand'=>false,
'collapse'=>true, // requires bootstrap-responsive.css
'subnav'=>true,
'items'=>array(
array(
'class'=>'bootstrap.widgets.TbMenu',
......@@ -1044,7 +1044,7 @@ Yii::app()->clientScript->registerScript('ConsolePolyfill', "
'type'=>'horizontal',
)); ?>
<?php $this->widget('bootstrap.widgets.TbTabbable', array(
<?php $this->widget('bootstrap.widgets.TbTabs', array(
'tabs'=>$this->getTabularFormTabs($form, $model),
)); ?>
......@@ -1063,7 +1063,7 @@ Yii::app()->clientScript->registerScript('ConsolePolyfill', "
'type'=>'horizontal',
)); ?>
<?php \$this->widget('bootstrap.widgets.TbTabbable', array(
<?php \$this->widget('bootstrap.widgets.TbTabs', array(
'tabs'=>\$this->getTabularFormTabs(\$form, \$model),
)); ?>
......@@ -1447,23 +1447,23 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
</section>
<section id="tbTabbable">
<section id="tbTabs">
<h2>Tabbable <small>bootstrap.widgets.TbTabbable</small></h2>
<h2>Togglable tabs <small>bootstrap.widgets.TbTabs</small></h2>
<?php $this->widget('bootstrap.widgets.TbTabbable', array(
<?php $this->widget('bootstrap.widgets.TbTabs', array(
'type'=>'tabs', // 'tabs' or 'pills'
'htmlOptions'=>array('class'=>'tabbable'),
'htmlOptions'=>array('class'=>'togglable-tabs'),
'tabs'=>$tabs,
'events'=>array(
'show'=>"js:function() { console.log('Tabbable show.'); }",
'shown'=>"js:function() { console.log('Tabbable shown.'); }",
'show'=>"js:function() { console.log('Tabs show.'); }",
'shown'=>"js:function() { console.log('Tabs shown.'); }",
),
)); ?>
<h4>Source code</h4>
<?php echo $phpLighter->highlight("<?php \$this->widget('bootstrap.widgets.TbTabbable', array(
<?php echo $phpLighter->highlight("<?php \$this->widget('bootstrap.widgets.TbTabs', array(
'type'=>'tabs', // 'tabs' or 'pills'
'tabs'=>array(
array('label'=>'Home', 'content'=>'Raw denim you probably haven\'t heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.', 'active'=>true),
......@@ -1475,29 +1475,24 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
),
)); ?>"); ?>
<div class="alert alert-block alert-warning">
<strong>Note!</strong>
Because of a bug in the current version of Bootstrap tab-content fall below the tabs even when it shouldn't. This can be fixed by setting tab-content width to auto.
</div>
<div class="row">
<div class="span6">
<h3>Tabs on the top</h3>
<?php $this->widget('bootstrap.widgets.TbTabbable', array(
'htmlOptions'=>array('class'=>'tabbable tabbable-placed'),
'tabs'=>$tabbable,
)); ?>
<?php $this->widget('bootstrap.widgets.TbTabs', array(
'htmlOptions'=>array('class'=>'togglable-tabs'),
'tabs'=>$tabbable,
)); ?>
<h3>Tabs on the left</h3>
<?php $this->widget('bootstrap.widgets.TbTabbable', array(
'placement'=>'left',
'htmlOptions'=>array('class'=>'tabbable tabbable-placed'),
'tabs'=>$tabbable,
)); ?>
<?php $this->widget('bootstrap.widgets.TbTabs', array(
'placement'=>'left',
'htmlOptions'=>array('class'=>'togglable-tabs'),
'tabs'=>$tabbable,
)); ?>
</div>
......@@ -1505,25 +1500,25 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
<h3>Tabs on the bottom</h3>
<?php $this->widget('bootstrap.widgets.TbTabbable', array(
'placement'=>'below',
'htmlOptions'=>array('class'=>'tabbable tabbable-placed'),
'tabs'=>$tabbable,
)); ?>
<?php $this->widget('bootstrap.widgets.TbTabs', array(
'placement'=>'below',
'htmlOptions'=>array('class'=>'togglable-tabs'),
'tabs'=>$tabbable,
)); ?>
<h3>Tabs on the right</h3>
<?php $this->widget('bootstrap.widgets.TbTabbable', array(
'placement'=>'right',
'htmlOptions'=>array('class'=>'tabbable tabbable-placed'),
'tabs'=>$tabbable,
)); ?>
<?php $this->widget('bootstrap.widgets.TbTabs', array(
'placement'=>'right',
'htmlOptions'=>array('class'=>'togglable-tabs'),
'tabs'=>$tabbable,
)); ?>
</div>
</div>
<?php echo $phpLighter->highlight("<?php \$this->widget('bootstrap.widgets.TbTabbable', array(
<?php echo $phpLighter->highlight("<?php \$this->widget('bootstrap.widgets.TbTabs', array(
'type'=>'tabs',
'placement'=>'below', // 'above', 'right', 'below' or 'left'
'tabs'=>array(
......@@ -1618,19 +1613,17 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
</section>
<?php $this->widget('bootstrap.widgets.TbNavbar', array(
'type'=>'subnav',
'brand'=>false,
'fixed'=>'top',
'brand'=>false,
'collapse'=>true,
'subnav'=>true,
'items'=>array(
array(
'class'=>'bootstrap.widgets.TbMenu',
'scrollspy'=>array('spy'=>'.navbar-subnav', 'offset'=>0),
'scrollspy'=>'.navbar-subnav',
'items'=>array(
array('label'=>'Buttons', 'items'=>array(
array('label'=>'Basic buttons', 'url'=>'#tbButton'),
array('label'=>'Buttons groups', 'url'=>'#tbButtonGroup'),
)),
array('label'=>'Buttons', 'url'=>'#tbButton'),
array('label'=>'Buttons groups', 'url'=>'#tbButtonGroup'),
array('label'=>'Navigation', 'items'=>array(
array('label'=>'Breadcrumb', 'url'=>'#tbBreadcrumbs'),
array('label'=>'Menu', 'url'=>'#tbMenu'),
......@@ -1651,7 +1644,7 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
array('label'=>'Carousel', 'url'=>'#tbCarousel'),
array('label'=>'Modal', 'url'=>'#tbModal'),
array('label'=>'Popover', 'url'=>'#tbPopover'),
array('label'=>'Tabbable', 'url'=>'#tbTabbable'),
array('label'=>'Tabs', 'url'=>'#tbTabs'),
array('label'=>'Tooltip', 'url'=>'#tbTooltip'),
array('label'=>'Typeahead', 'url'=>'#tbTypeahead'),
)),
......
......@@ -169,17 +169,23 @@ Yii::app()->bootstrap->registerTypeahead('.typeahead', array(
</section>
<div class="subnav well">
<?php $this->widget('bootstrap.widgets.TbMenu', array(
'type'=>'list',
'scrollspy'=>array('spy'=>'.subnav', 'offset'=>50),
'items'=>array(
array('label'=>'Setup', 'url'=>'#setup'),
array('label'=>'Configuration', 'url'=>'#config'),
array('label'=>'Using LESS', 'url'=>'#less'),
array('label'=>'Plugin API', 'url'=>'#api')
),
)); ?>
<?php $this->widget('bootstrap.widgets.TbNavbar', array(
'fixed'=>'top',
'brand'=>false,
'collapse'=>true,
'subnav'=>true,
'items'=>array(
array(
'class'=>'bootstrap.widgets.TbMenu',
'scrollspy'=>'.navbar-subnav',
'items'=>array(
array('label'=>'Setup', 'url'=>'#setup'),
array('label'=>'Configuration', 'url'=>'#config'),
array('label'=>'Using LESS', 'url'=>'#less'),
array('label'=>'Plugin API', 'url'=>'#api')
),
),
),
)); ?>
</div>
\ No newline at end of file
<?php
/**
* BootActiveForm class file.
* TbActiveForm class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......
<?php
/**
* BootAlert class file.
* TbAlert class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -9,6 +9,7 @@
/**
* Bootstrap alert widget.
* @see http://twitter.github.com/bootstrap/javascript.html#alerts
*/
class TbAlert extends CWidget
{
......@@ -21,7 +22,7 @@ class TbAlert extends CWidget
*/
public $template = '<div class="alert alert-block alert-{key}{class}"><a class="close" data-dismiss="alert">&times;</a>{message}</div>';
/**
* @var string[] the JavaScript event handlers.
* @var string[] the Javascript event handlers.
*/
public $events = array();
/**
......@@ -34,8 +35,6 @@ class TbAlert extends CWidget
*/
public function init()
{
parent::init();
if (!isset($this->htmlOptions['id']))
$this->htmlOptions['id'] = $this->getId();
}
......@@ -45,7 +44,7 @@ class TbAlert extends CWidget
*/
public function run()
{
$id = $this->id;
$id = $this->htmlOptions['id'];
if (is_string($this->keys))
$this->keys = array($this->keys);
......@@ -76,7 +75,7 @@ class TbAlert extends CWidget
foreach ($this->events as $name => $handler)
{
$handler = CJavaScript::encode($handler);
$cs->registerScript(__CLASS__.'#'.$id.'_'.$name, "jQuery('{$selector}').on('".$name."', {$handler});");
$cs->registerScript(__CLASS__.'#'.$id.'_'.$name, "jQuery('{$selector}').on('{$name}', {$handler});");
}
}
}
<?php
/**
* BootBadge class file.
* TbBadge class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -9,6 +9,7 @@
/**
* Bootstrap badge widget.
* @see http://twitter.github.com/bootstrap/components.html#badges
*/
class TbBadge extends CWidget
{
......@@ -20,7 +21,7 @@ class TbBadge extends CWidget
const TYPE_INVERSE = 'inverse';
/**
* @var string the badge type (defaults to '').
* @var string the badge type.
* Valid types are 'success', 'warning', 'important', 'info' and 'inverse'.
*/
public $type;
......
<?php
/**
* BootCrumb class file.
* TbCrumb class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -11,11 +11,12 @@ Yii::import('zii.widgets.CBreadcrumbs');
/**
* Bootstrap breadcrumb widget.
* @see http://twitter.github.com/bootstrap/components.html#breadcrumbs
*/
class TbBreadcrumbs extends CBreadcrumbs
{
/**
* @var string the separator between links in the breadcrumbs (defaults to ' / ').
* @var string the separator between links in the breadcrumbs. Defaults to '/'.
*/
public $separator = '/';
......@@ -24,11 +25,10 @@ class TbBreadcrumbs extends CBreadcrumbs
*/
public function init()
{
$classes = 'breadcrumb';
if (isset($this->htmlOptions['class']))
$this->htmlOptions['class'] .= ' '.$classes;
$this->htmlOptions['class'] .= ' breadcrumb';
else
$this->htmlOptions['class'] = $classes;
$this->htmlOptions['class'] = 'breadcrumb';
}
/**
......@@ -37,6 +37,7 @@ class TbBreadcrumbs extends CBreadcrumbs
*/
public function run()
{
// Hide empty breadcrumbs.
if (empty($this->links))
return;
......@@ -61,9 +62,7 @@ class TbBreadcrumbs extends CBreadcrumbs
$links[] = $this->renderItem($this->encodeLabel ? CHtml::encode($url) : $url, true);
}
echo CHtml::openTag('ul', $this->htmlOptions);
echo implode('', $links);
echo '</ul>';
echo CHtml::tag('ul', $this->htmlOptions, implode('', $links));
}
/**
......
<?php
/**
* BootButton class file.
* TbButton class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -10,6 +10,7 @@
/**
* Bootstrap button widget.
* @see http://twitter.github.com/bootstrap/base-css.html#buttons
*/
class TbButton extends CWidget
{
......@@ -34,7 +35,6 @@ class TbButton extends CWidget
// Button sizes.
const SIZE_MINI = 'mini';
const SIZE_SMALL = 'small';
const SIZE_NORMAL = '';
const SIZE_LARGE = 'large';
/**
......@@ -49,9 +49,9 @@ class TbButton extends CWidget
public $type;
/**
* @var string the button size.
* Valid values are '', 'small' and 'large'.
* Valid values are 'small' and 'large'.
*/
public $size = self::SIZE_NORMAL;
public $size;
/**
* @var string the button icon, e.g. 'ok' or 'remove white'.
*/
......@@ -153,25 +153,14 @@ class TbButton extends CWidget
$this->label = '<i class="'.$this->icon.'"></i> '.$this->label;
}
$this->initHTML5Data();
}
if (isset($this->toggle))
$this->htmlOptions['data-toggle'] = 'button';
/**
* Initializes the HTML5 data attributes used by the data-api.
*/
protected function initHTML5Data()
{
if (isset($this->toggle) || isset($this->loadingText) || isset($this->completeText))
{
if (isset($this->toggle))
$this->htmlOptions['data-toggle'] = 'button';
if (isset($this->loadingText))
$this->htmlOptions['data-loading-text'] = $this->loadingText;
if (isset($this->loadingText))
$this->htmlOptions['data-loading-text'] = $this->loadingText;
if (isset($this->completeText))
$this->htmlOptions['data-complete-text'] = $this->completeText;
}
if (isset($this->completeText))
$this->htmlOptions['data-complete-text'] = $this->completeText;
}
/**
......
<?php
/**
* BootButtonColumn class file.
* TbButtonColumn class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......
<?php
/**
* BootButtonGroup class file.
* TbButtonGroup class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -12,6 +12,7 @@ Yii::import('bootstrap.widgets.TbButton');
/**
* Bootstrap button group widget.
* @see http://twitter.github.com/bootstrap/components.html#buttonGroups
*/
class TbButtonGroup extends CWidget
{
......@@ -33,7 +34,7 @@ class TbButtonGroup extends CWidget
* @var string the button size.
* @see BootButton::size
*/
public $size = TbButton::SIZE_NORMAL;
public $size;
/**
* @var boolean indicates whether to encode the button labels.
*/
......@@ -50,6 +51,10 @@ class TbButtonGroup extends CWidget
* @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.
......@@ -58,14 +63,8 @@ class TbButtonGroup extends CWidget
{
$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))
{
......@@ -91,13 +90,13 @@ class TbButtonGroup extends CWidget
foreach ($this->buttons as $button)
{
if (isset($button['visible']) && !$button['visible'] === false)
if (isset($button['visible']) && $button['visible'] === false)
continue;
$this->controller->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>isset($button['buttonType']) ? $button['buttonType'] : $this->buttonType,
'type'=>isset($button['type']) ? $button['type'] : $this->type,
'size'=>$this->size,
'size'=>$this->size, // all buttons in a group cannot vary in size
'icon'=>isset($button['icon']) ? $button['icon'] : null,
'label'=>isset($button['label']) ? $button['label'] : null,
'url'=>isset($button['url']) ? $button['url'] : null,
......@@ -111,24 +110,4 @@ class TbButtonGroup extends CWidget
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;
}
}
<?php
/**
* BootCarousel class file.
* TbCarousel class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -10,23 +10,24 @@
/**
* Bootstrap carousel widget.
* @see http://twitter.github.com/bootstrap/javascript.html#carousel
*/
class TbCarousel extends CWidget
{
/**
* @var string the previous button content.
* @var string the previous button label. Defaults to '&lsaquo;'.
*/
public $prev = '&lsaquo;';
public $prevLabel = '&lsaquo;';
/**
* @var string the next button content.
* @var string the next button label. Defaults to '&rsaquo;'.
*/
public $next = '&rsaquo;';
public $nextLabel = '&rsaquo;';
/**
* @var boolean whether the carousel should slide items.
* @var boolean indicates whether the carousel should slide items.
*/
public $slide = true;
/**
* @var boolean whether to display the previous and next links.
* @var boolean indicates whether to display the previous and next links.
*/
public $displayPrevAndNext = true;
/**
......@@ -34,11 +35,11 @@ class TbCarousel extends CWidget
*/
public $items = array();
/**
* @var array the options for the Bootstrap JavaScript plugin.
* @var array the options for the Bootstrap Javascript plugin.
*/
public $options = array();
/**
* @var string[] the JavaScript event handlers.
* @var string[] the Javascript event handlers.
*/
public $events = array();
/**
......@@ -83,8 +84,8 @@ class TbCarousel extends CWidget
if ($this->displayPrevAndNext)
{
echo '</div>';
echo '<a class="carousel-control left" href="#'.$id.'" data-slide="prev">'.$this->prev.'</a>';
echo '<a class="carousel-control right" href="#'.$id.'" data-slide="next">'.$this->next.'</a>';
echo '<a class="carousel-control left" href="#'.$id.'" data-slide="prev">'.$this->prevLabel.'</a>';
echo '<a class="carousel-control right" href="#'.$id.'" data-slide="next">'.$this->nextLabel.'</a>';
echo '</div>';
}
......@@ -96,7 +97,7 @@ class TbCarousel extends CWidget
foreach ($this->events as $name => $handler)
{
$handler = CJavaScript::encode($handler);
$cs->registerScript(__CLASS__.'#'.$id.'_'.$name, "jQuery('#{$id}').on('".$name."', {$handler});");
$cs->registerScript(__CLASS__.'#'.$id.'_'.$name, "jQuery('#{$id}').on('{$name}', {$handler});");
}
}
......@@ -111,6 +112,9 @@ class TbCarousel extends CWidget
if (!is_array($item))
continue;
if (isset($item['visible']) && $item['visible'] === false)
continue;
if (!isset($item['itemOptions']))
$item['itemOptions'] = array();
......@@ -119,11 +123,14 @@ class TbCarousel extends CWidget
if ($i === 0)
$classes[] = 'active';
$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;
}
echo CHtml::openTag('div', $item['itemOptions']);
......@@ -143,11 +150,10 @@ class TbCarousel extends CWidget
if (!isset($item['captionOptions']))
$item['captionOptions'] = array();
$classes = 'carousel-caption';
if (isset($item['captionOptions']['class']))
$item['captionOptions']['class'] .= ' '.$classes;
$item['captionOptions']['class'] .= ' carousel-caption';
else
$item['captionOptions']['class'] = $classes;
$item['captionOptions']['class'] = 'carousel-caption';
echo CHtml::openTag('div', $item['captionOptions']);
......
<?php
/**
* BootDataColumn class file.
* TbDataColumn class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -10,7 +10,7 @@
Yii::import('zii.widgets.grid.CDataColumn');
/**
* Bootstrap grid data column
* Bootstrap grid data column.
*/
class TbDataColumn extends CDataColumn
{
......
<?php
/**
* BootDetailView class file.
* TbDetailView class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -10,8 +10,7 @@
Yii::import('zii.widgets.CDetailView');
/**
* Bootstrap detail view widget.
* Used for setting default HTML classes and disabling the default CSS.
* Bootstrap Zii detail view.
*/
class TbDetailView extends CDetailView
{
......
......@@ -9,6 +9,10 @@
Yii::import('bootstrap.widgets.TbBaseMenu');
/**
* Bootstrap dropdown menu.
* @see http://twitter.github.com/bootstrap/javascript.html#dropdowns
*/
class TbDropdown extends TbBaseMenu
{
/**
......@@ -25,7 +29,7 @@ class TbDropdown extends TbBaseMenu
}
/**
* Returns the divider css class.
* Returns the divider CSS class.
* @return string the class name
*/
public function getDividerCssClass()
......
<?php
/**
* BootGridView class file.
* TbGridView class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -11,8 +11,7 @@ Yii::import('zii.widgets.grid.CGridView');
Yii::import('bootstrap.widgets.TbDataColumn');
/**
* Bootstrap grid view widget.
* Used for setting default HTML classes, disabling the default CSS and enable the bootstrap pager.
* Bootstrap Zii grid view.
*/
class TbGridView extends CGridView
{
......@@ -27,8 +26,7 @@ class TbGridView extends CGridView
*/
public $type;
/**
* @var string the CSS class name for the pager container.
* Defaults to 'pagination'.
* @var string the CSS class name for the pager container. Defaults to 'pagination'.
*/
public $pagerCssClass = 'pagination';
/**
......@@ -118,6 +116,7 @@ class TbGridView extends CGridView
$column = new TbDataColumn($this);
$column->name = $matches[1];
if (isset($matches[3]) && $matches[3] !== '')
$column->type = $matches[3];
......
<?php
/**
* BootHero class file.
* TbHeroUnit class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -9,8 +9,9 @@
*/
/**
* Modest bootstrap hero widget.
* Modest bootstrap hero unit widget.
* Thanks to Christphe Boulain for suggesting content capturing.
* @see http://twitter.github.com/bootstrap/components.html#typography
*/
class TbHeroUnit extends CWidget
{
......@@ -26,6 +27,11 @@ class TbHeroUnit extends CWidget
* @var array the HTML attributes for the widget container.
*/
public $htmlOptions = array();
/**
* @var array the HTML attributes for the heading element.
* @since 1.0.0
*/
public $headingOptions = array();
/**
* Initializes the widget.
......@@ -40,8 +46,10 @@ class TbHeroUnit extends CWidget
if ($this->encodeHeading)
$this->heading = CHtml::encode($this->heading);
ob_start();
ob_implicit_flush(false);
echo CHtml::openTag('div', $this->htmlOptions);
if (isset($this->heading))
echo CHtml::tag('h1', $this->headingOptions, $this->heading);
}
/**
......@@ -49,13 +57,6 @@ class TbHeroUnit extends CWidget
*/
public function run()
{
$content = ob_get_clean();
echo CHtml::openTag('div', $this->htmlOptions);
if (isset($this->heading))
echo CHtml::tag('h1', array(), $this->heading);
echo $content;
echo '</div>';
}
}
<?php
/**
* BootLabel class file.
* TbLabel class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -9,6 +9,7 @@
/**
* Bootstrap label widget.
* @see http://twitter.github.com/bootstrap/components.html#labels
*/
class TbLabel extends CWidget
{
......@@ -20,7 +21,7 @@ class TbLabel extends CWidget
const TYPE_INVERSE = 'inverse';
/**
* @var string the label type (defaults to '').
* @var string the label type.
* Valid types are 'success', 'warning', 'important', 'info' and 'inverse'.
*/
public $type;
......
<?php
/**
* BootListView class file.
* TbListView class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -10,8 +10,7 @@
Yii::import('zii.widgets.CListView');
/**
* Bootstrap list view.
* Used to enable the bootstrap pager.
* Bootstrap Zii list view.
*/
class TbListView extends CListView
{
......@@ -21,6 +20,7 @@ class TbListView extends CListView
public $pagerCssClass = 'pagination';
/**
* @var array the configuration for the pager.
* Defaults to <code>array('class'=>'ext.bootstrap.widgets.TbPager')</code>.
*/
public $pager = array('class'=>'bootstrap.widgets.TbPager');
/**
......
......@@ -9,6 +9,10 @@
Yii::import('bootstrap.widgets.TbBaseMenu');
/**
* Bootstrap menu.
* @see http://twitter.github.com/bootstrap/components.html#navs
*/
class TbMenu extends TbBaseMenu
{
// Menu types.
......@@ -18,17 +22,21 @@ class TbMenu extends TbBaseMenu
/**
* @var string the menu type.
* Valid values are 'tabs' and 'pills'. Defaults to ''.
* Valid values are 'tabs' and 'pills'.
*/
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.
* @var string|array the scrollspy configuration.
*/
public $scrollspy;
/**
* @var boolean indicates whether dropdowns should be dropups instead.
*/
public $dropup = false;
/**
* Initializes the widget.
......@@ -44,16 +52,16 @@ class TbMenu extends TbBaseMenu
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->dropup === true)
$classes[] = 'dropup';
if (isset($this->scrollspy))
{
if ($this->hasDropdown($item) && $this->isDropup($item))
{
$classes[] = 'dropup';
break;
}
$scrollspy = is_string($this->scrollspy) ? array('target'=>$this->scrollspy) : $this->scrollspy;
$this->widget('bootstrap.widgets.TbScrollSpy', $scrollspy);
}
if (!empty($classes))
......@@ -64,37 +72,6 @@ class TbMenu extends TbBaseMenu
else
$this->htmlOptions['class'] = $classes;
}
if (isset($this->scrollspy) && is_array($this->scrollspy) && isset($this->scrollspy['spy']))
{
if (!isset($this->scrollspy['subject']))
$this->scrollspy['subject'] = 'body';
if (!isset($this->scrollspy['offset']))
$this->scrollspy['offset'] = null;
Yii::app()->bootstrap->spyOn($this->scrollspy['subject'], $this->scrollspy['spy'], $this->scrollspy['offset']);
}
}
/**
* 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;
}
/**
......
<?php
/**
* BootModal class file.
* TbModal class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -10,23 +10,24 @@
/**
* Bootstrap modal widget.
* @see http://twitter.github.com/bootstrap/javascript.html#modals
*/
class TbModal extends CWidget
{
/**
* @var boolean indicates whether to automatically open the modal when initialized.
* @var boolean indicates whether to automatically open the modal when initialized. Defaults to 'false'.
*/
public $autoOpen = false;
/**
* @var boolean indicates whether the modal should use transitions.
* @var boolean indicates whether the modal should use transitions. Defaults to 'true'.
*/
public $fade = true;
/**
* @var array the options for the Bootstrap JavaScript plugin.
* @var array the options for the Bootstrap Javascript plugin.
*/
public $options = array();
/**
* @var string[] the JavaScript event handlers.
* @var string[] the Javascript event handlers.
*/
public $events = array();
/**
......@@ -42,7 +43,7 @@ class TbModal extends CWidget
if (!isset($this->htmlOptions['id']))
$this->htmlOptions['id'] = $this->getId();
if (!$this->autoOpen && !isset($this->options['show']))
if ($this->autoOpen === false && !isset($this->options['show']))
$this->options['show'] = false;
$classes = array('modal');
......@@ -59,7 +60,7 @@ class TbModal extends CWidget
$this->htmlOptions['class'] = $classes;
}
echo CHtml::openTag('div', $this->htmlOptions).PHP_EOL;
echo CHtml::openTag('div', $this->htmlOptions);
}
/**
......@@ -67,7 +68,7 @@ class TbModal extends CWidget
*/
public function run()
{
$id = $this->id;
$id = $this->htmlOptions['id'];
echo '</div>';
......@@ -80,7 +81,7 @@ class TbModal extends CWidget
foreach ($this->events as $name => $handler)
{
$handler = CJavaScript::encode($handler);
$cs->registerScript(__CLASS__.'#'.$id.'_'.$name, "jQuery('#{$id}').on('".$name."', {$handler});");
$cs->registerScript(__CLASS__.'#'.$id.'_'.$name, "jQuery('#{$id}').on('{$name}', {$handler});");
}
}
}
<?php
/**
* BootNavbar class file.
* TbNavbar class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -20,10 +20,6 @@ class TbNavbar extends CWidget
const FIXED_TOP = 'top';
const FIXED_BOTTOM = 'bottom';
/**
* @var string the navbar type.
*/
public $type;
/**
* @var string the text for the brand.
*/
......@@ -57,6 +53,11 @@ class TbNavbar extends CWidget
* @var boolean whether to enable collapsing on narrow screens. Default to false.
*/
public $collapse = false;
/**
* @var string indicates whether this is a sub navigation.
* @since 1.0.0
*/
public $subnav = false;
/**
* @var array the HTML attributes for the widget container.
*/
......@@ -85,8 +86,8 @@ class TbNavbar extends CWidget
$classes = array('navbar');
if (isset($this->type) && in_array($this->type, array(self::TYPE_SUBNAV)))
$classes[] = 'navbar-'.$this->type;
if (isset($this->subnav) && $this->subnav === true)
$classes[] = 'navbar-subnav';
if ($this->fixed !== false)
{
......@@ -94,7 +95,7 @@ class TbNavbar extends CWidget
{
$classes[] = 'navbar-fixed-'.$this->fixed;
if ($this->type === self::TYPE_SUBNAV)
if (isset($this->subnav) && $this->subnav === true)
$classes[] = 'navbar-subnav-fixed';
}
}
......@@ -130,7 +131,11 @@ class TbNavbar extends CWidget
echo CHtml::openTag('a', $this->brandOptions).$this->brand.'</a>';
if ($this->collapse)
echo '<div class="nav-collapse '.$this->getCollapseCssClass().'">';
{
$this->controller->beginWidget('bootstrap.widgets.TbCollapse', array(
'htmlOptions'=>array('class'=>$this->getCollapseCssClass()),
));
}
foreach ($this->items as $item)
{
......@@ -149,7 +154,7 @@ class TbNavbar extends CWidget
}
if ($this->collapse)
echo '</div>';
$this->controller->endWidget();
echo '</div></div></div>';
}
......@@ -160,7 +165,7 @@ class TbNavbar extends CWidget
*/
protected function getCollapseTarget()
{
return !isset($this->type) ? 'nav-collapse' : 'subnav-collapse';
return isset($this->subnav) && $this->subnav === true ? 'subnav-collapse' : 'nav-collapse';
}
/**
......@@ -169,6 +174,6 @@ class TbNavbar extends CWidget
*/
protected function getCollapseCssClass()
{
return !isset($this->type) ? 'nav-collapse' : 'nav-collapse subnav-collapse';
return isset($this->subnav) && $this->subnav === true ? 'nav-collapse subnav-collapse' : 'nav-collapse';
}
}
<?php
/**
* BootPager class file.
* TbPager class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -8,7 +8,8 @@
*/
/**
* Bootstrap pager widget.
* Bootstrap pager.
* @see http://twitter.github.com/bootstrap/components.html#pagination
*/
class TbPager extends CLinkPager
{
......@@ -17,12 +18,12 @@ class TbPager extends CLinkPager
const ALIGNMENT_RIGHT = 'right';
/**
* @var string the pager alignment (default to '').
* Valid values are 'left', 'centered' and 'right'.
* @var string the pager alignment. Valid values are 'centered' and 'right'.
*/
public $alignment;
/**
* @var string the text shown before page buttons (defaults to '').
* @var string the text shown before page buttons.
* Defaults to an empty string, meaning that no header will be displayed.
*/
public $header = '';
/**
......
<?php
/**
* BootProgress class file.
* TbProgress class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -10,6 +10,7 @@
/**
* Bootstrap progress bar widget.
* @see http://twitter.github.com/bootstrap/components.html#progress
*/
class TbProgress extends CWidget
{
......@@ -20,20 +21,19 @@ class TbProgress extends CWidget
const TYPE_DANGER = 'danger';
/**
* @var string the bar type.
* Valid values are 'info', 'success', and 'danger'.
* @var string the bar type. Valid values are 'info', 'success', and 'danger'.
*/
public $type;
/**
* @var boolean whether the bar is striped.
* @var boolean indicates whether the bar is striped.
*/
public $striped = false;
/**
* @var boolean whether the bar is animated.
* @var boolean indicates whether the bar is animated.
*/
public $animated = false;
/**
* @var integer the progress.
* @var integer the amount of progress in percent.
*/
public $percent = 0;
/**
......
<?php
/**
* BootThumbs class file.
* TbThumbnails class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -11,6 +11,7 @@ Yii::import('bootstrap.widgets.TbListView');
/**
* Bootstrap thumbnails widget.
* @see http://twitter.github.com/bootstrap/components.html#thumbnails
*/
class TbThumbnails extends TbListView
{
......
<?php
/**
* BootTypeahead class file.
* TbTypeahead class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......@@ -9,12 +9,13 @@
*/
/**
* Bootstrap type-a-head widget.
* Bootstrap typeahead widget.
* @see http://twitter.github.com/bootstrap/javascript.html#typeahead
*/
class TbTypeahead extends CInputWidget
{
/**
* @var array the options for the Bootstrap JavaScript plugin.
* @var array the options for the Bootstrap Javascript plugin.
*/
public $options = array();
......@@ -23,9 +24,6 @@ class TbTypeahead extends CInputWidget
*/
public function init()
{
if (!isset($this->htmlOptions['id']))
$this->htmlOptions['id'] = $this->getId();
$this->htmlOptions['type'] = 'text';
$this->htmlOptions['data-provide'] = 'typeahead';
}
......
<?php
/**
* BootInput class file.
* TbInput class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......
<?php
/**
* BootInputHorizontal class file.
* TbInputHorizontal class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......
<?php
/**
* BootInputInline class file.
* TbInputInline class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......
<?php
/**
* BootInputSearch class file.
* TbInputSearch class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......
<?php
/**
* BootInputVertical class file.
* TbInputVertical class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
......
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