Class yii\jui\Draggable

Inheritanceyii\jui\Draggable » yii\jui\Widget » yii\base\Widget
Available since extension's version2.0
Source Code https://github.com/yiisoft/yii2-jui/blob/master/Draggable.php

Draggable renders an draggable jQuery UI widget.

For example:

Draggable::begin([
    'clientOptions' => ['grid' => [50, 20]],
]);

echo 'Draggable contents here...';

Draggable::end();

See also http://api.jqueryui.com/draggable/.

Public Properties

Hide inherited properties

Property Type Description Defined By
$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

Protected Properties

Hide inherited properties

Property Type Description Defined By
$clientEventMap array Event names mapped to what should be specified in .on(). yii\jui\Draggable

Public Methods

Hide inherited methods

Method Description Defined By
init() Initializes the widget. yii\jui\Draggable
run() Renders the widget. yii\jui\Draggable

Protected Methods

Hide inherited 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

Hide inherited properties

$clientEventMap protected property

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.

protected array $clientEventMap = [
    
'create' => 'dragcreate',
    
'drag' => 'drag',
    
'stop' => 'dragstop',
    
'start' => 'dragstart',
]

Method Details

Hide inherited methods

init() public method

Initializes the widget.

public mixed init ( )

                public function init()
{
    parent::init();
    echo Html::beginTag('div', $this->options) . "\n";
}

            
registerClientEvents() protected method

Defined in: yii\jui\Widget::registerClientEvents()

Registers a specific jQuery UI widget events

protected mixed registerClientEvents ( string $name, string $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));
    }
}

            
registerClientOptions() protected method

Defined in: yii\jui\Widget::registerClientOptions()

Registers a specific jQuery UI widget options

protected mixed registerClientOptions ( string $name, string $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);
    }
}

            
registerWidget() protected method

Defined in: yii\jui\Widget::registerWidget()

Registers a specific jQuery UI widget asset bundle, initializes it with client options and registers related events

protected mixed registerWidget ( string $name, string $id null )
$name string

The name of the jQuery UI widget

$id string

The ID of the widget. If null, it will use the id value of $options.

                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);
}

            
run() public method

Renders the widget.

public mixed run ( )

                public function run()
{
    echo Html::endTag('div') . "\n";
    $this->registerWidget('draggable');
}