Class yii\jui\Widget
Inheritance | yii\jui\Widget » yii\base\Widget |
---|---|
Subclasses | yii\jui\Accordion, yii\jui\AutoComplete, yii\jui\DatePicker, yii\jui\Dialog, yii\jui\Draggable, yii\jui\Droppable, yii\jui\InputWidget, yii\jui\ProgressBar, yii\jui\Resizable, yii\jui\Selectable, yii\jui\Slider, yii\jui\SliderInput, yii\jui\Sortable, yii\jui\Spinner, yii\jui\Tabs |
Available since extension's version | 2.0 |
Source Code | https://github.com/yiisoft/yii2-jui/blob/master/Widget.php |
\yii\jui\Widget is the base class for all jQuery UI widgets.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$clientEventMap | array | Event names mapped to what should be specified in .on() . |
yii\jui\Widget |
$clientEvents | array | The event handlers for the underlying jQuery UI widget. | yii\jui\Widget |
$clientOptions | array | The options for the underlying jQuery UI widget. | yii\jui\Widget |
$options | array | The HTML attributes for the widget container tag. | yii\jui\Widget |
Public Methods
Method | Description | Defined By |
---|---|---|
init() | Initializes the widget. | yii\jui\Widget |
Protected Methods
Method | Description | Defined By |
---|---|---|
registerClientEvents() | Registers a specific jQuery UI widget events | yii\jui\Widget |
registerClientOptions() | Registers a specific jQuery UI widget options | yii\jui\Widget |
registerWidget() | Registers a specific jQuery UI widget asset bundle, initializes it with client options and registers related events | yii\jui\Widget |
Property Details
Event names mapped to what should be specified in .on()
.
If empty, it is assumed that event passed to clientEvents is prefixed with widget name.
The event handlers for the underlying jQuery UI widget.
Please refer to the corresponding jQuery UI widget Web page for possible events.
For example, this page shows
how to use the "Accordion" widget and the supported events (e.g. "create").
Keys are the event names and values are javascript code that is passed to the .on()
function
as the event handler.
For example you could write the following in your widget configuration:
'clientEvents' => [
'change' => 'function () { alert('event "change" occured.'); }'
],
The options for the underlying jQuery UI widget. Please refer to the corresponding jQuery UI widget Web page for possible options. For example, this page shows how to use the "Accordion" widget and the supported options (e.g. "header").
Method Details
Initializes the widget.
If you override this method, make sure you call the parent implementation first.
public void init ( ) |
public function init()
{
parent::init();
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
}
Registers a specific jQuery UI widget events
protected void registerClientEvents ( $name, $id ) | ||
$name | string |
The name of the jQuery UI widget |
$id | string |
The ID of the widget |
protected function registerClientEvents($name, $id)
{
if (!empty($this->clientEvents)) {
$js = [];
foreach ($this->clientEvents as $event => $handler) {
if (isset($this->clientEventMap[$event])) {
$eventName = $this->clientEventMap[$event];
} else {
$eventName = strtolower($name . $event);
}
$js[] = "jQuery('#$id').on('$eventName', $handler);";
}
$this->getView()->registerJs(implode("\n", $js));
}
}
Registers a specific jQuery UI widget options
protected void registerClientOptions ( $name, $id ) | ||
$name | string |
The name of the jQuery UI widget |
$id | string |
The ID of the widget |
protected function registerClientOptions($name, $id)
{
if ($this->clientOptions !== false) {
$options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
$js = "jQuery('#$id').$name($options);";
$this->getView()->registerJs($js);
}
}
Registers a specific jQuery UI widget asset bundle, initializes it with client options and registers related events
protected void registerWidget ( $name, $id = null ) | ||
$name | string |
The name of the jQuery UI widget |
$id | string |
The ID of the widget. If null, it will use the |
protected function registerWidget($name, $id = null)
{
if ($id === null) {
$id = $this->options['id'];
}
JuiAsset::register($this->getView());
$this->registerClientEvents($name, $id);
$this->registerClientOptions($name, $id);
}