tinymce.PluginManager.add('simpleMedia', function(editor) {
editor.ui.registry.addButton('simpleMedia', {
text: `<span title="插入/编辑视频">
<svg width="24" height="24" focusable="false"><path d="M4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 01-1-1V4c0-.6.4-1 1-1zm1 2v14h14V5H5zm4.8 2.6l5.6 4a.5.5 0 010 .8l-5.6 4A.5.5 0 019 16V8a.5.5 0 01.8-.4z" fill-rule="nonzero"></path></svg>
</span>`,
onAction: function (data) {
let input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'video/*');
input.click();
input.onchange = function(e) {
const vm = window.$Vue;
const file = this.files[0];
vm.$commonFunc.uploadFile({
that: vm,
file: file,
uploadDoneCallback: (res) => {
let videoUrl = `<video width="350" height="120" controls="controls" src="${res.fileUrl}" />`;
editor.insertContent(videoUrl);
},
});
}
}
});
});
|