-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
96 changed files
with
206 additions
and
1,918 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* Author: ljt | ||
* DateTime: 2016/12/7 9:51 | ||
* Description: | ||
*/ | ||
|
||
namespace common\widgets\editormd; | ||
|
||
use yii\helpers\Html; | ||
use yii\helpers\Json; | ||
use yii\widgets\InputWidget; | ||
|
||
class Editormd extends InputWidget | ||
{ | ||
/** | ||
* @var array the HTML attributes for the widget container tag. | ||
*/ | ||
public $options = []; | ||
/** | ||
* editor options | ||
*/ | ||
public $clientOptions = []; | ||
|
||
public $imageUploadRoute = [ | ||
'/upload/md-image-upload', | ||
'fileparam' => 'editormd-image-file' | ||
]; | ||
public function init() | ||
{ | ||
parent::init(); | ||
$this->options = array_merge([ | ||
'height' => '300', | ||
'emoji' => true, | ||
'watch' => false, | ||
'placeholder' => '本编辑器支持Markdown编辑,左边编写,右边预览', | ||
'syncScrolling' => 'single', | ||
'imageUpload' => true, | ||
'imageFormats' => ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], | ||
'imageUploadURL' => \yii\helpers\Url::to($this->imageUploadRoute) | ||
], $this->options); | ||
} | ||
|
||
public function run() | ||
{ | ||
if ($this->hasModel()) { | ||
$this->name = empty($this->options['name']) ? Html::getInputName($this->model, $this->attribute) : | ||
$this->options['name']; | ||
$this->value = Html::getAttributeValue($this->model, $this->attribute); | ||
} | ||
echo Html::tag('div', '', $this->options); | ||
$this->registerClientScript(); | ||
} | ||
|
||
protected function registerClientScript() | ||
{ | ||
$view = $this->getView(); | ||
$editormd = EditormdAsset::register($view); | ||
$id = $this->options['id']; | ||
$this->options['value'] = $this->value ? $this->value : ''; | ||
$this->options['name'] = $this->name; | ||
$this->options['path'] = $editormd->baseUrl . '/lib/'; | ||
$options = Json::encode($this->options); | ||
$js = 'var editor = editormd("' . $id . '", ' . $options . ');'; | ||
$view->registerJs($js); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* Author: ljt | ||
* DateTime: 2016/12/7 9:51 | ||
* Description: | ||
*/ | ||
|
||
namespace common\widgets\editormd; | ||
|
||
use yii\web\AssetBundle; | ||
|
||
class EditormdAsset extends AssetBundle | ||
{ | ||
public $sourcePath = '@bower/editor.md'; | ||
|
||
public $js = [ | ||
'editormd.min.js' | ||
]; | ||
|
||
public $css = [ | ||
'css/editormd.css', | ||
'css/editormd.logo.css', | ||
'css/editormd.preview.css' | ||
]; | ||
|
||
public $depends = [ | ||
'yii\web\JqueryAsset', | ||
'common\assets\FontAwesomeAsset' | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.