Ueditor上传图片后自定义样式类名

Ueditor是百度的一个富文本插件,如果使用者会前端语言的话,那适用性就很好,特别是现在移动端纵横的情况。但往往使用者并不懂编程,要让他们使用前端语言的话是不可能的,这就需要我们在开发时就定义好整个样式。

正常情况下,我们上传后的图片是固定了宽高的,要想适用移动端,就必须使宽度定义为100%,或者加个类上去,我们可以自定义。这就是我们的思路。

下面是修改代码:

ueditor.all.js
UE.plugin.register('simpleupload', function (){
...
function initUploadBtn(){
...
domUtils.on(btnIframe, 'load', function(){
...
domUtils.on(input, 'change', function(){
...
me.execCommand('inserthtml', '<img class="loadingclass" id="' + loadingId + '" src="' + me.options.themePath + me.options.theme +'/images/spacer.gif" title="' + (me.getLang('simpleupload.loading') || '') + '" >');//网上说法这里可以加自定义样式,试过会报错ueditor.all.js :  #24461  行
me.execCommand('inserthtml', '<img class="loadingclass" id="' + loadingId + '" src="' + me.options.themePath + me.options.theme +'/images/spacer.gif" title="' + (me.getLang('simpleupload.loading') || '') +  width="291" height="164"+'"style="width: 291px; height: 164px;">');
function callback(){
...
        domUtils.setStyle(loader, 'width', '100%');//设置控件样式style#24527
...
domUtils.addClass(loader, '自定义样式类名');//是自带方法,可以实现#24534
...
}
...
})
...
})
...
}
...
})
设置style时,要同时修改usditor.config.js
(function(){
...
window.UEDITOR_CONFIG = {
...
// xss过滤白名单 名单来源: https://raw.githubusercontent.com/leizongmin/js-xss/master/lib/default.js
,whitList: {
...
img: ['src', 'alt', 'title', 'width', 'height', 'id', '_src', 'loadingclass', 'class', 'data-latex', 'style'],//添加过滤白名单style#403
...
}
...
}
...
})
posted @ 2016-12-28 14:13  流空-C  阅读(2793)  评论(0编辑  收藏  举报