Commits

Christoffer Niska  committed ffdf174

added tab placement support to BootTabbable and updated the demo

  • Participants
  • Parent commits e9841b0
  • Branches bootstrap-2.0.2

Comments (0)

Files changed (9)

File components/Bootstrap.php

  * @author Christoffer Niska <ChristofferNiska@gmail.com>
  * @copyright Copyright &copy; Christoffer Niska 2011-
  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @version 0.9.10
  */
 
 /**

File demo/css/styles.css

 #bootTabbable .tabbable {
   margin-bottom: 20px;
 }
+#bootTabbable .tabbable.tabbable-placed {
+  width: 340px;
+}
 #bootThumbs .list-view {
   padding-top: 30px;
 }

File demo/less/styles.less

 
 #bootTabbable .tabbable {
 	margin-bottom: 20px;
+
+	&.tabbable-placed {
+		width: 340px;
+	}
 }
 
 #bootThumbs .list-view {

File demo/protected/config/main.php

 		'errorHandler'=>array(
 			'errorAction'=>'site/error',
 		),
+		'clientScript'=>array(
+			'class'=>'ext.minify.EClientScript',
+			//'combineScriptFiles' => true,
+			//'combineCssFiles' => true,
+			//'optimizeCssFiles' => true,
+			//'optimizeScriptFiles' => true,
+		),
 		'fb'=>array(
 			'class'=>'ext.facebook.components.FacebookConnect',
 			'appID'=>'106265262835735',

File demo/protected/controllers/SiteController.php

 	{
 		$model = new TestForm();
 
+		$tabs = array(
+			array('label'=>'Home', 'content'=>'<p>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.</p>'),
+			array('label'=>'Profile', 'content'=>'<p>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.</p>'),
+			array('label'=>'Dropdown', 'items'=>array(
+				array('label'=>'@fat', 'content'=>'<p>Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney\'s organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven\'t heard of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.</p>'),
+				array('label'=>'@mdo', 'content'=>'<p>Trust fund seitan letterpress, keytar raw denim keffiyeh etsy art party before they sold out master cleanse gluten-free squid scenester freegan cosby sweater. Fanny pack portland seitan DIY, art party locavore wolf cliche high life echo park Austin. Cred vinyl keffiyeh DIY salvia PBR, banh mi before they sold out farm-to-table VHS viral locavore cosby sweater. Lomo wolf viral, mustache readymade thundercats keffiyeh craft beer marfa ethical. Wolf salvia freegan, sartorial keffiyeh echo park vegan.</p>'),
+			)),
+		);
+
+		$tabbable = array(
+			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 3', 'content'=>'<p>What up girl, this is Section 3.</p>'),
+		);
+
 		$gridDataProvider = new CArrayDataProvider(array(
 			array('id'=>1, 'firstName'=>'Mark', 'lastName'=>'Otto', 'language'=>'CSS'),
 			array('id'=>2, 'firstName'=>'Jacob', 'lastName'=>'Thornton', 'language'=>'JavaScript'),
 
 		$this->render('index', array(
 			'model'=>$model,
+			'tabs'=>$tabs,
+			'tabbable'=>$tabbable,
 			'gridDataProvider'=>$gridDataProvider,
 			'gridColumns'=>$gridColumns,
 			'listDataProvider'=>$listDataProvider,
 	        	$this->render('error', $error);
 	    }
 	}
-}
+}

File demo/protected/views/layouts/main.php

 		'title'=>array('class'=>'ext.seo.widgets.SeoTitle', 'separator'=>' :: '),
 	)); ?>
 	<link rel="shortcut icon" href="<?php echo Yii::app()->request->baseUrl; ?>/favicon.ico">
-	<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/styles.css" />
+	<?php Yii::app()->clientScript->registerCssFile(Yii::app()->request->baseUrl.'/css/styles.css'); ?>
 	<!--[if lt IE 9]>
 		<script type="text/javascript" src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
 	<![endif]-->
-	<script type="text/javascript">
-
+	<?php Yii::app()->clientScript->registerScript('GA',"
 		var _gaq = _gaq || [];
 		_gaq.push(['_setAccount', 'UA-29040179-1']);
 		_gaq.push(['_trackPageview']);
 			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
 			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 		})();
-
-	</script>
+	"); ?>
 </head>
 
 <body id="top">

File demo/protected/views/site/index.php

 
 <section id="bootTabbable">
 
-	<h2>Tabs</h2>
+	<h2>Tabbable</h2>
 
 	<?php $this->widget('bootstrap.widgets.BootTabbable', array(
+		'type'=>'tabs', // 'tabs' or 'pills'
 		'htmlOptions'=>array('class'=>'tabbable'),
-		'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.'),
-			array('label'=>'Dropdown', 'items'=>array(
-				array('label'=>'@fat', 'content'=>'Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney\'s organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven\'t heard of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.'),
-				array('label'=>'@mdo', 'content'=>'Trust fund seitan letterpress, keytar raw denim keffiyeh etsy art party before they sold out master cleanse gluten-free squid scenester freegan cosby sweater. Fanny pack portland seitan DIY, art party locavore wolf cliche high life echo park Austin. Cred vinyl keffiyeh DIY salvia PBR, banh mi before they sold out farm-to-table VHS viral locavore cosby sweater. Lomo wolf viral, mustache readymade thundercats keffiyeh craft beer marfa ethical. Wolf salvia freegan, sartorial keffiyeh echo park vegan.'),
-			)),
-		),
-	)); ?>
-
-	<?php $this->widget('bootstrap.widgets.BootTabbable', array(
-		'type'=>'pills',
-		'htmlOptions'=>array('class'=>'tabbable'),
-		'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.'),
-			array('label'=>'Dropdown', 'items'=>array(
-				array('label'=>'@fat', 'content'=>'Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney\'s organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven\'t heard of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.'),
-				array('label'=>'@mdo', 'content'=>'Trust fund seitan letterpress, keytar raw denim keffiyeh etsy art party before they sold out master cleanse gluten-free squid scenester freegan cosby sweater. Fanny pack portland seitan DIY, art party locavore wolf cliche high life echo park Austin. Cred vinyl keffiyeh DIY salvia PBR, banh mi before they sold out farm-to-table VHS viral locavore cosby sweater. Lomo wolf viral, mustache readymade thundercats keffiyeh craft beer marfa ethical. Wolf salvia freegan, sartorial keffiyeh echo park vegan.'),
-			)),
-		),
+		'tabs'=>$tabs,
 	)); ?>
 
 	<h4>Source code</h4>
 
-<?php echo $parser->safeTransform("~~~
+	<?php echo $parser->safeTransform("~~~
 [php]
 <?php \$this->widget('bootstrap.widgets.BootTabbable', array(
 	'type'=>'pills', // 'tabs' or 'pills'
 )); ?>
 ~~~"); ?>
 
+	<div class="row">
+
+		<div class="span6">
+
+			<h3>Tabs on the top</h3>
+
+			<?php $this->widget('bootstrap.widgets.BootTabbable', array(
+				'htmlOptions'=>array('class'=>'tabbable tabbable-placed'),
+				'tabs'=>$tabbable,
+			)); ?>
+
+			<h3>Tabs on the left</h3>
+
+			<?php $this->widget('bootstrap.widgets.BootTabbable', array(
+				'placement'=>'left',
+				'htmlOptions'=>array('class'=>'tabbable tabbable-placed'),
+				'tabs'=>$tabbable,
+			)); ?>
+
+		</div>
+
+		<div class="span6">
+
+			<h3>Tabs on the bottom</h3>
+
+			<?php $this->widget('bootstrap.widgets.BootTabbable', array(
+				'placement'=>'below',
+				'htmlOptions'=>array('class'=>'tabbable tabbable-placed'),
+				'tabs'=>$tabbable,
+			)); ?>
+
+			<h3>Tabs on the right</h3>
+
+			<?php $this->widget('bootstrap.widgets.BootTabbable', array(
+				'placement'=>'right',
+				'htmlOptions'=>array('class'=>'tabbable tabbable-placed'),
+				'tabs'=>$tabbable,
+			)); ?>
+
+		</div>
+
+	</div>
+
+	<?php echo $parser->safeTransform("~~~
+[php]
+<?php \$this->widget('bootstrap.widgets.BootTabbable', array(
+	'type'=>'tabs',
+	'placement'=>'below', // 'top ', 'right', 'bottom' or 'left'
+	'tabs'=>array(
+		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 3', 'content'=>'<p>What up girl, this is Section 3.</p>'),
+	),
+)); ?>
+~~~"); ?>
+
 	<a class="top" href="#top">Back to top &uarr;</a>
 
 </section>
 			array('label'=>'Breadcrumb', 'url'=>'#bootCrumb'),
 			array('label'=>'Navbar', 'url'=>'#bootNavbar'),
 			array('label'=>'Menu', 'url'=>'#bootMenu'),
-			array('label'=>'Tabs', 'url'=>'#bootTabbable'),
+			array('label'=>'Tabbable', 'url'=>'#bootTabbable'),
 			array('label'=>'Detail view', 'url'=>'#bootDetailView'),
 			array('label'=>'Grid view', 'url'=>'#bootGridView'),
 			array('label'=>'Thumbnails', 'url'=>'#bootThumbs'),

File widgets/BootListView.php

 	 * @var array the configuration for the pager.
 	 */
 	public $pager = array('class'=>'bootstrap.widgets.BootPager');
+	/**
+	 * @var string the URL of the CSS file used by this detail view.
+	 * Defaults to false, meaning that no CSS will be included.
+	 */
+	public $cssFile = false;
 }

File widgets/BootTabbable.php

  */
 class BootTabbable extends BootWidget
 {
+	// The valid placements.
+	const PLACEMENT_ABOVE = 'above';
+	const PLACEMENT_BELOW = 'below';
+	const PLACEMENT_LEFT = 'left';
+	const PLACEMENT_RIGHT = 'right';
+
 	/**
 	 * @var string the type of tabs to display. Defaults to 'tabs'.
 	 * Valid values are 'tabs' and 'pills'.
+	 * Please not that JavaScript pills are not fully supported in Bootstrap!
 	 */
     public $type = BootMenu::TYPE_TABS;
 	/**
+	 * @var string the placement of the tabs.
+	 * Valid values are 'above', 'below', 'left' and 'right'.
+	 */
+	public $placement = self::PLACEMENT_ABOVE;
+	/**
 	 * @var array the tab configuration.
 	 */
     public $tabs = array();
     {
         parent::init();
 
-        Yii::app()->bootstrap->registerTabs();
-
 		if (!isset($this->htmlOptions['id']))
 			$this->htmlOptions['id'] = $this->getId();
+
+		if (isset($this->placement))
+		{
+			$validPlacements = array(self::PLACEMENT_ABOVE, self::PLACEMENT_BELOW, self::PLACEMENT_LEFT, self::PLACEMENT_RIGHT);
+			if (in_array($this->placement, $validPlacements))
+			{
+				$cssClass = 'tabs-'.$this->placement;
+				if (isset($this->htmlOptions['class']))
+					$this->htmlOptions['class'] .= ' '.$cssClass;
+				else
+					$this->htmlOptions['class'] = $cssClass;
+			}
+		}
+
+		Yii::app()->bootstrap->registerTabs();
     }
 
     /**
      */
     public function run()
     {
-	    $panes = array();
-	    $items = $this->normalizeTabs($this->tabs, $panes);
+	    $content = array();
+	    $items = $this->normalizeTabs($this->tabs, $content);
 
-	    echo CHtml::openTag('div', $this->htmlOptions);
-
-	    $this->controller->widget('bootstrap.widgets.BootMenu', array(
+		ob_start();
+		$this->controller->widget('bootstrap.widgets.BootMenu', array(
 			'type'=>$this->type,
 			'encodeLabel'=>$this->encodeLabel,
-		    'items'=>$items,
-	    ));
+			'items'=>$items,
+		));
+		$tabs = ob_get_clean();
 
-	    echo '<div class="tab-content">';
-		echo implode('', $panes);
-	    echo '</div></div>';
+		ob_start();
+		echo '<div class="tab-content">';
+		echo implode('', $content);
+		echo '</div>';
+		$content = ob_get_clean();
+
+		echo CHtml::openTag('div', $this->htmlOptions);
+		echo $this->placement === self::PLACEMENT_BELOW ? $content.$tabs : $tabs.$content;
+		echo '</div>';
 
 	    Yii::app()->clientScript->registerScript(__CLASS__.'#'.$this->id, "jQuery('{$this->id}').tab('show');");