Commits

Christoffer Niska committed 5998ef8

added option to disable js, refactored code and updated the demo

Comments (0)

Files changed (19)

components/Bootstrap.php

 	 */
 	public $responsiveCss = false;
 	/**
+	 * @var boolean whether to register jQuery and the Bootstrap JavaScript.
+	 */
+	public $enableJS = true;
+	/**
 	 * @var array the plugin options (name=>options).
 	 * @since 0.9.8
 	 */
 		if ($this->responsiveCss)
 			$this->registerResponsiveCss();
 
-		Yii::app()->clientScript->registerCoreScript('jquery');
-		$this->registerCorePlugins();
+		if ($this->enableJS)
+		{
+			Yii::app()->clientScript->registerCoreScript('jquery');
+			$this->registerCorePlugins();
+		}
 	}
 
 	/**

demo/protected/views/layouts/main.php

 	)); ?>
 
 	<?php if (!empty($this->breadcrumbs)):?>
-		<?php $this->widget('bootstrap.widgets.BootCrumb', array(
+		<?php $this->widget('bootstrap.widgets.BootBreadcrumbs', array(
 			'links'=>$this->breadcrumbs,
 		)); ?>
 	<?php endif?>

demo/protected/views/site/index.php

 
 </section>
 
-<section id="bootCrumb">
+<section id="bootBreadcrumbs">
 
 	<h2>Breadcrumbs</h2>
 
-	<?php $this->widget('bootstrap.widgets.BootCrumb', array(
+	<?php $this->widget('bootstrap.widgets.BootBreadcrumbs', array(
 		'links'=>array('Library'=>'#', 'Data'),
 	)); ?>
 
 
 <?php echo $parser->safeTransform("~~~
 [php]
-<?php \$this->widget('bootstrap.widgets.BootCrumb', array(
+<?php \$this->widget('bootstrap.widgets.BootBreadcrumbs', array(
 	'links'=>array('Library'=>'#', 'Data'),
 )); ?>
 ~~~"); ?>
 					array('label'=>'Link', 'url'=>'#'),
 					array('label'=>'Link', 'url'=>'#'),
 					array('label'=>'Dropdown', 'url'=>'#', 'items'=>array(
-						array('label'=>'DROPDOWN HEADER', 'header'=>true),
+						array('label'=>'DROPDOWN HEADER'),
 						array('label'=>'Action', 'url'=>'#'),
 						array('label'=>'Another action', 'url'=>'#'),
 						array('label'=>'Something else here', 'url'=>'#'),
 				'items'=>array(
 					array('label'=>'Link', 'url'=>'#'),
 					array('label'=>'Dropdown', 'url'=>'#', 'items'=>array(
+						array('label'=>'DROPDOWN HEADER'),
 						array('label'=>'Action', 'url'=>'#'),
 						array('label'=>'Another action', 'url'=>'#'),
 						array('label'=>'Something else here', 'url'=>'#'),
 				array('label'=>'Home', 'url'=>'#', 'active'=>true),
 				array('label'=>'Link', 'url'=>'#'),
 				array('label'=>'Dropdown', 'url'=>'#', 'items'=>array(
-					array('label'=>'DROPDOWN HEADER', 'itemOptions'=>array('class'=>'nav-header')),
+					array('label'=>'DROPDOWN HEADER'),
 					array('label'=>'Action', 'url'=>'#'),
 					array('label'=>'Another action', 'url'=>'#'),
 					array('label'=>'Something else here', 'url'=>'#'),
 			'items'=>array(
 				array('label'=>'Link', 'url'=>'#'),
 				array('label'=>'Dropdown', 'url'=>'#', 'items'=>array(
+					array('label'=>'DROPDOWN HEADER'),
 					array('label'=>'Action', 'url'=>'#'),
 					array('label'=>'Another action', 'url'=>'#'),
 					array('label'=>'Something else here', 'url'=>'#'),
 
 </section>
 
-<section id="bootThumbs">
+<section id="bootThumbnails">
 
 	<h2>Thumbnails</h2>
 
-	<?php $this->widget('bootstrap.widgets.BootThumbs', array(
+	<?php $this->widget('bootstrap.widgets.BootThumbnails', array(
 		'dataProvider'=>$listDataProvider,
 		'template'=>"{items}\n{pager}",
 		'itemView'=>'_thumb',
 
 <?php echo $parser->safeTransform("~~~
 [php]
-<?php \$this->widget('bootstrap.widgets.BootThumbs', array(
+<?php \$this->widget('bootstrap.widgets.BootThumbnails', array(
 	'dataProvider'=>\$listDataProvider,
 	'template'=>\"{items}\\n{pager}\",
 	'itemView'=>'_thumb',
 
 	<?php $this->endWidget(); ?>
 
-	<div class="alert alert-block alert-warning">
-
-	</div>
-
 	<h3>Horizontal</h3>
 
 	<?php /** @var BootActiveForm $form */
 		'scrollspy'=>array('spy'=>'.subnav', 'offset'=>50),
 		'items'=>array(
 			array('label'=>'Alert', 'url'=>'#bootAlert'),
-			array('label'=>'Breadcrumb', 'url'=>'#bootCrumb'),
+			array('label'=>'Breadcrumb', 'url'=>'#bootBreadcrumbs'),
 			array('label'=>'Navbar', 'url'=>'#bootNavbar'),
 			array('label'=>'Menu', 'url'=>'#bootMenu'),
 			array('label'=>'Tabbable', 'url'=>'#bootTabbable'),
 			array('label'=>'Detail view', 'url'=>'#bootDetailView'),
 			array('label'=>'Grid view', 'url'=>'#bootGridView'),
-			array('label'=>'Thumbnail', 'url'=>'#bootThumbs'),
+			array('label'=>'Thumbnail', 'url'=>'#bootThumbnails'),
 			array('label'=>'Tooltip', 'url'=>'#bootTooltip'),
 			array('label'=>'Popover', 'url'=>'#bootPopover'),
 			array('label'=>'Modal', 'url'=>'#bootModal'),

widgets/BootActiveForm.php

  */
 class BootActiveForm extends CActiveForm
 {
-	// The different form types.
+	// Form types.
 	const TYPE_VERTICAL = 'vertical';
 	const TYPE_INLINE = 'inline';
 	const TYPE_HORIZONTAL = 'horizontal';
 	const TYPE_SEARCH = 'search';
 
+	// Input classes.
 	const INPUT_HORIZONTAL = 'bootstrap.widgets.input.BootInputHorizontal';
 	const INPUT_INLINE = 'bootstrap.widgets.input.BootInputInline';
 	const INPUT_SEARCH = 'bootstrap.widgets.input.BootInputSearch';

widgets/BootBaseMenu.php

 			$item['label'] = '<i class="'.$item['icon'].'"></i> '.$item['label'];
 		}
 
-		if (!isset($item['header']) && !isset($item['url']))
-			$item['url'] = '#';
-
 		if (isset($item['url']))
 			return CHtml::link($item['label'], $item['url'], $item['linkOptions']);
 		else

widgets/BootBreadcrumbs.php

+<?php
+/**
+ * BootCrumb 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
+ * @package bootstrap.widgets
+ */
+
+Yii::import('zii.widgets.CBreadcrumbs');
+
+/**
+ * Bootstrap breadcrumb widget.
+ */
+class BootBreadcrumbs extends CBreadcrumbs
+{
+	/**
+	 * @var array the HTML attributes for the breadcrumbs container tag.
+	 */
+	public $htmlOptions = array('class'=>'breadcrumb');
+	/**
+	 * @var string the separator between links in the breadcrumbs (defaults to ' / ').
+	 */
+	public $separator = '/';
+
+	/**
+	 * Renders the content of the widget.
+	 */
+	public function run()
+	{
+		$links = array();
+
+		if ($this->homeLink === null || !(isset($this->homeLink['label']) && isset($this->homeLink['url'])))
+			$this->homeLink = array('label'=>Yii::t('bootstrap', 'Home'),'url'=>Yii::app()->homeUrl);
+
+		if (!empty($this->links))
+		{
+			$content = CHtml::link($this->homeLink['label'], $this->homeLink['url']);
+			$links[] = $this->renderItem($content);
+		}
+		else
+			$links[] = $this->renderItem($this->homeLink['label'], true);
+
+		foreach ($this->links as $label=>$url)
+		{
+			if (is_string($label) || is_array($url))
+			{
+				$label = $this->encodeLabel ? CHtml::encode($label) : $label;
+				$content = CHtml::link($label, $url);
+				$links[] = $this->renderItem($content);
+			}
+			else
+				$links[] = $this->renderItem($this->encodeLabel ? CHtml::encode($url) : $url, true);
+		}
+
+		echo CHtml::openTag('ul', $this->htmlOptions);
+		echo implode('', $links);
+		echo '</ul>';
+	}
+
+	/**
+	 * Renders a single breadcrumb item.
+	 * @param string $content the content.
+	 * @param boolean $active whether the item is active.
+	 * @return string the markup.
+	 */
+	protected function renderItem($content, $active=false)
+	{
+		$separator = !$active ? '<span class="divider">'.$this->separator.'</span>' : '';
+		
+		ob_start();
+		echo CHtml::openTag('li', $active ? array('class'=>'active') : array());
+		echo $content.$separator;
+		echo '</li>';
+		return ob_get_clean();
+	}
+}

widgets/BootButton.php

 
 Yii::import('bootstrap.widgets.BootWidget');
 
+/**
+ * Bootstrap button widget.
+ */
 class BootButton extends BootWidget
 {
+	// Button methods.
 	const METHOD_LINK = 'link';
 	const METHOD_BUTTON = 'button';
 	const METHOD_AJAXLINK = 'ajaxLink';
 	const METHOD_AJAXBUTTON = 'ajaxButton';
 
+	// Button types.
 	const TYPE_NORMAL = '';
 	const TYPE_PRIMARY = 'primary';
 	const TYPE_INFO = 'info';
 	const TYPE_DANGER = 'danger';
 	const TYPE_INVERSE = 'inverse';
 
+	// Button sizes.
 	const SIZE_SMALL = 'small';
 	const SIZE_NORMAL = '';
 	const SIZE_LARGE = 'large';
 
+	/**
+	 * @var string the method to use for rendering the button.
+	 * Valid values are 'link', 'button', 'ajaxLink' and 'ajaxButton'.
+	 */
 	public $method = self::METHOD_LINK;
+	/**
+	 * @var string the button type.
+	 * Valid values are '', 'primary', 'info', 'success', 'warning', 'danger' and 'inverse'.
+	 */
 	public $type = self::TYPE_NORMAL;
+	/**
+	 * @var string the button size.
+	 * Valid values are '', 'small' and 'large'.
+	 */
 	public $size = self::SIZE_NORMAL;
+	/**
+	 * @var string the button icon, e.g. 'ok' or 'remove white'.
+	 */
 	public $icon;
+	/**
+	 * @var string the button label.
+	 */
 	public $label;
+	/**
+	 * @var string the button URL.
+	 */
 	public $url;
+	/**
+	 * @var boolean indicates whether the button is active.
+	 */
 	public $active = false;
+	/**
+	 * @var array the dropdown button items.
+	 */
 	public $items;
+	/**
+	 * @var boolean indicates whether to enable toggle.
+	 */
 	public $toggle;
+	/**
+	 * @var string the loading text.
+	 */
 	public $loadingText;
+	/**
+	 * @var string the complete text.
+	 */
 	public $completeText;
+	/**
+	 * @var boolean indicates whether to encode the label.
+	 */
 	public $encodeLabel = true;
+	/**
+	 * @var array the button ajax options (used by 'ajaxLink' and 'ajaxButton').
+	 */
 	public $ajaxOptions = array();
 
 	/**
 
 		if ($this->hasDropdown())
 		{
+			if (!isset($this->url))
+				$this->url = '#';
+
 			$class[] = 'dropdown-toggle';
 			$this->label .= ' <span class="caret"></span>';
 			$this->htmlOptions['data-toggle'] = 'dropdown';

widgets/BootButtonColumn.php

  * @copyright  Copyright &copy; Christoffer Niska 2011-
  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  * @package bootstrap.widgets
+ * @since 0.9.8
  */
 
 Yii::import('zii.widgets.grid.CButtonColumn');
 
 /**
  * Bootstrap button column widget.
- * Used to set zbuttons to use Glyphicons instead of the defaults.
- * @since 0.9.8
+ * Used to set buttons to use Glyphicons instead of the defaults images.
  */
 class BootButtonColumn extends CButtonColumn
 {
+	/**
+	 * @var string the view button icon (defaults to 'eye-open').
+	 */
 	public $viewButtonIcon = 'eye-open';
+	/**
+	 * @var string the update button icon (defaults to 'pencil').
+	 */
 	public $updateButtonIcon = 'pencil';
+	/**
+	 * @var string the delete button icon (defaults to 'trash').
+	 */
 	public $deleteButtonIcon = 'trash';
 
 	/**

widgets/BootButtonGroup.php

 Yii::import('bootstrap.widgets.BootButton');
 Yii::import('bootstrap.widgets.BootWidget');
 
+/**
+ * Bootstrap button group widget.
+ */
 class BootButtonGroup extends BootWidget
 {
+	// Toggle options.
 	const TOGGLE_CHECKBOX = 'checkbox';
 	const TOGGLE_RADIO = 'radio';
 
+	/**
+	 * @var string the button method.
+	 * @see BootButton::method
+	 */
 	public $method = BootButton::METHOD_LINK;
+	/**
+	 * @var string the button type.
+	 * @see BootButton::type
+	 */
 	public $type = BootButton::TYPE_NORMAL;
+	/**
+	 * @var string the button size.
+	 * @see BootButton::size
+	 */
 	public $size = BootButton::SIZE_NORMAL;
+	/**
+	 * @var boolean indicates whether to encode the button labels.
+	 */
 	public $encodeLabel = true;
+	/**
+	 * @var array the button configuration.
+	 */
 	public $buttons = array();
+	/**
+	 * @var boolean indicates whether to enable button toggling.
+	 */
 	public $toggle;
 
+	/**
+	 * Initializes the widget.
+	 */
 	public function init()
 	{
 		$cssClass = 'btn-group';
 		}
 	}
 
+	/**
+	 * Runs the widget.
+	 */
 	public function run()
 	{
 		echo CHtml::openTag('div', $this->htmlOptions);

widgets/BootCrumb.php

-<?php
-/**
- * BootCrumb 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
- * @package bootstrap.widgets
- */
-
-Yii::import('zii.widgets.CBreadcrumbs');
-
-/**
- * Bootstrap breadcrumb widget.
- */
-class BootCrumb extends CBreadcrumbs
-{
-	/**
-	 * @var array the HTML attributes for the breadcrumbs container tag.
-	 */
-	public $htmlOptions=array('class'=>'breadcrumb');
-	/**
-	 * @var string the separator between links in the breadcrumbs. Defaults to ' / '.
-	 */
-	public $separator = '/';
-
-	/**
-	 * Renders the content of the widget.
-	 */
-	public function run()
-	{
-		$links = array();
-
-		if ($this->homeLink === null || !(isset($this->homeLink['label']) && isset($this->homeLink['url'])))
-			$this->homeLink = array('label'=>Yii::t('bootstrap', 'Home'),'url'=>Yii::app()->homeUrl);
-
-		if (!empty($this->links))
-		{
-			$content = CHtml::link($this->homeLink['label'], $this->homeLink['url']);
-			$links[] = $this->renderItem($content);
-		}
-		else
-			$links[] = $this->renderItem($this->homeLink['label'], true);
-
-		foreach ($this->links as $label=>$url)
-		{
-			if (is_string($label) || is_array($url))
-			{
-				$label = $this->encodeLabel ? CHtml::encode($label) : $label;
-				$content = CHtml::link($label, $url);
-				$links[] = $this->renderItem($content);
-			}
-			else
-				$links[] = $this->renderItem($this->encodeLabel ? CHtml::encode($url) : $url, true);
-		}
-
-		echo CHtml::openTag('ul', $this->htmlOptions);
-		echo implode('', $links);
-		echo '</ul>';
-	}
-
-	/**
-	 * Renders a single breadcrumb item.
-	 * @param string $content the content.
-	 * @param boolean $active whether the item is active.
-	 * @return string the markup.
-	 */
-	protected function renderItem($content, $active=false)
-	{
-		$separator = !$active ? '<span class="divider">'.$this->separator.'</span>' : '';
-		
-		ob_start();
-		echo CHtml::openTag('li', $active ? array('class'=>'active') : array());
-		echo $content.$separator;
-		echo '</li>';
-		return ob_get_clean();
-	}
-}

widgets/BootDetailView.php

 	/**
 	 * @var string the template used to render a single attribute. Defaults to a table row.
 	 */
-	public $itemTemplate="<tr class=\"{class}\"><th style=\"width: 160px\">{label}</th><td>{value}</td></tr>\n";
+	public $itemTemplate = "<tr class=\"{class}\"><th style=\"width: 160px\">{label}</th><td>{value}</td></tr>\n";
 	/**
 	 * @var array the CSS class names for the items displaying attribute values.
 	 */

widgets/BootDropdown.php

 
 Yii::import('bootstrap.widgets.BootBaseMenu');
 
+/**
+ * Bootstrap dropdown menu widget.
+ */
 class BootDropdown extends BootBaseMenu
 {
 	/**
 					$item['itemOptions'] = array();
 
 				$class = array();
-				if (isset($item['header']))
+				if (!isset($item['url']))
 					$class[] = 'nav-header';
 
 				if ($item['active'])

widgets/BootMenu.php

  */
 class BootMenu extends BootBaseMenu
 {
-	// The different menu types.
+	// Menu types.
 	const TYPE_UNSTYLED = '';
 	const TYPE_TABS = 'tabs';
 	const TYPE_PILLS = 'pills';
 			$item['label'] .= ' <span class="caret"></span>';
 		}
 
+		if (!isset($item['url']))
+			$item['url'] = '#';
+
 		return parent::renderItem($item);
 	}
 

widgets/BootModal.php

  * @copyright Copyright &copy; Christoffer Niska 2011-
  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  * @package bootstrap.widgets
+ * @since 0.9.3
  */
 
 Yii::import('bootstrap.widgets.BootWidget');
 
 /**
  * Bootstrap modal widget.
- * @since 0.9.3
  */
 class BootModal extends BootWidget
 {

widgets/BootNavbar.php

  * @copyright Copyright &copy; Christoffer Niska 2011-
  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  * @package bootstrap.widgets
+ * @since 0.9.7
  */
 
 Yii::import('bootstrap.widgets.BootWidget');
 
 /**
  * Bootstrap navigation bar widget.
- * @since 0.9.7
  */
 class BootNavbar extends BootWidget
 {

widgets/BootProgress.php

  */
 class BootProgress extends BootWidget
 {
-	// The different progress bar types.
+	// Progress bar types.
 	const TYPE_DEFAULT = '';
 	const TYPE_INFO = 'info';
 	const TYPE_SUCCESS = 'success';

widgets/BootTabbable.php

  */
 class BootTabbable extends BootWidget
 {
-	// The valid placements.
+	// Tab placements.
 	const PLACEMENT_ABOVE = 'above';
 	const PLACEMENT_BELOW = 'below';
 	const PLACEMENT_LEFT = 'left';

widgets/BootThumbnails.php

+<?php
+/**
+ * BootThumbs 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
+ * @package bootstrap.widgets
+ */
+
+Yii::import('bootstrap.widgets.BootListView');
+
+/**
+ * Bootstrap thumbnails widget.
+ */
+class BootThumbnails extends BootListView
+{
+	/**
+	 * Renders the data items for the view.
+	 * Each item is corresponding to a single data model instance.
+	 * Child classes should override this method to provide the actual item rendering logic.
+	 */
+	public function renderItems()
+	{
+		$data = $this->dataProvider->getData();
+		
+		if (!empty($data))
+		{
+			echo CHtml::openTag('ul', array('class'=>'thumbnails'));
+			$owner = $this->getOwner();
+			$render = $owner instanceof CController ? 'renderPartial' : 'render';
+			foreach($data as $i=>$item)
+			{
+				$data = $this->viewData;
+				$data['index'] = $i;
+				$data['data'] = $item;
+				$data['widget'] = $this;
+				$owner->$render($this->itemView,$data);
+			}
+
+			echo '</ul>';
+		}
+		else
+			$this->renderEmptyText();
+	}
+}

widgets/BootThumbs.php

-<?php
-/**
- * BootThumbs 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
- * @package bootstrap.widgets
- */
-
-Yii::import('bootstrap.widgets.BootListView');
-
-/**
- * Bootstrap thumbnails widget.
- */
-class BootThumbs extends BootListView
-{
-	/**
-	 * Renders the data items for the view.
-	 * Each item is corresponding to a single data model instance.
-	 * Child classes should override this method to provide the actual item rendering logic.
-	 */
-	public function renderItems()
-	{
-		$data = $this->dataProvider->getData();
-		
-		if (!empty($data))
-		{
-			echo CHtml::openTag('ul', array('class'=>'thumbnails'));
-			$owner = $this->getOwner();
-			$render = $owner instanceof CController ? 'renderPartial' : 'render';
-			foreach($data as $i=>$item)
-			{
-				$data = $this->viewData;
-				$data['index'] = $i;
-				$data['data'] = $item;
-				$data['widget'] = $this;
-				$owner->$render($this->itemView,$data);
-			}
-
-			echo '</ul>';
-		}
-		else
-			$this->renderEmptyText();
-	}
-}