经常用到编辑器,也经常忘记一些常用编辑器的配置,今天干脆写篇记录下来
编辑器:百度编辑器
版本:1.2.6 utf-8
1,引入js,css,文件
<!-- 配置文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
<!-- 语言包文件(建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败) -->
<script type="text/javascript" src="__PUBLIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
2,设置容器
<script id="container" name="content" type="text/plain">
</script>
3,配置
看源码如下:
UE.getEditor = function (id, opt) {
var editor = instances[id];
if (!editor) {
editor = instances[id] = new UE.ui.Editor(opt);
editor.render(id);
}
return editor;
};
可知,id为编辑器要渲染的容器id,opt为参数对象,所以配置如下:
<script type="text/javascript">
var editor = UE.getEditor('container',{
toolbars:[
['fullscreen', 'source', '|', 'undo', 'redo', '|',
'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
'directionalityltr', 'directionalityrtl', 'indent', '|',
'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
'insertimage', 'emotion', 'scrawl',
]
]//自定义工具
,initialFrameHeight:350 //容器高度
,elementPathEnabled:false //是否显示底部的元素层级关系
,UEDITOR_HOME_URL:"Public/ueditor/" //ueditor的路径,这个很关键
})
</script>