yii2-medium-editor

Medium Editor for Yii2 (https://github.com/yabwe/medium-editor)

  • 所有者: Borales/yii2-medium-editor
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Medium Editor for Yii2

Latest Version
Software License
Total Downloads

Renders Medium.com WYSIWYG editor (yabwe/medium-editor) widget.

Installation

The preferred way to install this extension is through composer.

Either run

$ php composer.phar require "borales/yii2-medium-editor" "*"

or add

"borales/yii2-medium-editor": "*"

to the require section of your composer.json file.

Assets

By default - this extension doesn't provide any source files for Medium Editor itself.
It uses public CDN instead (jsdelivr.com). And by default - it
uses the latest version of the Medium Editor plugin.

However, you can change these settings by checking the following configuration of your application (config/main.php):

return [
    // ... other settings
    'components' => [
        // ... other settings
        'assetManager' => [
            'bundles' => [
                'borales\medium\Asset' => [
                    // set `bootstrap` theme for Medium Editor widget as a default one
                    'theme' => 'bootstrap',
                    // switch Medium Editor sources from the "latest" to the specific version
                    'useLatest' => false,
                    // use specific version of Medium Editor plugin with "useLatest=false"
                    'cdnVersion' => '5.22.1',
                ],
            ]
        ],
    ]
]

The default specified version for Medium Editor plugin is 5.22.1.

In case if you want to use Medium Editor plugin from local sources - you can do that
by adding bower-asset/medium-editor package to your composer.json file and adding this line
to your local configuration:

return [
    // ... other settings
    'components' => [
        // ... other settings
        'assetManager' => [
            'bundles' => [
                'borales\medium\Asset' => [
                    // use Medium Editor plugin sources from this path
                    'sourcePath' => '@bower/medium-editor/dist',
                ],
            ]
        ],
    ]
]

Usage

as a standalone widget for a Model

echo \borales\medium\Widget::widget([
    'model' => $model,
    'attribute' => 'text',
]);

as a standalone widget for a custom variable

echo \borales\medium\Widget::widget([
    'name' => 'my_custom_var',
    'value' => '<p>Some custom text!</p>',
]);

as a widget with extra Medium Editor settings

echo \borales\medium\Widget::widget([
    'model' => $model,
    'attribute' => 'text',
    'theme' => 'tim', // Set a theme for this specific widget
    'settings' => [
        'toolbar' => [
            'buttons' => ['bold', 'italic', 'quote'],
        ]
    ],
]);

Here you can check the full list of Medium Editor options.

as an ActiveForm widget

echo $form->field($model, 'text')->widget(\borales\medium\Widget::className());

as an ActiveForm widget with settings

echo $form->field($model, 'text')->widget(\borales\medium\Widget::className(), [
    'theme' => 'mani',
    'settings' => [
        'toolbar' => [
            'buttons' => ['bold', 'italic', 'quote'],
        ]
    ],
]);

as an ActiveField method (via MediumEditorTrait)

In case if you use your custom ActiveField class - you can use MediumEditorTrait in your class:

namespace app\components;

class ActiveField extends \yii\widgets\ActiveField
{
    use \borales\medium\MediumEditorTrait;
}

And after that - call mediumEditor() method to render Medium Editor widget like this
(and you can also pass Medium Editor settings as in above examples):

echo $form->field($model, 'text')->mediumEditor()

External plugins

If you want to use external plugin, which does not refer to the toolbar button (such as
medium-editor-insert-plugin),
you need to use plugins property of the Widget and pass your code like this:

echo $form->field($model, 'text')->widget(\borales\medium\Widget::className(), [
    'plugins' => [
        'mediumInsert' => '$(selector).mediumInsert({editor: editor});',
    ],
]);

selector and editor variables will be passed to the callback inside of the Widget's
render method.

License

MIT License. Please see License File for more information.

主要指標

概覽
名稱與所有者Borales/yii2-medium-editor
主編程語言PHP
編程語言PHP (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2016-11-01 09:20:14
推送於2016-11-06 16:11:16
最后一次提交2016-11-06 17:10:57
發布數2
最新版本名稱0.0.2 (發布於 )
第一版名稱0.0.1 (發布於 )
用户参与
星數4
關注者數3
派生數1
提交數12
已啟用問題?
問題數0
打開的問題數0
拉請求數0
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?