使用Ueditor上传图片后自定义样式类名介绍

高洛峰
高洛峰 原创
2017-03-15 11:39:02 1281浏览

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过滤白名单 名单来源: //m.sbmmt.com/

,whitList: {

...

img: ['src', 'alt', 'title', 'width', 'height', 'id', '_src', 'loadingclass', 'class', 'data-latex', 'style'],//添加过滤白名单style#403

...

}

...

}

...

})

以上就是使用Ueditor上传图片后自定义样式类名介绍的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。