You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.2 KiB
80 lines
2.2 KiB
/**
|
|
* upfile 1.1v
|
|
* The tinymce-plugins is used to upfile
|
|
*
|
|
* https://github.com/Five-great/tinymce-plugins
|
|
*
|
|
* Copyright 2020, Five(Li Hailong) The Chengdu, China https://www.fivecc.cn/
|
|
*
|
|
* Licensed under MIT
|
|
*/
|
|
tinymce.PluginManager.add('upfile', function(editor, url) {
|
|
var pluginName='上传文件';
|
|
window.upfile={}; //扔外部公共变量,也可以扔一个自定义的位置
|
|
|
|
var baseURL=tinymce.baseURL||'.';
|
|
var iframe1 = baseURL+'/plugins/upfile/upfiles.html';
|
|
upfile.file_callback = editor.getParam('file_callback', undefined, 'function');
|
|
upfile.tinymce = tinymce;
|
|
upfile.res={};
|
|
var openDialog = function() {
|
|
return editor.windowManager.openUrl({
|
|
title: pluginName,
|
|
size: 'large',
|
|
width: 450,
|
|
height: 450,
|
|
url:iframe1,
|
|
buttons: [
|
|
{
|
|
type: 'cancel',
|
|
text: 'Close'
|
|
},
|
|
{
|
|
type: 'custom',
|
|
text: 'Save',
|
|
name: 'save',
|
|
primary: true
|
|
},
|
|
],
|
|
onAction: function (api, details) {
|
|
switch (details.name) {
|
|
case 'save':
|
|
var res = upfile.res;
|
|
var html = '<span class="attachment" contenteditable="false"><a href="'+res.url+'" target="_blank" title="'+res.text+'" >'+res.text+'<a></span>';
|
|
editor.insertContent(html);
|
|
upfile.res={};
|
|
api.close();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
});
|
|
};
|
|
|
|
editor.ui.registry.getAll().icons.upfile || editor.ui.registry.addIcon('upfile','<svg width="20" height="20"><path d="M16.3 9.3a.8.8 0 00-1 0l-5.5 5.4a2.8 2.8 0 01-4.3-.4v-.1l-.2-.3-.1-.2a3 3 0 01-.2-.6V13c0-.9.2-1.7.8-2.2L11.7 5c.6-.7 1.6-.7 2.3 0a1.6 1.6 0 010 2.2L8 13a.4.4 0 01-.7-.3v-.3L12.2 8c.3-.3.3-.8 0-1a.8.8 0 00-1 0l-4.7 4.5a1.9 1.9 0 000 2.7c.8.7 2 .7 2.8 0L15 8.3a3 3 0 000-4.4 3.1 3.1 0 00-4.4 0L4.8 9.7a4.2 4.2 0 000 6 4.3 4.3 0 006 0l5.5-5.3.2-.6c0-.2 0-.4-.2-.5" fill-rule="evenodd"/></svg>');
|
|
|
|
editor.ui.registry.addButton('upfile', {
|
|
icon: 'upfile',
|
|
tooltip: pluginName,
|
|
onAction: function() {
|
|
openDialog();
|
|
}
|
|
});
|
|
editor.ui.registry.addMenuItem('upfile', {
|
|
icon: 'upfile',
|
|
text: '图片上传...',
|
|
onAction: function() {
|
|
openDialog();
|
|
}
|
|
});
|
|
return {
|
|
getMetadata: function() {
|
|
return {
|
|
name: pluginName,
|
|
url: "https://github.com/Five-great/tinymce-plugins",
|
|
};
|
|
}
|
|
};
|
|
});
|
|
|