forked from 2amigos/yii2-ckeditor-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CKEditorInline.php
96 lines (78 loc) · 2.01 KB
/
CKEditorInline.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @copyright Copyright (c) 2013 2amigOS! Consulting Group LLC
* @link http://2amigos.us
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
*/
namespace dosamigos\ckeditor;
use yii\base\Widget;
use yii\helpers\Html;
use yii\helpers\Json;
/**
* CKEditorInline renders a CKEditor js plugin for inline editing.
*
* @author Antonio Ramirez <amigo.cobos@gmail.com>
* @link http://www.ramirezcobos.com/
* @link http://www.2amigos.us/
* @package dosamigos\ckeditor
*/
class CKEditorInline extends Widget
{
use CKEditorTrait;
/**
* @var array the HTML attributes for the input tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $options = [];
/**
* @var string
*/
public $tag = 'div';
/**
* @var bool disables creating the inline editor automatically for elements with contenteditable attribute
* set to the true. Defaults to true.
*/
public $disableAutoInline = true;
/**
* @inheritdoc
*/
public function init()
{
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
$this->options['contenteditable'] = 'true';
parent::init();
$this->initOptions();
echo Html::beginTag($this->tag, $this->options);
}
/**
* @inheritdoc
*/
public function run()
{
echo Html::endTag($this->tag);
$this->registerPlugin();
}
/**
* Registers CKEditor plugin
*/
protected function registerPlugin()
{
$view = $this->getView();
CKEditorAsset::register($view);
$id = $this->options['id'];
$options = $this->clientOptions !== false && !empty($this->clientOptions)
? Json::encode($this->clientOptions)
: '{}';
$js = [];
if ($this->disableAutoInline) {
$js[] = "CKEDITOR.disableAutoInline = true;";
}
$js[] = "CKEDITOR.inline('$id', $options);";
if(isset($this->clientOptions['filebrowserUploadUrl'])) {
$js[] = "dosamigos.ckEditorWidget.registerCsrfImageUploadHandler();";
}
$view->registerJs(implode("\n", $js));
}
}