1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
| const dialog = (editor) => {
| return {
| title: '上传文件',
| body: {
| type: 'panel',
| items: [
| {
| type: 'urlinput', // component type
| name: 'upload', // identifier
| filetype: 'file', // allow any file types
| label: 'Url', // text for component label
| }
| ]
| },
| buttons: [
| {
| type: 'cancel',
| text: '取消'
| },
| {
| type: 'submit',
| text: '插入',
| primary: true
| }
| ],
| onChange(api) {
| // api.block('上传中……')
| // console.log(api.getData())
| },
| onSubmit: function (api) {
| let data = api.getData()
| console.log(data)
| let url= data.upload.meta.text
| // 截取文件名
| let filename = url.substring(url.lastIndexOf('/') + 1)
| // 将输入框内容插入到内容区光标位置
| editor.insertContent(`<a href="${url}" download="${filename}" target="_blank">下载链接</a>`)
| api.close()
| }
| }
| }
|
| tinymce.PluginManager.add('download', function (editor, url) {
| // 注册一个工具栏按钮名称
| editor.ui.registry.addButton('download', {
| text: '',
| icon: 'download',
| tooltip: '下载',
| onAction: function () {
| const dialogConfig = dialog(editor)
| editor.windowManager.open(dialogConfig)
| }
| })
|
| return {
| getMetadata: function () {
| return {
| //插件名和链接会显示在“帮助”→“插件”→“已安装的插件”中
| name: '下载', //插件名称
| url: 'doc.tduckcloud.com' //作者网址
| }
| }
| }
| })
|
|