注冊插件
首先,全局配置kindeditor參數:
KindEditor.lang({ audio : 'MP3' }); KindEditor.options.htmlTags['audio'] = ['src','controls','autoplay','type']; KindEditor.options.htmlTags['source'] = ['src','controls','autoplay','type'];
在初始化編輯器的地方,配置按鈕列表items參數,把
'audio'
放在合適的位置:
KindEditor.ready(function(K) { editor = K.create('#info,#spread_info', { //其他配置省略... items : [ 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage', '|' ,'table', 'hr', 'emoticons', 'baidumap', 'pagebreak', 'anchor', 'link', 'unlink', '|', 'about','audio' ] });
為了便于閱讀,我把audio按鈕放在最后,在 "幫助" 標簽的后面。
為了讓按鈕能夠顯示,我們還需要指定一下css樣式:
這里我圖方便,直接用了自帶的音視頻按鈕的圖標,自定義圖標請手動指定 background 樣式屬性。
最后,創建腳本
kindeditor/plugins/audio/audio.js
audio目錄手動建立。
我們把
plugins/media/media.js
中的代碼復制到audio.js里,然后著手修改。
修改media插件
主要是去掉一些無用的屬性,如 寬、高、自動播放等,并修改插入代碼的部分,手動構建 "audio" 標簽的html代碼。
至此,整個插件基本結束。
需要注意的是,上傳文件用的是通用的配置uploadJson參數,但會在上傳的時候自動添加一個get參數 "dir=audio" ,以便后臺識別:
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com