Skip to content

Commit

Permalink
Merge branch 'master' of github.com:froala/yii2-froala-editor
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanneculai committed May 4, 2017
2 parents 0088fa8 + df9c533 commit b30d6e5
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 166 deletions.
166 changes: 0 additions & 166 deletions FroalaEditorWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

}
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?= \froala\froalaeditor\FroalaEditorWidget::widget([
'name' => '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
Expand Down

0 comments on commit b30d6e5

Please sign in to comment.