发布时间:2018-05-14作者:laosun阅读(5088)
ueditor自定义菜单按钮,插入html
现在跟着博主一步步的来添加一个,.比如我们添加一个名字叫做: insertahtml
, 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', '|', 'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|', 'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|', 'print', 'preview', 'searchreplace', 'drafts', 'insertahtml' ]] ,labelMap:{'insertahtml': '插入本站链接'} //当鼠标放在工具栏上时显示的tooltip提示,留空支持自动多语言配置,否则以配置值为准 //,labelMap:{ // 'anchor':'', 'undo':'' //}
如下图所示:
//为工具栏添加按钮,以下都是统一的按钮触发命令,所以写在一起 var btnCmds = ['undo', 'redo', 'formatmatch', 'bold', 'italic', 'underline', 'fontborder', 'touppercase', 'tolowercase', 'strikethrough', 'subscript', 'superscript', 'source', 'indent', 'outdent', 'blockquote', 'pasteplain', 'pagebreak', 'selectall', 'print','horizontal', 'removeformat', 'time', 'date', 'unlink', 'insertparagraphbeforetable', 'insertrow', 'insertcol', 'mergeright', 'mergedown', 'deleterow', 'deletecol', 'splittorows', 'splittocols', 'splittocells', 'mergecells', 'deletetable', 'drafts','insertahtml'];
如下图所示:
如果你自定义了toolbars,那么一定要添加的,如果使用默认的,则无需添加.
var ue = UE.getEditor('content', ........ toolbars[数组内别忘了添加]。
清空缓存刷新下页面吧(刷新缓存,chrome浏览器是Ctrl+R,mac下是command+R)!工具栏的对应位置是否出现了一个自己定义的按钮呢?如下图所示:
由于此时未设置对应按钮的图片样式,所以会显示默认的“B”字符。要想让其显示成自己需要的图标样式,接着按照下面的步骤动手吧。
第五步:如需更改成另外图标,那么制作一张 18 X 18的 png 透明图片。
然后样式这么设置
.edui-for-insertahtml .edui-icon { background: url(/assets/images/insertahtml.png) no-repeat !important; }
效果如下图所示:
下面我们就来定义该方法的具体内容:
在初始化编辑器的时候,加上自己的事件处理(插入一个URL),如下代码:
ue.commands['insertahtml'] = { execCommand: function() { this.execCommand('insertHtml', '<a href="https://www.sunjs.com/" target="_blank">技术客</a>'); return true; }, queryCommandState: function() { } };
版权属于: 技术客
原文地址: https://www.sunjs.com/article/detail/1ba746bd0fc148a1819f6c15674de48d.html
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。