You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					82 lines
				
				2.2 KiB
			
		
		
			
		
	
	
					82 lines
				
				2.2 KiB
			| 
											13 years ago
										 | <?php
 | ||
|  | /**
 | ||
|  |  * @link http://www.yiiframework.com/
 | ||
|  |  * @copyright Copyright (c) 2008 Yii Software LLC
 | ||
|  |  * @license http://www.yiiframework.com/license/
 | ||
|  |  */
 | ||
|  | 
 | ||
| 
											13 years ago
										 | namespace yii\bootstrap;
 | ||
| 
											13 years ago
										 | 
 | ||
|  | use Yii;
 | ||
| 
											13 years ago
										 | use yii\helpers\Json;
 | ||
| 
											13 years ago
										 | 
 | ||
| 
											13 years ago
										 | /**
 | ||
| 
											13 years ago
										 |  * \yii\bootstrap\Widget is the base class for all bootstrap widgets.
 | ||
| 
											13 years ago
										 |  *
 | ||
|  |  * @author Antonio Ramirez <amigo.cobos@gmail.com>
 | ||
| 
											13 years ago
										 |  * @author Qiang Xue <qiang.xue@gmail.com>
 | ||
| 
											13 years ago
										 |  * @since 2.0
 | ||
|  |  */
 | ||
| 
											13 years ago
										 | class Widget extends \yii\base\Widget
 | ||
| 
											13 years ago
										 | {
 | ||
|  | 	/**
 | ||
|  | 	 * @var array the HTML attributes for the widget container tag.
 | ||
|  | 	 */
 | ||
| 
											12 years ago
										 | 	public $options = [];
 | ||
| 
											13 years ago
										 | 	/**
 | ||
| 
											13 years ago
										 | 	 * @var array the options for the underlying Bootstrap JS plugin.
 | ||
|  | 	 * Please refer to the corresponding Bootstrap plugin Web page for possible options.
 | ||
|  | 	 * For example, [this page](http://twitter.github.io/bootstrap/javascript.html#modals) shows
 | ||
|  | 	 * how to use the "Modal" plugin and the supported options (e.g. "remote").
 | ||
| 
											13 years ago
										 | 	 */
 | ||
| 
											12 years ago
										 | 	public $clientOptions = [];
 | ||
| 
											13 years ago
										 | 	/**
 | ||
| 
											13 years ago
										 | 	 * @var array the event handlers for the underlying Bootstrap JS plugin.
 | ||
|  | 	 * Please refer to the corresponding Bootstrap plugin Web page for possible events.
 | ||
|  | 	 * For example, [this page](http://twitter.github.io/bootstrap/javascript.html#modals) shows
 | ||
|  | 	 * how to use the "Modal" plugin and the supported events (e.g. "shown").
 | ||
| 
											13 years ago
										 | 	 */
 | ||
| 
											12 years ago
										 | 	public $clientEvents = [];
 | ||
| 
											13 years ago
										 | 
 | ||
| 
											13 years ago
										 | 
 | ||
|  | 	/**
 | ||
| 
											13 years ago
										 | 	 * Initializes the widget.
 | ||
|  | 	 * This method will register the bootstrap asset bundle. If you override this method,
 | ||
|  | 	 * make sure you call the parent implementation first.
 | ||
| 
											13 years ago
										 | 	 */
 | ||
| 
											13 years ago
										 | 	public function init()
 | ||
| 
											13 years ago
										 | 	{
 | ||
| 
											13 years ago
										 | 		parent::init();
 | ||
| 
											13 years ago
										 | 		if (!isset($this->options['id'])) {
 | ||
|  | 			$this->options['id'] = $this->getId();
 | ||
| 
											13 years ago
										 | 		}
 | ||
| 
											13 years ago
										 | 	}
 | ||
|  | 
 | ||
|  | 	/**
 | ||
| 
											13 years ago
										 | 	 * Registers a specific Bootstrap plugin and the related events
 | ||
|  | 	 * @param string $name the name of the Bootstrap plugin
 | ||
| 
											13 years ago
										 | 	 */
 | ||
| 
											13 years ago
										 | 	protected function registerPlugin($name)
 | ||
| 
											13 years ago
										 | 	{
 | ||
| 
											13 years ago
										 | 		$view = $this->getView();
 | ||
| 
											12 years ago
										 | 
 | ||
|  | 		BootstrapPluginAsset::register($view);
 | ||
|  | 
 | ||
|  | 		$id = $this->options['id'];
 | ||
| 
											13 years ago
										 | 
 | ||
| 
											13 years ago
										 | 		if ($this->clientOptions !== false) {
 | ||
|  | 			$options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions);
 | ||
| 
											13 years ago
										 | 			$js = "jQuery('#$id').$name($options);";
 | ||
|  | 			$view->registerJs($js);
 | ||
|  | 		}
 | ||
|  | 
 | ||
| 
											13 years ago
										 | 		if (!empty($this->clientEvents)) {
 | ||
| 
											12 years ago
										 | 			$js = [];
 | ||
| 
											13 years ago
										 | 			foreach ($this->clientEvents as $event => $handler) {
 | ||
| 
											13 years ago
										 | 				$js[] = "jQuery('#$id').on('$event', $handler);";
 | ||
|  | 			}
 | ||
|  | 			$view->registerJs(implode("\n", $js));
 | ||
|  | 		}
 | ||
| 
											13 years ago
										 | 	}
 | ||
| 
											13 years ago
										 | }
 |