Commit 80d276db by Crisu83

added collapse and scrollspy widgets and renamed tabbable to tabs

parent 1cc2899a
<?php
/**
* TbCollapse class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2012-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package bootstrap.widgets
* @since 1.0.0
*/
/**
* Bootstrap collapse widget.
* @see http://twitter.github.com/bootstrap/javascript.html#collapse
*/
class TbCollapse extends CWidget
{
/**
* @var string the name of the collapse element. Defaults to 'a'.
*/
public $tagName = 'div';
/**
* @var boolean the CSS selector for element to collapse. Default to 'false'.
*/
public $parent = false;
/**
* @var boolean indicates whether to toggle the collapsible element on invocation.
*/
public $toggle = true;
/**
* @var array the options for the Bootstrap Javascript plugin.
*/
public $options = array();
/**
* @var string[] the Javascript event handlers.
*/
public $events = array();
/**
* @var array the HTML attributes for the widget container.
*/
public $htmlOptions = array();
/**
* Initializes the widget.
*/
public function init()
{
if (!isset($this->htmlOptions['id']))
$this->htmlOptions['id'] = $this->getId();
if (isset($this->parent) && !isset($this->options['parent']))
$this->options['parent'] = $this->parent;
if (isset($this->toggle) && !isset($this->options['toggle']))
$this->options['toggle'] = $this->toggle;
echo CHtml::tag($this->tagName, $this->htmlOptions);
}
/**
* Runs the widget.
*/
public function run()
{
$id = $this->htmlOptions['id'];
echo CHtml::closeTag($this->tagName);
/** @var CClientScript $cs */
$cs = Yii::app()->getClientScript();
$options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
$cs->registerScript(__CLASS__.'#'.$id, "jQuery('#{$id}').collapse({$options});");
foreach ($this->events as $name => $handler)
{
$handler = CJavaScript::encode($handler);
$cs->registerScript(__CLASS__.'#'.$id.'_'.$name, "jQuery('#{$id}').on('{$name}', {$handler});");
}
}
}
<?php
/**
* TbScrollSpy class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2012-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package bootstrap.widgets
* @since 1.0.0
*/
/**
* Bootstrap scrollspy widget.
* @see http://twitter.github.com/bootstrap/javascript.html#scrollspy
*/
class TbScrollSpy extends CWidget
{
/**
* @var string the CSS selector for the scrollspy element. Defaults to 'body'.
*/
public $selector = 'body';
/**
* @var string the CSS selector for the spying element.
*/
public $target;
/**
* @var integer the scroll offset (in pixels).
*/
public $offset;
/**
* @var array string[] the Javascript event handlers.
*/
public $events = array();
/**
* Runs the widget.
*/
public function run()
{
$script = "jQuery('{$this->selector}').attr('data-spy', 'scroll');";
if (isset($this->target))
$script .= "jQuery('{$this->selector}').attr('data-target', '{$this->target}');";
if (isset($this->offset))
$script .= "jQuery('{$this->selector}').attr('data-offset', '{$this->offset}');";
/** @var CClientScript $cs */
$cs = Yii::app()->getClientScript();
$cs->registerScript(__CLASS__.'#'.$this->selector, $script, CClientScript::POS_BEGIN);
foreach ($this->events as $name => $handler)
{
$handler = CJavaScript::encode($handler);
$cs->registerScript(__CLASS__.'#'.$this->selector.'_'.$name, "jQuery('{$this->selector}').on('{$name}', {$handler});");
}
}
}
<?php <?php
/** /**
* BootTabbable class file. * TbTabs class file.
* @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
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
Yii::import('bootstrap.widgets.TbMenu'); Yii::import('bootstrap.widgets.TbMenu');
/** /**
* Bootstrap JavaScript tabs widget. * Bootstrap Javascript tabs widget.
* @since 0.9.8 * @see http://twitter.github.com/bootstrap/javascript.html#tabs
*/ */
class TbTabbable extends CWidget class TbTabs extends CWidget
{ {
// Tab placements. // Tab placements.
const PLACEMENT_ABOVE = 'above'; const PLACEMENT_ABOVE = 'above';
...@@ -22,9 +22,9 @@ class TbTabbable extends CWidget ...@@ -22,9 +22,9 @@ class TbTabbable extends CWidget
const PLACEMENT_RIGHT = 'right'; const PLACEMENT_RIGHT = 'right';
/** /**
* @var string the type of tabs to display. Defaults to 'tabs'. * @var string the type of tabs to display. Defaults to 'tabs'. Valid values are 'tabs' and 'pills'.
* Valid values are 'tabs' and 'pills'. * Please not that Javascript pills are not fully supported in Bootstrap yet!
* Please not that JavaScript pills are not fully supported in Bootstrap! * @see TbMenu::$type
*/ */
public $type = TbMenu::TYPE_TABS; public $type = TbMenu::TYPE_TABS;
/** /**
...@@ -41,7 +41,7 @@ class TbTabbable extends CWidget ...@@ -41,7 +41,7 @@ class TbTabbable extends CWidget
*/ */
public $encodeLabel = true; public $encodeLabel = true;
/** /**
* @var string[] the JavaScript event handlers. * @var string[] the Javascript event handlers.
*/ */
public $events = array(); public $events = array();
/** /**
...@@ -108,7 +108,7 @@ class TbTabbable extends CWidget ...@@ -108,7 +108,7 @@ class TbTabbable extends CWidget
foreach ($this->events as $name => $handler) foreach ($this->events as $name => $handler)
{ {
$handler = CJavaScript::encode($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});");
} }
} }
...@@ -128,7 +128,7 @@ class TbTabbable extends CWidget ...@@ -128,7 +128,7 @@ class TbTabbable extends CWidget
{ {
$item = $tab; $item = $tab;
if (isset($item['visible']) && !$item['visible']) if (isset($item['visible']) && $item['visible'] === false)
continue; continue;
if (!isset($item['itemOptions'])) if (!isset($item['itemOptions']))
......
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