class UEditor extends Field
{
protected $view = 'admin.ueditor';
protected static $css = [
'/vendor/ueditor/themes/iframe.css'
];
protected static $js = [
'/vendor/ueditor/ueditor.config.js',
'/vendor/ueditor/lang/zh-cn/zh-cn.js',
'/vendor/ueditor/ueditor.all.min.js',
];
public function render()
{
$name = $this->formatName($this->column);
$this->token = csrf_token();
$this->script = <<<EOT
UE.delEditor('{$this->id}');
var ue = UE.getEditor('{$this->id}');
$(document).on('pjax:start', function() {
UE.delEditor('{$this->id}');
var ue = UE.getEditor('{$this->id}');
});
EOT;
return parent::render();
}
}
在进编辑页面的时候,有些从其他地方复制过来的内容样式会有问题,laravel-admin在调转edit页面的时候是通过pjax更新内容的,这个时候ueditor.all.min.js需要重新执行一次才能正确加载编辑内容,所以需要在pjax开始的时候去重新初始化一次ueditor