UEditor工具栏自定义位置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UEditor工具栏自定义位置相关的知识,希望对你有一定的参考价值。

UEditor上传图片啊 表情啊 这些工具栏我想拿出来 放到自定义的位置上 这样可以吗 有没有参考 谢谢大家

参考技术A 步骤一:创建编辑器
var option =
initialContent: 'hello world',//初始化编辑器的内容
minFrameHeight: 200,
iframeCssUrl :'../../themes/default/iframe.css' //给iframe样式的路径
;
//实例化编辑器
var myeditor = new baidu.editor.Editor(option);

步骤二:给自定义的ui注册事件
myeditor.addListener('selectionchange', function ()
var cmdName = ['bold','italic','underline','strikethrough'],
fontName = ['fontfamily','fontsize'],i=-1,
range = myeditor.selection.getRange();//得到选中区域
//判断是否为封闭标签
if(range.collapsed)
document.getElementById("bold").disabled = true;
document.getElementById("italic").disabled = true;
document.getElementById("underline").disabled = true;
document.getElementById("strikethrough").disabled = true;
document.getElementById("fontfamily").disabled = true;
document.getElementById("fontsize").disabled = true;
document.getElementById("fontColor").disabled = true;
else
document.getElementById("bold").disabled = false;
document.getElementById("italic").disabled = false;
document.getElementById("underline").disabled = false;
document.getElementById("strikethrough").disabled = false;
document.getElementById("fontfamily").disabled = false;
document.getElementById("fontsize").disabled = false;
document.getElementById("fontColor").disabled = false;

while(i++ < cmdName.length-1)
//分别判断underline和strikethrough的命令
if(cmdName[i] == "underline")
var val = myeditor.queryCommandValue("underline");
if(val == "underline")
document.getElementById(cmdName[i]).style.color = "red";
else
document.getElementById(cmdName[i]).style.color = "";

else if(cmdName[i] == "strikethrough")
var val = myeditor.queryCommandValue("underline");
if(val == "line-through")
document.getElementById(cmdName[i]).style.color = "red";
else
document.getElementById(cmdName[i]).style.color = "";

else
var state = myeditor.queryCommandState(cmdName[i]);
if(state == 1)
document.getElementById(cmdName[i]).style.color = "red";
else
document.getElementById(cmdName[i]).style.color = "";



i = -1;
while(i++<fontName.length-1)
var fstate = myeditor.queryCommandValue(fontName[i]).toLowerCase();
var fselect = document.getElementById(fontName[i]);
for(var j= 0;j<fselect.options.length;j++)
if(fselect.options[j].value.toLowerCase().indexOf(fstate.split(",")[0])!=-1)
fselect.options[j].selected = "true";



var fcolor = myeditor.queryCommandValue("forecolor");
document.getElementById("fontColor").style.color = fcolor;
);

以上是关于UEditor工具栏自定义位置的主要内容,如果未能解决你的问题,请参考以下文章

Ueditor文本编辑工具栏自定义

怎么定义ueditor的工具栏显示位置

UEditor自定义toolbar工具条

UEditor 自定义 工具条

Ueditor 自定义按钮

基于UEditor上开发的表单设计器--自定义文本控件