Maison  >  Article  >  développement back-end  >  百度ueditor 上传图片后如何设置样式

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

WBOY
WBOYoriginal
2016-08-08 09:33:071294parcourir

UEditor是由百度web前端研发部开发所见即所得富文本web编辑器,具有轻量,可定制,注重用户体验等特点,开源基于MIT协议,允许自由使用和修改代码,涵盖流行富文本编辑器特色功能,独创多种全新编辑操作模式。

下面看看UEditor上传图片后,在内容展示会修改图片样式。但是表情也是img标签,所以全局修改是有问题的,

所以只能着手修改一下插件的代码。

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

找到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 属性的值

 

一种是修改js

找到ueditor.all.js 中 24461 如下代码

修改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);
}

 

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

以上就介绍了百度ueditor 上传图片后如何设置样式,包括了百度ueditor方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn