1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2013-2019 2amigOS! Consulting Group LLC |
4
|
|
|
* @link http://2amigos.us |
5
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
6
|
|
|
*/ |
7
|
|
|
namespace dosamigos\ckeditor; |
8
|
|
|
|
9
|
|
|
use yii\base\Widget; |
10
|
|
|
use yii\helpers\Html; |
11
|
|
|
use yii\helpers\Json; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* CKEditorInline renders a CKEditor js plugin for inline editing. |
15
|
|
|
* |
16
|
|
|
* @author Antonio Ramirez <[email protected]> |
17
|
|
|
* @link http://www.ramirezcobos.com/ |
18
|
|
|
* @link http://www.2amigos.us/ |
19
|
|
|
* @package dosamigos\ckeditor |
20
|
|
|
*/ |
21
|
|
|
class CKEditorInline extends Widget |
22
|
|
|
{ |
23
|
|
|
use CKEditorTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array the HTML attributes for the input tag. |
27
|
|
|
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
28
|
|
|
*/ |
29
|
|
|
public $options = []; |
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
public $tag = 'div'; |
34
|
|
|
/** |
35
|
|
|
* @var bool disables creating the inline editor automatically for elements with contenteditable attribute |
36
|
|
|
* set to the true. Defaults to true. |
37
|
|
|
*/ |
38
|
|
|
public $disableAutoInline = true; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritdoc |
42
|
|
|
*/ |
43
|
1 |
|
public function init() |
44
|
|
|
{ |
45
|
1 |
|
if (!isset($this->options['id'])) { |
46
|
1 |
|
$this->options['id'] = $this->getId(); |
47
|
1 |
|
} |
48
|
1 |
|
$this->options['contenteditable'] = 'true'; |
49
|
|
|
|
50
|
1 |
|
parent::init(); |
51
|
|
|
|
52
|
1 |
|
$this->initOptions(); |
53
|
|
|
|
54
|
1 |
|
echo Html::beginTag($this->tag, $this->options); |
55
|
1 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @inheritdoc |
59
|
|
|
*/ |
60
|
1 |
|
public function run() |
61
|
|
|
{ |
62
|
1 |
|
echo Html::endTag($this->tag); |
63
|
|
|
|
64
|
1 |
|
$this->registerPlugin(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Registers CKEditor plugin |
69
|
|
|
* @codeCoverageIgnore |
70
|
|
|
*/ |
71
|
|
|
protected function registerPlugin() |
72
|
|
|
{ |
73
|
|
|
$js = []; |
74
|
|
|
|
75
|
|
|
$view = $this->getView(); |
76
|
|
|
|
77
|
|
|
CKEditorAsset::register($view); |
78
|
|
|
|
79
|
|
|
$id = $this->options['id']; |
80
|
|
|
|
81
|
|
|
$options = $this->clientOptions !== false && !empty($this->clientOptions) |
82
|
|
|
? Json::encode($this->clientOptions) |
83
|
|
|
: '{}'; |
84
|
|
|
|
85
|
|
|
if ($this->disableAutoInline) { |
86
|
|
|
$js[] = "CKEDITOR.disableAutoInline = true;"; |
87
|
|
|
} |
88
|
|
|
$js[] = "CKEDITOR.inline('$id', $options);"; |
89
|
|
|
|
90
|
|
|
if (isset($this->clientOptions['filebrowserUploadUrl'])) { |
91
|
|
|
$js[] = "dosamigos.ckEditorWidget.registerCsrfImageUploadHandler();"; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$view->registerJs(implode("\n", $js)); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|