百度ueditor 上传图片后如何设置样式

最近项目中遇到一个问题,UEditor上传图片后,在内容展现会修改图片样式。可是表情也是img标签,因此全局修改是有问题的,php

因此只能着手修改一下插件的代码。html

首先找到图片上传的服务器段文件。这里主要是php讲解json

找到php目录下Uploader.class.php 337行服务器

public function getFileInfo()
   {
       return array(
           "state" => $this->stateInfo,
           "url" => $this->fullName,
           "title" => $this->fileName,
           "original" => $this->oriName,
           "type" => $this->fileType,
	   "class"=> "aaa"
           "size" => $this->fileSize,

       );
   }

这样返回的json 多一个class 属性的值dom

 

一种是修改jsthis

找到ueditor.all.js 中 24461 以下代码url

修改js插件

function callback(){
try{
var link, json, loader,
body = (iframe.contentDocument || iframe.contentWindow.document).body,
result = body.innerText || body.textContent || '';
json = (new Function("return " + result))();
link = me.options.imageUrlPrefix + json.url;
if(json.state == 'SUCCESS' && json.url) {
loader = me.document.getElementById(loadingId);
loader.setAttribute('src', link);
loader.setAttribute('_src', link);
loader.setAttribute('class', json.class || ''); //添加行代码
loader.setAttribute('title', json.title || '');
loader.setAttribute('alt', json.original || '');
loader.removeAttribute('id');
domUtils.removeClasses(loader, 'loadingclass');
} else {
showErrorLoader && showErrorLoader(json.state);
}
}catch(er){
showErrorLoader && showErrorLoader(me.getLang('simpleupload.loadError'));
}
form.reset();
domUtils.un(iframe, 'load', callback);
}

 

这样上传下图片你就能看见上传的图片都多了个样式。orm