示例#1
0
 public function run()
 {
     Assets::register($this->getView());
     echo Html::beginTag('div', $this->containerOptions);
     if ($this->hasModel()) {
         echo Html::activeTextarea($this->model, $this->attribute, $this->options);
     } else {
         echo Html::textarea($this->name, $this->value, $this->options);
     }
     echo Html::endTag('div');
     $js = ['mihaildev.ckEditor.registerOnChange(' . Json::encode($this->options['id']) . ');'];
     if (isset($this->editorOptions['filebrowserUploadUrl'])) {
         $js[] = "mihaildev.ckEditor.registerCsrf();";
     }
     if (!isset($this->editorOptions['on']['instanceReady'])) {
         $this->editorOptions['on']['instanceReady'] = new JsExpression("function( ev ){" . implode(' ', $js) . "}");
     }
     if ($this->_inline) {
         $JavaScript = "CKEDITOR.inline(";
         $JavaScript .= Json::encode($this->options['id']);
         $JavaScript .= empty($this->editorOptions) ? '' : ', ' . Json::encode($this->editorOptions);
         $JavaScript .= ");";
         $JavaScript .= "\$('#" . $this->options['id'] . "').on('change', function() {\n                function periodicData(data) {\n                    \$.ajax({\n                        type: 'POST',\n                        url: '" . $this->dataUrlEdit . "',\n                        dataType: 'json',\n                        data: {data: data,'attr':'" . $this->name . "'},\n                        beforeSend: function (data) {},\n                        success: function (data) {console.log(data)},\n                        error: function (xhr, ajaxOptions, thrownError) {\n                            alert(xhr.status);\n                            alert(thrownError);\n                        },\n                        complete: function (data) {}\n                    });\n                }\n                periodicData(\$(this).val());\n            });";
         $this->getView()->registerJs($JavaScript, View::POS_END);
         $this->getView()->registerCss('#' . $this->containerOptions['id'] . ', #' . $this->containerOptions['id'] . ' .cke_textarea_inline{height: ' . $this->editorOptions['height'] . 'px;}');
     } else {
         $JavaScript = "CKEDITOR.replace(";
         $JavaScript .= Json::encode($this->options['id']);
         $JavaScript .= empty($this->editorOptions) ? '' : ', ' . Json::encode($this->editorOptions);
         $JavaScript .= ");";
         $this->getView()->registerJs($JavaScript, View::POS_END);
     }
 }
示例#2
0
 public function run()
 {
     Assets::register($this->getView());
     echo Html::beginTag('div', $this->containerOptions);
     if ($this->hasModel()) {
         echo Html::activeTextarea($this->model, $this->attribute, $this->options);
     } else {
         echo Html::textarea($this->name, $this->value, $this->options);
     }
     echo Html::endTag('div');
     $js = ['mihaildev.ckEditor.registerOnChange(' . Json::encode($this->options['id']) . ');'];
     if (isset($this->editorOptions['filebrowserUploadUrl'])) {
         $js[] = "mihaildev.ckEditor.registerCsrf();";
     }
     if (!isset($this->editorOptions['on']['instanceReady'])) {
         $this->editorOptions['on']['instanceReady'] = new JsExpression("function( ev ){" . implode(' ', $js) . "}");
     }
     if ($this->_inline) {
         $JavaScript = "CKEDITOR.inline(";
         $JavaScript .= Json::encode($this->options['id']);
         $JavaScript .= empty($this->editorOptions) ? '' : ', ' . Json::encode($this->editorOptions);
         $JavaScript .= ");";
         $this->getView()->registerCss('#' . $this->containerOptions['id'] . ', #' . $this->containerOptions['id'] . ' .cke_textarea_inline{height: ' . $this->editorOptions['height'] . 'px;}');
     } else {
         $JavaScript = "CKEDITOR.replace(";
         $JavaScript .= Json::encode($this->options['id']);
         $JavaScript .= empty($this->editorOptions) ? '' : ', ' . Json::encode($this->editorOptions);
         $JavaScript .= ");";
     }
     if ($this->initOnEvent) {
         $JavaScript = 'jQuery("#' . $this->options['id'] . '").one("' . $this->initOnEvent . '", function(){' . $JavaScript . '});';
         JqueryAsset::register($this->getView());
     }
     $this->getView()->registerJs($JavaScript, View::POS_END);
 }