Commits

Christoffer Niska  committed 88331be

fixed BootAlert events and removed BootWidget

  • Participants
  • Parent commits ae8f1a4
  • Branches 1.0.0-wip

Comments (0)

Files changed (18)

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.11
+ * @version 0.9.12
  */
 
 /**

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

 $this->addMetaProperty('og:site_name', Yii::app()->name);
 $this->addMetaProperty('og:locale',Yii::app()->fb->locale);
 $this->addMetaProperty('fb:app_id', Yii::app()->fb->appID);
+
+Yii::app()->clientScript->registerScript('ConsolePolyfill', "
+	if (!console) {
+		console = {};
+		console.log = function() {};
+	}
+");
 ?>
 
 <section id="bootAlert">
 	Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few things up and try submitting again.');
 	?>
 
-	<?php $this->widget('bootstrap.widgets.BootAlert'); ?>
+	<?php $this->widget('bootstrap.widgets.BootAlert', array(
+		'events'=>array(
+			'close'=>"js:function() { console.log('Alert close.'); }",
+			'closed'=>"js:function() { console.log('Alert closed.'); }",
+		),
+	)); ?>
 
 	<h4>Source code</h4>
 
 			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.'),
 		)),
-		'events'=>array(
-			'show'=>\"js:function() { console.log('Tabbable show.'); }\",
-			'shown'=>\"js:function() { console.log('Tabbable shown.'); }\",
-		),
 	),
 )); ?>"); ?>
 
 
 	<h4>Source code</h4>
 
-<?php echo $phpLighter->highlight("<?php \$this->beginWidget('bootstrap.widgets.BootModal', array(
-	'id'=>'modal',
-	'events'=>array(
-		'show'=>\"js:function() { console.log('Modal show.'); }\",
-		'shown'=>\"js:function() { console.log('Modal shown.'); }\",
-		'hide'=>\"js:function() { console.log('Modal hide.'); }\",
-		'hidden'=>\"js:function() { console.log('Modal hidden.'); }\",
-	),
-)); ?>
+<?php echo $phpLighter->highlight("<?php \$this->beginWidget('bootstrap.widgets.BootModal', array('id'=>'modal')); ?>
 
 <div class=\"modal-header\">
 	<a class=\"close\" data-dismiss=\"modal\">&times;</a>
 		array('image'=>'http://placehold.it/770x400&text=Second+thumbnail', 'label'=>'Second Thumbnail label', 'caption'=>'Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.'),
 		array('image'=>'http://placehold.it/770x400&text=Third+thumbnail', 'label'=>'Third Thumbnail label', 'caption'=>'Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.'),
 	),
-	'events'=>array(
-		'slide'=>\"js:function() { console.log('Carousel slide.'); }\",
-		'slid'=>\"js:function() { console.log('Carousel slid.'); }\",
-	),
 )); ?>"); ?>
 
 		<a class="top" href="#top">Back to top &uarr;</a>
 			array('label'=>'Carousel', 'url'=>'#bootCarousel'),
 			array('label'=>'Progress', 'url'=>'#bootProgress'),
 			array('label'=>'Typeahead', 'url'=>'#bootTypeahead'),
-			array('label'=>'Labels <span class="label label-inverse">New</span>', 'encodeLabel'=>false, 'url'=>'#bootLabel'),
-			array('label'=>'Badges <span class="label label-inverse">New</span>', 'encodeLabel'=>false, 'url'=>'#bootBadge'),
+			array('label'=>'Labels', 'url'=>'#bootLabel'),
+			array('label'=>'Badges', 'url'=>'#bootBadge'),
 		),
 	)); ?>
 

File widgets/BootAlert.php

  * @package bootstrap.widgets
  */
 
-Yii::import('bootstrap.widgets.BootWidget');
-
 /**
  * Bootstrap alert widget.
- * @todo Fix event support. http://twitter.github.com/bootstrap/javascript.html#alerts
  */
-class BootAlert extends BootWidget
+class BootAlert extends CWidget
 {
 	/**
 	 * @var array the keys for which to get flash messages.
 	 */
 	public $template = '<div class="alert alert-block alert-{key}{class}"><a class="close" data-dismiss="alert">&times;</a>{message}</div>';
 	/**
-	 * @var array the html options.
+	 * @var string[] the JavaScript event handlers.
+	 */
+	public $events = array();
+	/**
+	 * @var array the HTML attributes for the widget container.
 	 */
 	public $htmlOptions = array();
 
 	{
 		parent::init();
 
-		Yii::app()->bootstrap->registerAlert();
-
 		if (!isset($this->htmlOptions['id']))
 			$this->htmlOptions['id'] = $this->getId();
+
+		Yii::app()->bootstrap->registerAlert();
 	}
 
 	/**
 		echo '</div>';
 
 		$selector = "#{$this->id} .alert";
-		Yii::app()->clientScript->registerScript(__CLASS__.'#'.$this->id, "jQuery('{$selector}').alert();");
+		Yii::app()->clientScript->registerScript(__CLASS__."#{$this->id}", "jQuery('{$selector}').alert();");
 
-		/*
 		// Register the "close" event-handler.
 		if (isset($this->events['close']))
 		{
 			$fn = CJavaScript::encode($this->events['close']);
-			Yii::app()->clientScript->registerScript(__CLASS__.'#'.$this->id.'.close', "jQuery('{$selector}').bind('close', {$fn});");
+			Yii::app()->clientScript->registerScript(__CLASS__."#{$this->id}.close",
+					"jQuery('{$selector}').bind('close', {$fn});");
 		}
 
 		// Register the "closed" event-handler.
 		if (isset($this->events['closed']))
 		{
 			$fn = CJavaScript::encode($this->events['closed']);
-			Yii::app()->clientScript->registerScript(__CLASS__.'#'.$this->id.'.closed', "jQuery('{$selector}').bind('closed', {$fn});");
+			Yii::app()->clientScript->registerScript(__CLASS__."#{$this->id}.closed",
+					"jQuery('{$selector}').bind('closed', {$fn});");
 		}
-		*/
 	}
 }

File widgets/BootBadge.php

  * @package bootstrap.widgets
  */
 
-Yii::import('bootstrap.widgets.BootWidget');
-
 /**
  * Bootstrap badge widget.
  */
-class BootBadge extends BootWidget
+class BootBadge extends CWidget
 {
 	// Badge types.
 	const TYPE_DEFAULT = '';
 	 * @var boolean whether to encode the label.
 	 */
 	public $encodeLabel = true;
+	/**
+	 * @var array the HTML attributes for the widget container.
+	 */
+	public $htmlOptions = array();
 
 	/**
 	 * Initializes the widget.

File widgets/BootBaseMenu.php

  * @package bootstrap.widgets
  */
 
-Yii::import('bootstrap.widgets.BootWidget');
-
-abstract class BootBaseMenu extends BootWidget
+abstract class BootBaseMenu extends CWidget
 {
 	/**
 	 * @var array the menu items.
 	 * @var boolean whether to encode item labels.
 	 */
 	public $encodeLabel = true;
+	/**
+	 * @var array the HTML attributes for the widget container.
+	 */
+	public $htmlOptions = array();
 
 	/**
 	 * Runs the widget.
 		if (!isset($item['header']) && !isset($item['url']))
 			$item['url'] = '#';
 
-		if (isset($item['url']))
-			return CHtml::link($item['label'], $item['url'], $item['linkOptions']);
-		else
-			return $item['label'];
+		return isset($item['url']) ? CHtml::link($item['label'], $item['url'], $item['linkOptions']) : $item['label'];
 	}
 
 	/**

File widgets/BootButton.php

  * @since 0.9.10
  */
 
-Yii::import('bootstrap.widgets.BootWidget');
-
 /**
  * Bootstrap button widget.
  */
-class BootButton extends BootWidget
+class BootButton extends CWidget
 {
 	// Button callback types.
 	const BUTTON_LINK = 'link';
 	 */
 	public $encodeLabel = true;
 	/**
+	 * @var array the HTML attributes for the widget container.
+	 */
+	public $htmlOptions = array();
+	/**
 	 * @var array the button ajax options (used by 'ajaxLink' and 'ajaxButton').
 	 */
 	public $ajaxOptions = array();

File widgets/BootButtonGroup.php

  */
 
 Yii::import('bootstrap.widgets.BootButton');
-Yii::import('bootstrap.widgets.BootWidget');
 
 /**
  * Bootstrap button group widget.
  */
-class BootButtonGroup extends BootWidget
+class BootButtonGroup extends CWidget
 {
 	// Toggle options.
 	const TOGGLE_CHECKBOX = 'checkbox';
 	 */
 	public $encodeLabel = true;
 	/**
+	 * @var array the HTML attributes for the widget container.
+	 */
+	public $htmlOptions = array();
+	/**
 	 * @var array the button configuration.
 	 */
 	public $buttons = array();

File widgets/BootCarousel.php

  * @since 0.9.10
  */
 
-Yii::import('bootstrap.widgets.BootWidget');
-
 /**
  * Bootstrap carousel widget.
  */
-class BootCarousel extends BootWidget
+class BootCarousel extends CWidget
 {
 	/**
 	 * @var string the previous button content.
 	 * @var array the carousel items configuration.
 	 */
 	public $items = array();
+	/**
+	 * @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.

File widgets/BootDropdown.php

 	{
 		foreach ($items as $i => $item)
 		{
+			if (!is_array($item))
+				continue;
+
 			if (isset($item['visible']) && !$item['visible'])
 			{
 				unset($items[$i]);

File widgets/BootHero.php

  * @since 0.9.10
  */
 
-Yii::import('bootstrap.widgets.BootWidget');
-
 /**
  * Modest bootstrap hero widget.
  * Thanks to Christphe Boulain for suggesting content capturing.
  */
-class BootHero extends BootWidget
+class BootHero extends CWidget
 {
 	/**
 	 * @var string the heading text.
 	 * @var boolean indicates whether to encode the heading.
 	 */
 	public $encodeHeading = true;
+	/**
+	 * @var array the HTML attributes for the widget container.
+	 */
+	public $htmlOptions = array();
 
 	/**
 	 * Initializes the widget.

File widgets/BootLabel.php

  * @package bootstrap.widgets
  */
 
-Yii::import('bootstrap.widgets.BootWidget');
-
 /**
  * Bootstrap label widget.
  */
-class BootLabel extends BootWidget
+class BootLabel extends CWidget
 {
 	// Label types.
 	const TYPE_DEFAULT = '';
 	 * @var boolean whether to encode the label.
 	 */
 	public $encodeLabel = true;
+	/**
+	 * @var array the HTML attributes for the widget container.
+	 */
+	public $htmlOptions = array();
 
 	/**
 	 * Initializes the widget.

File widgets/BootMenu.php

 	{
 		foreach ($items as $i => $item)
 		{
+			if (!is_array($item))
+				continue;
+
 			if (isset($item['visible']) && !$item['visible'])
 			{
 				unset($items[$i]);

File widgets/BootModal.php

 /**
  * Bootstrap modal widget.
  */
-class BootModal extends BootWidget
+class BootModal extends CWidget
 {
 	/**
+	 * @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()
 		else
 			$this->htmlOptions['class'] = $cssClass;
 
-
-
 		echo CHtml::openTag('div', $this->htmlOptions).PHP_EOL;
 	}
 

File widgets/BootNavbar.php

 /**
  * Bootstrap navigation bar widget.
  */
-class BootNavbar extends BootWidget
+class BootNavbar extends CWidget
 {
 	// Navbar fix locations.
 	const FIXED_TOP = 'top';
 	 * @var boolean whether to enable collapsing on narrow screens. Default to false.
 	 */
 	public $collapse = false;
+	/**
+	 * @var array the HTML attributes for the widget container.
+	 */
+	public $htmlOptions = array();
 
 	/**
 	 * Initializes the widget.

File widgets/BootProgress.php

  * @since 0.9.10
  */
 
-Yii::import('bootstrap.widgets.BootWidget');
-
 /**
  * Bootstrap progress bar widget.
  */
-class BootProgress extends BootWidget
+class BootProgress extends CWidget
 {
 	// Progress bar types.
 	const TYPE_DEFAULT = '';
 	 * @var integer the progress.
 	 */
 	public $percent = 0;
+	/**
+	 * @var array the HTML attributes for the widget container.
+	 */
+	public $htmlOptions = array();
 
 	/**
 	 * Initializes the widget.

File widgets/BootTabbable.php

  */
 
 Yii::import('bootstrap.widgets.BootMenu');
-Yii::import('bootstrap.widgets.BootWidget');
 
 /**
  * Bootstrap JavaScript tabs widget.
  * @since 0.9.8
- * @todo Fix event support. http://twitter.github.com/bootstrap/javascript.html#tabs
  */
-class BootTabbable extends BootWidget
+class BootTabbable extends CWidget
 {
 	// Tab placements.
 	const PLACEMENT_ABOVE = 'above';
 	 * @var boolean whether to encode item labels.
 	 */
 	public $encodeLabel = true;
+	/**
+	 * @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 run()
     {
-	    $id = $this->id;
 	    $content = array();
 	    $items = $this->normalizeTabs($this->tabs, $content);
 
 
 	    /** @var CClientScript $cs */
 	    $cs = Yii::app()->getClientScript();
-	    $cs->registerScript(__CLASS__.'#'.$id, "jQuery('#{$id}').tab('show');");
+	    $cs->registerScript(__CLASS__.'#'.$this->id, "jQuery('#{$this->id}').tab('show');");
 
         // Register the "show" event-handler.
         if (isset($this->events['show']))
         {
             $fn = CJavaScript::encode($this->events['show']);
-	        $cs->registerScript(__CLASS__.'#'.$id.'.show',
-	                "jQuery('#{$id} a[data-toggle=\"tab\"]').on('show', {$fn});");
+	        $cs->registerScript(__CLASS__.'#'.$this->id.'.show',
+	                "jQuery('#{$this->id} a[data-toggle=\"tab\"]').on('show', {$fn});");
         }
 
         // Register the "shown" event-handler.
         if (isset($this->events['shown']))
         {
             $fn = CJavaScript::encode($this->events['shown']);
-	        $cs->registerScript(__CLASS__.'#'.$id.'.shown',
-	                "jQuery('#{$id} a[data-toggle=\"tab\"]').on('shown', {$fn});");
+	        $cs->registerScript(__CLASS__.'#'.$this->id.'.shown',
+	                "jQuery('#{$this->id} a[data-toggle=\"tab\"]').on('shown', {$fn});");
         }
     }
 

File widgets/BootTypeahead.php

 /**
  * Bootstrap type-a-head widget.
  */
-class BootTypeahead extends BootWidget
+class BootTypeahead extends CWidget
 {
 	/**
+	 * @var array the options for the Bootstrap JavaScript plugin.
+	 */
+	public $options = array();
+	/**
+	 * @var array the HTML attributes for the widget container.
+	 */
+	public $htmlOptions = array();
+
+	/**
 	 * Initializes the widget.
 	 */
 	public function init()

File widgets/BootWidget.php

-<?php
-/**
- * BootWidget 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
- */
-
-/**
- * Bootstrap base widget.
- */
-class BootWidget extends CWidget
-{
-	/**
-	 * @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();
-}