01.code/LanweiUI/UEditor/_src/plugins/removeformat.js
(开头部分) 7KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
///import core
///commands 清除格式
///commandsName RemoveFormat
///commandsTitle 清除格式
/**
* @description 清除格式
* @name baidu.editor.execCommand
* @param {String} cmdName removeformat清除格式命令
* @param {String} tags 以逗号隔开的标签。如:span,a
* @param {String} style 样式
* @param {String} attrs 属性
* @param {String} notIncluedA 是否把a标签切开
* @author zhanyi
*/
UE.plugins['removeformat'] = function(){
var me = this;
me.setOpt({
'removeFormatTags': 'b,big,code,del,dfn,em,font,i,ins,kbd,q,samp,small,span,strike,strong,sub,sup,tt,u,var',
'removeFormatAttributes':'class,style,lang,width,height,align,hspace,valign'
});
me.commands['removeformat'] = {
execCommand : function( cmdName, tags, style, attrs,notIncludeA ) {
var tagReg = new RegExp( '^(?:' + (tags || this.options.removeFormatTags).replace( /,/g, '|' ) + ')$', 'i' ) ,
removeFormatAttributes = style ? [] : (attrs || this.options.removeFormatAttributes).split( ',' ),
range = new dom.Range( this.document ),
bookmark,node,parent,
filter = function( node ) {
return node.nodeType == 1;
};
function isRedundantSpan (node) {
if (node.nodeType == 3 || node.tagName.toLowerCase() != 'span')
return 0;
if (browser.ie) {
//ie 下判断实效,所以只能简单用style来判断
//return node.style.cssText == '' ? 1 : 0;
var attrs = node.attributes;
if ( attrs.length ) {
for ( var i = 0,l = attrs.length; i<l; i++ ) {
if ( attrs[i].specified ) {
return 0;
}
}
return 1;
}
}
return !node.attributes.length
}
function doRemove( range ) {
var bookmark1 = range.createBookmark();
if ( range.collapsed ) {
range.enlarge( true );
}
//不能把a标签切了
if(!notIncludeA){
var aNode = domUtils.findParentByTagName(range.startContainer,'a',true);
if(aNode){
后面还有 122 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读 AI
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
