-
Notifications
You must be signed in to change notification settings - Fork 0
/
UEditor.php
59 lines (53 loc) · 1.62 KB
/
UEditor.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace moxuandi\ueditor;
use Yii;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\helpers\Url;
use yii\widgets\InputWidget;
/**
* UEditor renders a editor js plugin for classic editing.
*
* @author zhangmoxuan <[email protected]>
* @link http://www.zhangmoxuan.com
* @QQ 1104984259
* @Date 2019-2-6
* @see http://ueditor.baidu.com/website/
*/
class UEditor extends InputWidget
{
/**
* @var array 配置接口, 参阅[UEditor 官方文档](http://fex.baidu.com/ueditor/#start-config)
* @see assets/ueditor.config.js
*/
public $editorOptions = [];
public function init()
{
parent::init();
$this->hasModel() ? $this->id = $this->options['id'] : $this->id = $this->options['id'] = $this->id . '_' . $this->name;
$this->editorOptions = array_merge([
'serverUrl' => Url::to(['UeUpload']),
'initialFrameWidth' => '100%',
'initialFrameHeight' => 320,
'lang' => strtolower(Yii::$app->language) == 'en-us' ? 'en' : 'zh-cn'
], $this->editorOptions);
}
/**
* 渲染输入域
* @return string
*/
public function run()
{
$this->registerScript();
return $this->hasModel() ? Html::activeTextarea($this->model, $this->attribute, $this->options) : Html::textarea($this->name, $this->value, $this->options);
}
/**
* 注册客户端脚本
*/
public function registerScript()
{
UEditorAsset::register($this->view);
$editorOptions = Json::encode($this->editorOptions);
$this->view->registerJs("UE.getEditor('{$this->id}', $editorOptions);");
}
}