百度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

相關文章
相關標籤/搜索