昨天爲一個客戶的項目修改後臺富編輯器在上傳圖片後去掉自動添加高寬度的功能。這個客戶所用的後臺系統是 PHPCMS ,這個系統所使用的富文本編輯器是知名的 CKEditor,這個編輯器在上傳圖片後會自動添加高寬度的 style 屬性。以下:css
<img alt="" src="/uploadfile/2017/0608/20170608015605433.jpg" style="width: 580px; height: 295px;" />
那麼如何去掉【style=」width: 580px; height: 295px;「】這個屬性,因而呼在【度娘】搜索了屢次沒有找到相關的資料,因而呼就本身動手去找解決方法了,現將這個解決方法記錄下來。編輯器
PHPCMS 所使用的 CKEditor 的配置文件 config.js 中沒有找到有關這項的配置設置的方法說明及參數,這也許和它使用的版本有關,也或者是 PHPCMS 自家將這項的設置給去除,再怎麼猜想也沒用啊。因而呼想到直接經過修改 plugins 來解決這個問題。ide
按照這個線索繼續查找,找到了處理圖片的地方是測試
你的 PHPCMS 路徑\statics\js\ckeditor\plugins\image\dialogs\image.jsthis
這個打開後是壓縮版的 JS,能夠用格式化 JS 將其中的代碼清楚的顯示出來後就能夠找設置 style 的幾個點。一共找到 2 處有關它的設置分別是:code
一、設置寬度的地方圖片
if (B == d) { if (E) C.setStyle('width', CKEDITOR.tools.cssLength(E)); else C.removeStyle('width'); ! D && C.removeAttribute('width'); } else if (B == f) { var F = E.match(h); if (!F) { var G = this.getDialog().originalElement; if (G.getCustomData('isReady') == 'true') C.setStyle('width', G.$.width + 'px'); } else C.setStyle('width', CKEDITOR.tools.cssLength(E)); } else if (B == g) { C.removeAttribute('width'); C.removeStyle('width'); }
二、設置高度的地方rem
if (B == d) { if (E) C.setStyle('height', CKEDITOR.tools.cssLength(E)); else C.removeStyle('height'); ! D && C.removeAttribute('height'); } else if (B == f) { var F = E.match(h); if (!F) { var G = this.getDialog().originalElement; if (G.getCustomData('isReady') == 'true') C.setStyle('height', G.$.height + 'px'); } else C.setStyle('height', CKEDITOR.tools.cssLength(E)); } else if (B == g) { C.removeAttribute('height'); C.removeStyle('height'); }
將以上兩個地方的代碼註釋也好刪除也罷均可以,任你選。最後測試圖片上傳就能發現問題解決了。get