Commit a8ced14d by Crisu83

Added the BootTabs widget and made some minor improvements.

parent 483dc174
/*!
* Bootstrap Tabs jQuery UI widget 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
* @see http://twitter.github.com/bootstrap
*/
( function( $ ) {
"use strict" // set strict mode
var widget = $.extend( {}, $.ui.bootWidget.prototype, {
/**
* The name of the widget.
* @type String
*/
name: 'tabs',
/**
* Widget options.
* @type Object
*/
options: {
},
/**
* Creates the widget.
*/
_create: function() {
var self = this,
element = self.element,
options = self.options,
title = self.element.attr( 'title' );
element.bind('click', function( event ) {
self._tab( event );
});
},
_activate: function( element, container ) {
container.find( '> .active' )
.removeClass( 'active' )
.find( '> .dropdown-menu > .active' )
.removeClass( 'active' );
element.addClass( 'active' );
if ( element.parent( '.dropdown-menu' ) ) {
element.closest( 'li.dropdown' ).addClass( 'active' );
}
},
_tab: function( event ) {
var self = this,
element = self.element,
ul = element.closest( 'ul:not(.dropdown-menu)' ),
href = element.attr( 'href' ),
previous, pane;
if ( /^#\w+/.test( href ) ) {
event.preventDefault();
if ( !element.parent( 'li' ).hasClass( 'active' ) ) {
previous = ul.find( '.active a' ).last()[0];
pane = $( href );
self._activate( element.parent( 'li' ), ul );
self._activate( pane, pane.parent() );
element.trigger( {
type: 'change',
relatedTarget: previous
} );
}
}
},
/**
* Destructs this widget.
*/
_destroy: function() {
// Nothing here yet...
}
} );
/**
* BootTabs jQuery UI widget.
*/
$.widget( 'ui.bootTabs', widget );
} )( jQuery );
\ No newline at end of file
......@@ -46,7 +46,7 @@
var self = this,
element = self.element,
options = self.options,
title = self.element.attr( 'title' ),
title = element.attr( 'title' ),
binder = options.live ? 'live' : 'bind';
if ( title && title.length > 0 ) {
......@@ -54,12 +54,11 @@
element.attr( 'data-title', title );
element[ binder ]( options.showEvent, function() {
self.show();
});
self.show();
});
element[ binder ]( options.hideEvent, function() {
self.hide();
});
self.hide();
});
}
},
/**
......
......@@ -12,9 +12,9 @@ class BootstrapCode extendS CrudCode
public function generateActiveRow($modelClass, $column)
{
if ($column->type === 'boolean')
return "\$form->checkBoxRow(\$model,'{$column->name}')";
return "\$form->checkBoxBlock(\$model,'{$column->name}')";
else if (stripos($column->dbType,'text') !== false)
return "\$form->textAreaRow(\$model,'{$column->name}',array('rows'=>6, 'cols'=>50, 'class'=>'span8'))";
return "\$form->textAreaBlock(\$model,'{$column->name}',array('rows'=>6, 'cols'=>50, 'class'=>'span8'))";
else
{
if (preg_match('/^(password|pass|passwd|passcode)$/i',$column->name))
......
/* Reset.less
* Props to Eric Meyer (meyerweb.com) for his CSS reset file. We're using an adapted version here that cuts out some of the reset HTML elements we will never need here (i.e., dfn, samp, etc).
* ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
......
......@@ -58,7 +58,7 @@ class BootAlert extends BootWidget
$this->options['keys'] = $this->keys;
$this->options['template'] = $this->template;
$options = CJavaScript::encode($this->options);
$options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').bootAlert({$options});");
}
}
\ No newline at end of file
......@@ -6,38 +6,77 @@
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
*/
Yii::import('zii.widgets.grid.CDataColumn');
/**
* Thanks to Simo Jokela <rBoost@gmail.com> for writing the original version of this class.
*/
Yii::import('zii.widgets.grid.CDataColumn');
class BootDataColumn extends CDataColumn
{
/**
* @properties string the header color for sortable columns.
* Valid values are: 'blue', 'green', 'red', 'yellow', 'orange' and 'purple'.
*/
public $color;
/**
* Initializes the column.
*/
public function init()
{
if (isset($this->headerHtmlOptions['class']))
$this->headerHtmlOptions['class'] .= ' header';
else
$this->headerHtmlOptions['class'] = 'header';
if ($this->grid->enableSorting && $this->sortable && $this->name !== null)
{
$colorCss = $this->color !== null ? ' '.$this->color : '';
$class = 'header'.$colorCss;
if (isset($this->headerHtmlOptions['class']))
$this->headerHtmlOptions['class'] .= $class;
else
$this->headerHtmlOptions['class'] = $class;
}
/*
$matches = array();
preg_match('/href\="(.*)"/i', $this->grid->dataProvider->sort->link($this->name), $matches);
if (isset($matches[1]))
$url = $matches[1];
*/
parent::init();
}
/**
* Renders the header cell content.
*/
/*
protected function renderHeaderCellContent()
{
if($this->name!==null && $this->header===null)
{
if($this->grid->dataProvider instanceof CActiveDataProvider)
echo CHtml::encode($this->grid->dataProvider->model->getAttributeLabel($this->name));
else
echo CHtml::encode($this->name);
}
else
echo trim($this->header) !== '' ? $this->header : $this->grid->blankDisplay;
}
*/
/**
* Renders the header cell.
*/
public function renderHeaderCell()
{
if ($this->grid->enableSorting && $this->sortable && $this->name !== null)
{
$sortDir = $this->grid->dataProvider->getSort()->getDirection($this->name);
$direction = $this->grid->dataProvider->sort->getDirection($this->name);
if ($sortDir !== null)
if ($direction !== null)
{
$sortCssClass = $sortDir ? 'headerSortDown' : 'headerSortUp';
$sortCssClass = $direction ? 'headerSortDown' : 'headerSortUp';
$this->headerHtmlOptions['class'] .= ' '.$sortCssClass;
}
}
......
......@@ -101,7 +101,7 @@ class BootInput extends CInputWidget
break;
default:
throw new CException(Yii::t('bootstrap',__CLASS__.': Failed to run widget! Input type is invalid.'));
throw new CException(__CLASS__.': '.Yii::t('bootstrap','Failed to run widget! Input type is invalid.'));
}
echo '</div>';
......@@ -109,12 +109,12 @@ class BootInput extends CInputWidget
protected function checkBox()
{
echo '<div class="input">';
echo '<div class="input"><div class="inputs-list">';
echo '<label for="'.CHtml::getIdByName(CHtml::resolveName($this->model, $this->attribute)).'">';
echo $this->form->checkBox($this->model, $this->attribute, $this->htmlOptions).' ';
echo '<span>'.$this->model->getAttributeLabel($this->attribute).'</span>';
echo $this->getHint().$this->getError();
echo '</label></div>';
echo '</label></div></div>';
}
protected function checkBoxList()
......@@ -151,12 +151,12 @@ class BootInput extends CInputWidget
protected function radioButton()
{
echo '<div class="input">';
echo '<div class="input"><div class="inputs-list">';
echo '<label for="'.CHtml::getIdByName(CHtml::resolveName($this->model, $this->attribute)).'">';
echo $this->form->radioButton($this->model, $this->attribute, $this->htmlOptions).' ';
echo '<span>'.$this->model->getAttributeLabel($this->attribute).'</span>';
echo $this->getHint().$this->getError();
echo '</label></div>';
echo '</label></div></div>';
}
protected function radioButtonList()
......
......@@ -14,7 +14,7 @@ class BootMenu extends CMenu
* @property string the type of menu to display.
* Following types are supported: 'tabs' and 'pills'.
*/
public $type='tabs';
public $type = 'tabs';
/**
* Initializes the menu widget.
......@@ -24,9 +24,9 @@ class BootMenu extends CMenu
public function init()
{
if (isset($this->htmlOptions['class']))
$this->htmlOptions['class'].=' '.$this->type;
$this->htmlOptions['class'] .= ' '.$this->type;
else
$this->htmlOptions['class']=$this->type;
$this->htmlOptions['class'] = $this->type;
parent::init();
}
......
<?php
/**
* BootTabs 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
* @since 0.9.6
*/
Yii::import('ext.bootstrap.widgets.BootWidget');
class BootTabs extends BootWidget
{
/**
* @property string the type of tabs to display. Defaults to 'tabs'.
* Valid values are 'tabs' and 'pills'.
*/
public $type = 'tabs';
/**
* @property array the tab configuration.
*/
public $tabs = array();
/**
* @property string the name of the container element that contains all panels. Defaults to 'div'.
*/
public $tagName = 'div';
/**
* @property string the template to use for displaying the header.
*/
public $headerTemplate = '<li class="{class}"><a href="{url}">{title}</a></li>';
/**
* @property string the template to use for displaying the content.
*/
public $contentTemplate = '<div class="tab-pane {class}" id="{id}">{content}</div>';
/**
* @property string the CSS selector to use for selecting the tabs elements.
*/
public $selector = '.tabs li > a, .pills > li > a';
/**
* Initializes the widget.
*/
public function init()
{
parent::init();
$this->registerScriptFile('jquery.ui.boottabs.js');
}
/**
* Run this widget.
*/
public function run()
{
$id = $this->getId();
if (isset($this->htmlOptions['id']))
$id = $this->htmlOptions['id'];
else
$this->htmlOptions['id'] = $id;
echo CHtml::openTag($this->tagName, $this->htmlOptions);
$tabsOut = '';
$contentOut = '';
$tabCount = 0;
foreach ($this->tabs as $title => $content)
{
$tabId = (is_array($content) && isset($content['id'])) ? $content['id'] : $id.'_tab_'.$tabCount++;
if (!is_array($content))
{
$tabsOut .= strtr($this->headerTemplate, array(
'{title}'=>$title,
'{url}'=>'#'.$tabId,
'{id}'=>'#'.$tabId,
'{class}'=>$tabCount === 1 ? 'active' : '',
));
$contentOut .= strtr($this->contentTemplate, array(
'{content}'=>$content,
'{id}'=>$tabId,
'{class}'=>$tabCount === 1 ? 'active' : '',
));
}
elseif (isset($content['ajax']))
{
$tabsOut .= strtr($this->headerTemplate, array(
'{title}'=>$title,
'{url}'=>CHtml::normalizeUrl($content['ajax']),
'{id}'=>'#'.$tabId,
'{class}'=>$tabCount === 1 ? 'active' : '',
));
}
else
{
$tabsOut .= strtr($this->headerTemplate, array(
'{title}'=>$title,
'{url}'=>'#'.$tabId,
'{class}'=>$tabCount === 1 ? 'active' : '',
));
if(isset($content['content']))
{
$contentOut .= strtr($this->contentTemplate, array(
'{content}'=>$content['content'],
'{id}'=>$tabId,
'{class}'=>$tabCount === 1 ? 'active' : '',
));
}
}
}
echo CHtml::openTag('ul', array('class'=>$this->type, 'data-'.$this->type=>$this->type));
echo $tabsOut;
echo '</ul>';
echo CHtml::openTag('div', array('class'=>$this->type === 'tabs' ? 'tab-content' : 'pill-content'));
echo $contentOut;
echo '</div>';
echo CHtml::closeTag($this->tagName);
$options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
Yii::app()->clientScript->registerScript(__CLASS__.'#'.$id,"jQuery('{$this->selector}').bootTabs({$options});");
}
}
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