Commit 130dd139 by Crisu83

Improved the support for glyphicons and updated the demo.

parent 710b7b56
......@@ -94,56 +94,6 @@ class Bootstrap extends CApplicationComponent
}
/**
* Returns whether a plugin is disabled in the plugin configuration.
* @param string $name the name of the plugin
* @return boolean the result
* @since 0.9.8
*/
protected function isPluginDisabled($name)
{
return isset($this->plugins[$name]) || (isset($this->plugins[$name]) && $this->plugins[$name] !== false);
}
/**
* Registers a Bootstrap JavaScript plugin.
* @param string $name the name of the plugin
* @param string $selector the CSS selector
* @param array $options the plugin options
* @param string $defaultSelector the default selector to use
* @since 0.9.8
*/
protected function registerPlugin($name, $selector = null, $options = array(), $defaultSelector = null)
{
if (!$this->isPluginRegistered($name))
{
$this->registerScriptFile("bootstrap-{$name}.js");
$this->_rp[$name] = true;
}
if (!isset($selector) && empty($options))
{
// Initialization from extension configuration.
$config = isset($this->plugins[$name]) ? $this->plugins[$name] : array();
if (isset($config['selector']))
$selector = $config['selector'];
if (isset($config['options']))
$options = $config['options'];
if (!isset($selector))
$selector = $defaultSelector;
}
if (isset($selector))
{
$key = __CLASS__.'.'.md5($name.$selector.serialize($options).$defaultSelector);
$options = !empty($options) ? CJavaScript::encode($options) : '';
Yii::app()->clientScript->registerScript($key, "jQuery('{$selector}').{$name}({$options});");
}
}
/**
* Enables the Bootstrap transitions plugin.
* @since 0.9.8
*/
......@@ -295,6 +245,56 @@ class Bootstrap extends CApplicationComponent
}
/**
* Returns whether a plugin is disabled in the plugin configuration.
* @param string $name the name of the plugin
* @return boolean the result
* @since 0.9.8
*/
protected function isPluginDisabled($name)
{
return isset($this->plugins[$name]) || (isset($this->plugins[$name]) && $this->plugins[$name] !== false);
}
/**
* Registers a Bootstrap JavaScript plugin.
* @param string $name the name of the plugin
* @param string $selector the CSS selector
* @param array $options the plugin options
* @param string $defaultSelector the default selector to use
* @since 0.9.8
*/
protected function registerPlugin($name, $selector = null, $options = array(), $defaultSelector = null)
{
if (!$this->isPluginRegistered($name))
{
$this->registerScriptFile("bootstrap-{$name}.js");
$this->_rp[$name] = true;
}
if (!isset($selector) && empty($options))
{
// Initialization from extension configuration.
$config = isset($this->plugins[$name]) ? $this->plugins[$name] : array();
if (isset($config['selector']))
$selector = $config['selector'];
if (isset($config['options']))
$options = $config['options'];
if (!isset($selector))
$selector = $defaultSelector;
}
if (isset($selector))
{
$key = __CLASS__.'.'.md5($name.$selector.serialize($options).$defaultSelector);
$options = !empty($options) ? CJavaScript::encode($options) : '';
Yii::app()->clientScript->registerScript($key, "jQuery('{$selector}').{$name}({$options});");
}
}
/**
* Registers a JavaScript file in the assets folder.
* @param string $fileName the file name.
* @param integer $position the position of the JavaScript file.
......
......@@ -38,11 +38,8 @@ class SiteController extends Controller
'class'=>'BootButtonColumn',
'htmlOptions'=>array('style'=>'width: 50px'),
'viewButtonUrl'=>null,
'viewButtonOptions'=>array('rel'=>'tooltip'),
'updateButtonUrl'=>null,
'updateButtonOptions'=>array('rel'=>'tooltip'),
'deleteButtonUrl'=>null,
'deleteButtonOptions'=>array('rel'=>'tooltip'),
)
);
......
......@@ -227,13 +227,13 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
'encodeLabel'=>false,
'items'=>array(
array('label'=>'LIST HEADER', 'itemOptions'=>array('class'=>'nav-header')),
array('label'=>'<i class="icon-home"></i> Home', 'url'=>'#', 'active'=>true),
array('label'=>'<i class="icon-book"></i> Library', 'url'=>'#'),
array('label'=>'<i class="icon-pencil"></i> Application', 'url'=>'#'),
array('label'=>'Home', 'icon'=>'home', 'url'=>'#', 'active'=>true),
array('label'=>'Library', 'icon'=>'book', 'url'=>'#'),
array('label'=>'Application', 'icon'=>'pencil', 'url'=>'#'),
array('label'=>'ANOTHER LIST HEADER', 'itemOptions'=>array('class'=>'nav-header')),
array('label'=>'<i class="icon-user"></i> Profile', 'url'=>'#'),
array('label'=>'<i class="icon-cog"></i> Settings', 'url'=>'#'),
array('label'=>'<i class="icon-flag"></i> Help', 'url'=>'#'),
array('label'=>'Profile', 'icon'=>'user', 'url'=>'#'),
array('label'=>'Settings', 'icon'=>'cog', 'url'=>'#'),
array('label'=>'Help', 'icon'=>'flag', 'url'=>'#'),
),
)); ?>
......@@ -248,13 +248,13 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
'encodeLabel'=>false,
'items'=>array(
array('label'=>'LIST HEADER', 'itemOptions'=>array('class'=>'nav-header')),
array('label'=>'<i class=\"icon-home\"></i> Home', 'url'=>'#', 'active'=>true),
array('label'=>'<i class=\"icon-book\"></i> Library', 'url'=>'#'),
array('label'=>'<i class=\"icon-pencil\"></i> Application', 'url'=>'#'),
array('label'=>'Home', 'icon'=>'home', 'url'=>'#', 'active'=>true),
array('label'=>'Library', 'icon'=>'book', 'url'=>'#'),
array('label'=>'Application', 'icon'=>'pencil', 'url'=>'#'),
array('label'=>'ANOTHER LIST HEADER', 'itemOptions'=>array('class'=>'nav-header')),
array('label'=>'<i class=\"icon-user\"></i> Profile', 'url'=>'#'),
array('label'=>'<i class=\"icon-cog\"></i> Settings', 'url'=>'#'),
array('label'=>'<i class=\"icon-flag\"></i> Help', 'url'=>'#'),
array('label'=>'Profile', 'icon'=>'user', 'url'=>'#'),
array('label'=>'Settings', 'icon'=>'cog', 'url'=>'#'),
array('label'=>'Help', 'icon'=>'flag', 'url'=>'#'),
),
)); ?>
~~~"); ?>
......@@ -280,7 +280,7 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
)); ?>
<?php $this->widget('bootstrap.widgets.BootTabbed', array(
'type'=>BootMenu::TYPE_PILLS,
'type'=>'pills',
'htmlOptions'=>array('class'=>'tabbed'),
'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.'),
......@@ -297,6 +297,7 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
<?php echo $parser->safeTransform("~~~
[php]
<?php \$this->widget('bootstrap.widgets.BootTabbed', array(
'type'=>'pills', // '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.'),
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.'),
......@@ -312,6 +313,16 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
</section>
<section id="bootDetailView">
<h2>BootDetailView</h2>
<p>@todo</p>
<a class="top" href="#top">Back to top &uarr;</a>
</section>
<section id="bootGridView">
<h2>BootGridView</h2>
......@@ -325,7 +336,7 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
'columns'=>$gridColumns,
)); ?>
<h3>Striped</h3>moi
<h3>Striped</h3>
<?php $this->widget('bootstrap.widgets.BootGridView', array(
'dataProvider'=>$gridDataProvider,
......@@ -385,9 +396,6 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
array(
'class'=>'BootButtonColumn',
'htmlOptions'=>array('style'=>'width: 50px'),
'viewButtonOptions'=>array('rel'=>'tooltip'),
'updateButtonOptions'=>array('rel'=>'tooltip'),
'deleteButtonOptions'=>array('rel'=>'tooltip'),
),
),
)); ?>
......
......@@ -11,14 +11,14 @@ Yii::import('zii.widgets.grid.CButtonColumn');
/**
* Bootstrap button column widget.
* Used to set buttons to use Glyphicons instead of the defaults.
* Used to set zbuttons to use Glyphicons instead of the defaults.
* @since 0.9.8
*/
class BootButtonColumn extends CButtonColumn
{
public $viewButtonIconCssClass = 'icon-search';
public $updateButtonIconCssClass = 'icon-pencil';
public $deleteButtonIconCssClass = 'icon-trash';
public $viewButtonIcon = 'eye-open';
public $updateButtonIcon = 'pencil';
public $deleteButtonIcon = 'trash';
/**
* Initializes the default buttons (view, update and delete).
......@@ -27,12 +27,12 @@ class BootButtonColumn extends CButtonColumn
{
parent::initDefaultButtons();
if ($this->viewButtonIconCssClass !== false)
$this->buttons['view']['iconCssClass'] = $this->viewButtonIconCssClass;
if ($this->updateButtonIconCssClass !== false)
$this->buttons['update']['iconCssClass'] = $this->updateButtonIconCssClass;
if ($this->deleteButtonIconCssClass !== false)
$this->buttons['delete']['iconCssClass'] = $this->deleteButtonIconCssClass;
if ($this->viewButtonIcon !== false)
$this->buttons['view']['icon'] = $this->viewButtonIcon;
if ($this->updateButtonIcon !== false)
$this->buttons['update']['icon'] = $this->updateButtonIcon;
if ($this->deleteButtonIcon !== false)
$this->buttons['delete']['icon'] = $this->deleteButtonIcon;
}
/**
......@@ -42,25 +42,31 @@ class BootButtonColumn extends CButtonColumn
* @param integer $row the row number (zero-based)
* @param mixed $data the data object associated with the row
*/
protected function renderButton($id,$button,$row,$data)
protected function renderButton($id, $button, $row, $data)
{
if (isset($button['visible']) && !$this->evaluateExpression($button['visible'],array('row'=>$row,'data'=>$data)))
if (isset($button['visible']) && !$this->evaluateExpression($button['visible'], array('row'=>$row, 'data'=>$data)))
return;
$label=isset($button['label']) ? $button['label'] : $id;
$url=isset($button['url']) ? $this->evaluateExpression($button['url'],array('data'=>$data,'row'=>$row)) : '#';
$options=isset($button['options']) ? $button['options'] : array();
$label = isset($button['label']) ? $button['label'] : $id;
$url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data'=>$data, 'row'=>$row)) : '#';
$options = isset($button['options']) ? $button['options'] : array();
if (!isset($options['title']))
$options['title']=$label;
$options['title'] = $label;
if (isset($button['iconCssClass']))
$linkContent = '<i class="'.$button['iconCssClass'].'"></i>';
if (!isset($options['rel']))
$options['rel'] = 'tooltip';
if (isset($button['icon']))
{
if (strpos($button['icon'], 'icon') === false)
$button['icon'] = 'icon-'.$button['icon'];
echo CHtml::link('<i class="'.$button['icon'].'"></i>', $url, $options);
}
else if (isset($button['imageUrl']) && is_string($button['imageUrl']))
$linkContent = CHtml::image($button['imageUrl'],$label);
echo CHtml::link(CHtml::image($button['imageUrl'], $label), $url, $options);
else
$linkContent = $label;
echo CHtml::link($linkContent,$url,$options);
echo CHtml::link($label, $url, $options);
}
}
......@@ -176,7 +176,16 @@ class BootMenu extends BootWidget
}
if (isset($item['url']))
{
if (isset($item['icon'])) {
if (strpos($item['icon'], 'icon') === false)
$item['icon'] = 'icon-'.$item['icon'];
$item['label'] = '<i class="'.$item['icon'].'"></i> '.$item['label'];
}
return CHtml::link($item['label'], $item['url'], isset($item['linkOptions']) ? $item['linkOptions'] : array());
}
else
return $item['label'];
}
......
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