UEditor添加自定義彈窗 插入音頻地址


  1. 修改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
}

至此,彈窗可以正常顯示了,並能插入相應的代碼。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM