最近項目中遇到一個問題,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);}
這樣上傳下圖片你就能看見上傳的圖片都多了個樣式。
|
新聞熱點
疑難解答