Commit 796bad96 by Crisu83

fixed a bug in BootTabbable and improved BootButton

parent 370aac36
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @author Christoffer Niska <ChristofferNiska@gmail.com> * @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011- * @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version 0.9.10 * @version 1.0.0
*/ */
/** /**
...@@ -56,14 +56,15 @@ class Bootstrap extends CApplicationComponent ...@@ -56,14 +56,15 @@ class Bootstrap extends CApplicationComponent
*/ */
public function init() public function init()
{ {
// Register the bootstrap path alias.
if (!Yii::getPathOfAlias('bootstrap'))
Yii::setPathOfAlias('bootstrap', realpath(dirname(__FILE__).'/..'));
// Prevents the extension from registering scripts // Prevents the extension from registering scripts
// and publishing assets when ran from the command line. // and publishing assets when ran from the command line.
if (php_sapi_name() === 'cli') if (php_sapi_name() === 'cli')
return; return;
if (!Yii::getPathOfAlias('bootstrap'))
Yii::setPathOfAlias('bootstrap', realpath(dirname(__FILE__).'/..'));
if ($this->coreCss) if ($this->coreCss)
$this->registerCss(); $this->registerCss();
...@@ -78,16 +79,6 @@ class Bootstrap extends CApplicationComponent ...@@ -78,16 +79,6 @@ class Bootstrap extends CApplicationComponent
} }
/** /**
* Returns whether a plugin is registered.
* @param string $name the name of the plugin
* @return boolean the result
*/
public function isPluginRegistered($name)
{
return isset($this->_rp[$name]);
}
/**
* Registers the Bootstrap CSS. * Registers the Bootstrap CSS.
*/ */
public function registerCss() public function registerCss()
...@@ -108,7 +99,7 @@ class Bootstrap extends CApplicationComponent ...@@ -108,7 +99,7 @@ class Bootstrap extends CApplicationComponent
* Registers the core JavaScript plugins. * Registers the core JavaScript plugins.
* @since 0.9.8 * @since 0.9.8
*/ */
protected function registerCorePlugins() public function registerCorePlugins()
{ {
if (!$this->isPluginDisabled(self::PLUGIN_TRANSITION)) if (!$this->isPluginDisabled(self::PLUGIN_TRANSITION))
$this->enableTransitions(); $this->enableTransitions();
...@@ -282,6 +273,16 @@ class Bootstrap extends CApplicationComponent ...@@ -282,6 +273,16 @@ class Bootstrap extends CApplicationComponent
} }
/** /**
* Returns whether a plugin is registered.
* @param string $name the name of the plugin
* @return boolean the result
*/
public function isPluginRegistered($name)
{
return isset($this->_rp[$name]);
}
/**
* Returns whether a plugin is disabled in the plugin configuration. * Returns whether a plugin is disabled in the plugin configuration.
* @param string $name the name of the plugin * @param string $name the name of the plugin
* @return boolean the result * @return boolean the result
......
...@@ -286,8 +286,8 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin ...@@ -286,8 +286,8 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
<?php echo $parser->safeTransform("~~~ <?php echo $parser->safeTransform("~~~
[php] [php]
<?php \$this->widget('bootstrap.widgets.BootTabbed', array( <?php \$this->widget('bootstrap.widgets.BootTabbable', array(
'type'=>'pills', // 'tabs' or 'pills' 'type'=>'tabs', // 'tabs' or 'pills'
'tabs'=>array( '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.'), 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.'),
array('label'=>'Profile', 'content'=>'Food truck fixie locavore, accusamus mcsweeney\'s marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.'), array('label'=>'Profile', 'content'=>'Food truck fixie locavore, accusamus mcsweeney\'s marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.'),
...@@ -344,9 +344,9 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin ...@@ -344,9 +344,9 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
<?php echo $parser->safeTransform("~~~ <?php echo $parser->safeTransform("~~~
[php] [php]
<?php \$this->widget('bootstrap.widgets.BootTabbed', array( <?php \$this->widget('bootstrap.widgets.BootTabbable', array(
'type'=>'tabs', 'type'=>'tabs',
'placement'=>'below', // '', 'right', 'below' or 'left' 'placement'=>'below', // 'above', 'right', 'below' or 'left'
'tabs'=>array( 'tabs'=>array(
array('label'=>'Section 1', 'content'=>'<p>I\'m in Section 1.</p>'), array('label'=>'Section 1', 'content'=>'<p>I\'m in Section 1.</p>'),
array('label'=>'Section 2', 'content'=>'<p>Howdy, I\'m in Section 2.</p>'), array('label'=>'Section 2', 'content'=>'<p>Howdy, I\'m in Section 2.</p>'),
......
...@@ -94,6 +94,11 @@ class BootButton extends BootWidget ...@@ -94,6 +94,11 @@ class BootButton extends BootWidget
* @var array the button ajax options (used by 'ajaxLink' and 'ajaxButton'). * @var array the button ajax options (used by 'ajaxLink' and 'ajaxButton').
*/ */
public $ajaxOptions = array(); public $ajaxOptions = array();
/**
* @var array the HTML options for the dropdown menu.
* @since 1.0.0
*/
public $dropdownOptions = array();
/** /**
* Initializes the widget. * Initializes the widget.
...@@ -113,9 +118,8 @@ class BootButton extends BootWidget ...@@ -113,9 +118,8 @@ class BootButton extends BootWidget
if (isset($this->size) && in_array($this->size, $validSizes)) if (isset($this->size) && in_array($this->size, $validSizes))
$class[] = 'btn-'.$this->size; $class[] = 'btn-'.$this->size;
if ($this->active) { if ($this->active)
$class[] = 'active'; $class[] = 'active';
}
if ($this->encodeLabel) if ($this->encodeLabel)
$this->label = CHtml::encode($this->label); $this->label = CHtml::encode($this->label);
...@@ -128,7 +132,6 @@ class BootButton extends BootWidget ...@@ -128,7 +132,6 @@ class BootButton extends BootWidget
$class[] = 'dropdown-toggle'; $class[] = 'dropdown-toggle';
$this->label .= ' <span class="caret"></span>'; $this->label .= ' <span class="caret"></span>';
$this->htmlOptions['data-toggle'] = 'dropdown'; $this->htmlOptions['data-toggle'] = 'dropdown';
Yii::app()->bootstrap->registerDropdown();
} }
$cssClass = implode(' ', $class); $cssClass = implode(' ', $class);
...@@ -177,7 +180,11 @@ class BootButton extends BootWidget ...@@ -177,7 +180,11 @@ class BootButton extends BootWidget
echo $this->createButton(); echo $this->createButton();
if ($this->hasDropdown()) if ($this->hasDropdown())
$this->controller->widget('bootstrap.widgets.BootDropdown', array('items'=>$this->items)); $this->controller->widget('bootstrap.widgets.BootDropdown', array(
'encodeLabel'=>$this->encodeLabel,
'items'=>$this->items,
'htmlOptions'=>$this->dropdownOptions,
));
} }
/** /**
......
...@@ -126,6 +126,7 @@ class BootMenu extends BootBaseMenu ...@@ -126,6 +126,7 @@ class BootMenu extends BootBaseMenu
if(isset($item['items']) && !empty($item['items'])) if(isset($item['items']) && !empty($item['items']))
{ {
$this->controller->widget('bootstrap.widgets.BootDropdown', array( $this->controller->widget('bootstrap.widgets.BootDropdown', array(
'encodeLabel'=>$this->encodeLabel,
'items'=>$item['items'], 'items'=>$item['items'],
'htmlOptions'=>isset($item['dropdownOptions']) ? $item['dropdownOptions'] : $this->dropdownOptions, 'htmlOptions'=>isset($item['dropdownOptions']) ? $item['dropdownOptions'] : $this->dropdownOptions,
)); ));
......
...@@ -51,17 +51,15 @@ class BootTabbable extends BootWidget ...@@ -51,17 +51,15 @@ class BootTabbable extends BootWidget
if (!isset($this->htmlOptions['id'])) if (!isset($this->htmlOptions['id']))
$this->htmlOptions['id'] = $this->getId(); $this->htmlOptions['id'] = $this->getId();
if (isset($this->placement)) $validPlacements = array(self::PLACEMENT_ABOVE, self::PLACEMENT_BELOW, self::PLACEMENT_LEFT, self::PLACEMENT_RIGHT);
if (isset($this->placement) && in_array($this->placement, $validPlacements))
{ {
$validPlacements = array(self::PLACEMENT_ABOVE, self::PLACEMENT_BELOW, self::PLACEMENT_LEFT, self::PLACEMENT_RIGHT); $cssClass = 'tabs-'.$this->placement;
if (in_array($this->placement, $validPlacements)) if (isset($this->htmlOptions['class']))
{ $this->htmlOptions['class'] .= ' '.$cssClass;
$cssClass = 'tabs-'.$this->placement; else
if (isset($this->htmlOptions['class'])) $this->htmlOptions['class'] = $cssClass;
$this->htmlOptions['class'] .= ' '.$cssClass;
else
$this->htmlOptions['class'] = $cssClass;
}
} }
Yii::app()->bootstrap->registerTabs(); Yii::app()->bootstrap->registerTabs();
...@@ -151,7 +149,7 @@ class BootTabbable extends BootWidget ...@@ -151,7 +149,7 @@ class BootTabbable extends BootWidget
else else
{ {
if (!isset($item['id'])) if (!isset($item['id']))
$item['id'] = $id.'_tab_'.++$i; $item['id'] = $id.'_tab_'.($i + 1);
$item['url'] = '#'.$item['id']; $item['url'] = '#'.$item['id'];
...@@ -169,23 +167,28 @@ class BootTabbable extends BootWidget ...@@ -169,23 +167,28 @@ class BootTabbable extends BootWidget
$paneOptions['id'] = $item['id']; $paneOptions['id'] = $item['id'];
if (isset($tab['paneOptions']['class'])) $class = array('tab-pane');
$paneOptions['class'] .= ' tab-pane';
else
$paneOptions['class'] = 'tab-pane';
if ($transitions) if ($transitions)
$paneOptions['class'] .= ' fade'; $class[] = 'fade';
if ($i === 1) if ($i === 0)
{ {
if ($transitions) $class[] = 'active';
$paneOptions['class'] .= ' in';
$paneOptions['class'] .= ' active'; if ($transitions)
$class[] = 'in';
} }
$cssClass = implode(' ', $class);
if (isset($paneOptions['class']))
$paneOptions['class'] .= $cssClass;
else
$paneOptions['class'] = $cssClass;
$panes[] = CHtml::tag('div', $paneOptions, $content); $panes[] = CHtml::tag('div', $paneOptions, $content);
$i++; // increment the tab-index
} }
$items[] = $item; $items[] = $item;
......
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