- 修改ueditor.config.js文件
在ueditor.config.js文件中,找到toolbars参数,增加一个“audio”字符串,对应着添加一个labelMap,用于鼠标移上按钮时的提示。
//工具栏上的所有的功能按钮和下拉框,可以在new编辑器的实例时选择自己需要的从新定义 , 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‘,‘audio‘, ‘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‘, ‘help‘, ‘drafts‘ ]] //当鼠标放在工具栏上时显示的tooltip提示,留空支持自动多语言配置,否则以配置值为准 ,labelMap:{ audio:‘音频‘ }
2.修改ueditor.all.js文件
找到iframeUrlMap增加一行:
‘audio‘: ‘~/dialogs/audio/audio.html‘,
找到btnCmds、dialogBtns增加一个元素:audio
接下来在dialogs文件夹下创建audio文件夹并新建audio.html
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script type="text/javascript" src="../internal.js"></script> <style type="text/css"> *{margin:0;padding:0;color: #838383;} table{font-size: 12px;margin: 10px;line-height: 30px} .txt{width:300px;height:21px;line-height:21px;border:1px solid #d7d7d7;} </style> </head> <body> <table> <tr> <td><label for="href">音频地址:</label></td> <td><input class="txt" id="href" type="text" /></td> </tr> </table> <script type="text/javascript"> function handleDialogOk() { if ($G(‘href‘).value) { var patt1 = /ogg|oga|aac|m4a|mp3|wav/gi; if (patt1.test($G(‘href‘).value)) { editor.execCommand(‘insertHtml‘, "<object>" + "<audio controls>" + "<source src=\"" + $G(‘href‘).value + "\" >" + "Your browser does not support the audio tag" + "</audio>" + "</object>"); dialog.close(); } else { alert("不支持该音频格式"); return false; } } else { alert("请输入音频地址"); return false; } } dialog.onok = handleDialogOk; $G(‘href‘).onkeydown = function(evt) { evt = evt || window.event; if (evt.keyCode == 13) { handleDialogOk(); return false; } } </script> </body> </html>
相关的操作js也写在该html里面。
到这里,运行编辑器 新加的按钮已经出来啦,但是点击弹出的窗口样式不对 乱了;
这时候,修改themes/default/css/ueditor.css文件,增加一条样式:
.edui-default .edui-for-audio .edui-icon { background-position: -18px -40px }
至此,弹窗可以正常显示了,并能插入相应的代码。
时间: 2024-09-28 18:51:43