流程比较简单,主要有以下步骤:
注册插件
首先,全局配置kindeditor参数:
PHP;">
KindEditor.lang({
audio : 'MP3'
});
KindEditor.options.htmlTags['audio'] = ['src','controls','autoplay','type'];
KindEditor.options.htmlTags['source'] = ['src','type'];
在初始化编辑器的地方,配置按钮列表items参数,把 'audio' 放在合适的位置:
PHP;">
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样式:
.ke-icon-audio {
background-position: 0px -528px;
width: 16px;
height: 16px;
}
这里我图方便,直接用了自带的音视频按钮的图标,自定义图标请手动指定 background 样式属性。
最后,创建脚本
dio/audio.js
audio目录手动建立。
我们把
修改media插件
主要是去掉一些无用的属性,如 宽、高、自动播放等,并修改插入代码的部分,手动构建 "audio" 标签的HTML代码。
KindEditor.plugin('audio',function(K) {
var self = this,name = 'audio',lang = self.lang(name + '.'),allowMediaUpload = K.undef(self.allowMediaUpload,true),allowFileManager = K.undef(self.allowFileManager,false),formatUploadUrl = K.undef(self.formatUploadUrl,uploadJson = K.undef(self.uploadJson,self.basePath + 'PHP/upload_json.PHP');
self.plugin.media = {
edit : function() {
var html = [
'<div style="padding:20px;">',//url
'<div class="ke-dialog-row">','<label for="keUrl" style="width:60px;">MP3 URL',' ',' ','
','var self = this,name = 'audio',lang = self.lang(name + '.'),allowMediaUpload = K.undef(self.allowMediaUpload,true),allowFileManager = K.undef(self.allowFileManager,false),formatUploadUrl = K.undef(self.formatUploadUrl,uploadJson = K.undef(self.uploadJson,self.basePath + 'PHP/upload_json.PHP');
self.plugin.media = {
edit : function() {
var html = [
'<div style="padding:20px;">',//url
'<div class="ke-dialog-row">','<label for="keUrl" style="width:60px;">MP3 URL',' ',' ','