diff --git a/FroalaEditorWidget.php b/FroalaEditorWidget.php index 21cba70..d16eecc 100644 --- a/FroalaEditorWidget.php +++ b/FroalaEditorWidget.php @@ -79,7 +79,6 @@ public function run() public function registerClientScript() { $view = $this->getView(); - $this->initClientOptions(); $asset = FroalaEditorAsset::register($view); $asset->registerClientPlugins($this->clientPlugins, $this->excludedPlugins); @@ -111,169 +110,4 @@ public function registerClientScript() $view->registerJs("\$('#$id').froalaEditor($jsOptions);"); } - - /** - * client options init - */ - protected function initClientOptions() - { - // KindEditor optional parameters - $params = [ - 'charCounterCount', - 'charCounterMax', - 'codeBeautifier', - 'codeMirror', - 'codeMirrorOptions', - 'colorsBackground', - 'colorsDefaultTab', - 'colorsStep', - 'colorsText', - 'direction', - 'disableRightClick', - 'editInPopup', - 'editorClass', - 'emoticonsSet', - 'emoticonsStep', - 'enter', - 'entities', - 'fileAllowedTypes', - 'fileMaxSize', - 'fileUploadMethod', - 'fileUploadParam', - 'fileUploadParams', - 'fileUploadToS3', - 'fileUploadURL', - 'fileUseSelectedText', - 'fontFamily', - 'fontFamilySelection', - 'fontSize', - 'fontSizeSelection', - 'fullPage', - 'height', - 'heightMax', - 'heightMin', - 'htmlAllowComments', - 'htmlAllowedAttrs', - 'htmlAllowedEmptyTags', - 'htmlAllowedTags', - 'htmlRemoveTags', - 'htmlSimpleAmpersand', - 'iframe', - 'iframeStyle', - 'iframeStyleFiles', - 'imageAllowedTypes', - 'imageAltButtons', - 'imageDefaultAlign', - 'imageDefaultDisplay', - 'imageDefaultWidth', - 'imageEditButtons', - 'imageInsertButtons', - 'imageManagerDeleteMethod', - 'imageManagerDeleteParams', - 'imageManagerDeleteURL', - 'imageManagerLoadMethod', - 'imageManagerLoadParams', - 'imageManagerLoadURL', - 'imageManagerPageSize', - 'imageManagerPreloader', - 'imageManagerScrollOffset', - 'imageMaxSize', - 'imageMove', - 'imageMultipleStyles', - 'imagePaste', - 'imageResize', - 'imageResizeWithPercent', - 'imageSizeButtons', - 'imageStyles', - 'imageTextNear', - 'imageUploadMethod', - 'imageUploadParam', - 'imageUploadParams', - 'imageUploadToS3', - 'imageUploadURL', - 'initOnClick', - 'inlineStyles', - 'keepFormatOnDelete', - 'language', - 'lineBreakerOffset', - 'lineBreakerTags', - 'linkAlwaysBlank', - 'linkAlwaysNoFollow', - 'linkAttributes', - 'linkAutoPrefix', - 'linkConvertEmailAddress', - 'linkEditButtons', - 'linkInsertButtons', - 'linkList', - 'linkMultipleStyles', - 'linkStyles', - 'linkText', - 'multiLine', - 'paragraphFormat', - 'paragraphFormatSelection', - 'paragraphMultipleStyles', - 'paragraphStyles', - 'pasteAllowLocalImages', - 'pasteDeniedAttrs', - 'pasteDeniedTags', - 'pastePlain', - 'placeholderText', - 'requestHeaders', - 'requestWithCORS', - 'saveInterval', - 'saveMethod', - 'saveParam', - 'saveParams', - 'saveURL', - 'scrollableContainer', - 'shortcutsEnabled', - 'spellcheck', - 'tabSpaces', - 'tableCellMultipleStyles', - 'tableCellStyles', - 'tableColors', - 'tableColorsButtons', - 'tableColorsStep', - 'tableEditButtons', - 'tableInsertButtons', - 'tableInsertMaxSize', - 'tableMultipleStyles', - 'tableResizerOffset', - 'tableResizingLimit', - 'tableStyles', - 'theme', - 'toolbarBottom', - 'toolbarButtons', - 'toolbarButtonsMD', - 'toolbarButtonsSM', - 'toolbarButtonsXS', - 'toolbarInline', - 'toolbarSticky', - 'toolbarStickyOffset', - 'toolbarVisibleWithoutSelection', - 'typingTimer', - 'useClasses', - 'videoDefaultAlign', - 'videoDefaultDisplay', - 'videoEditButtons', - 'videoInsertButtons', - 'videoResize', - 'videoSizeButtons', - 'videoTextNear', - 'width', - 'zIndex', - 'key' - ]; - $options = []; - $options['height'] = '80px'; - $options['theme'] = 'dark'; - $options['language'] = 'en_gb'; - foreach ($params as $key) { - if (isset($this->clientOptions[$key])) { - $options[$key] = $this->clientOptions[$key]; - } - } - $this->clientOptions = $options; - } - } diff --git a/README.md b/README.md index d7101ce..0b1ac21 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,83 @@ or use with a model: ]);; ?> ``` +## Upload example + +Using the basic Yii template make a new folder under /web/ called uploads. + +For controler: + +```php +public function actionUpload() { + $base_path = Yii::getAlias('@app'); + $web_path = Yii::getAlias('@web'); + $model = new UploadForm(); + + if (Yii::$app->request->isPost) { + $model->file = UploadedFile::getInstanceByName('file'); + + if ($model->validate()) { + $model->file->saveAs($base_path . '/web/uploads/' . $model->file->baseName . '.' . $model->file->extension); + } + } + + // Get file link + $res = array ( + 'link' => $web_path . '/uploads/' . $model->file->baseName . '.' . $model->file->extension, + ); + + // Response data + return json_encode($res); +} +``` + +For model: + +```php +namespace app\models; +use yii\base\Model; +use yii\web\UploadedFile; + +/** + * UploadForm is the model behind the upload form. + */ +class UploadForm extends Model +{ + /** + * @var UploadedFile|Null file attribute + */ + public $file; + + /** + * @return array the validation rules. + */ + public function rules() + { + return [ + [['file'], 'file'] + ]; + } +} +``` + +For the view: + +```php + 'body', + 'clientOptions' => [ + 'toolbarInline'=> false, + 'height' => 200, + 'theme' =>'royal',//optional: dark, red, gray, royal + 'language'=>'en_gb' , + 'toolbarButtons' => ['fullscreen', 'bold', 'italic', 'underline', '|', 'paragraphFormat', 'insertImage'], + 'imageUploadParam'=> 'file', + 'imageUploadURL'=> \yii\helpers\Url::to(['site/upload/']) + ], + 'clientPlugins'=> ['fullscreen', 'paragraph_format', 'image'] +]); ?> +``` + For full details on usage, see the [documentation](https://froala.com/wysiwyg-editor/docs). ## License