-
Notifications
You must be signed in to change notification settings - Fork 34
/
Summernote.php
41 lines (37 loc) · 1.33 KB
/
Summernote.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* @copyright Aleksandr Zelenin <[email protected]>
*/
namespace Zelenin\yii\widgets\Summernote;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\widgets\InputWidget;
class Summernote extends InputWidget
{
private $defaultOptions = ['class' => 'form-control'];
private $defaultClientOptions = ['height' => 200];
public $options = [];
public $clientOptions = [];
public function init()
{
$this->options = array_merge($this->options, $this->defaultOptions);
$this->clientOptions = array_merge($this->clientOptions, $this->defaultClientOptions);
parent::init();
}
public function run()
{
$view = $this->getView();
SummernoteAsset::register($view);
if (ArrayHelper::getValue($this->clientOptions, 'lang', null)) {
LanguageAsset::register($view)->language = $this->clientOptions['lang'];
}
echo $this->hasModel()
? Html::activeTextarea($this->model, $this->attribute, $this->options)
: Html::textarea($this->name, $this->value, $this->options);
$clientOptions = empty($this->clientOptions)
? null
: Json::encode($this->clientOptions);
$view->registerJs('jQuery( "#' . $this->options['id'] . '" ).summernote(' . $clientOptions . ');');
}
}