plugin.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * upfile 1.1v
  3. * The tinymce-plugins is used to upfile
  4. *
  5. * https://github.com/Five-great/tinymce-plugins
  6. *
  7. * Copyright 2020, Five(Li Hailong) The Chengdu, China https://www.fivecc.cn/
  8. *
  9. * Licensed under MIT
  10. */
  11. tinymce.PluginManager.add('upfile', function(editor, url) {
  12. var pluginName='上传文件';
  13. window.upfile={}; //扔外部公共变量,也可以扔一个自定义的位置
  14. var baseURL=tinymce.baseURL||'.';
  15. var iframe1 = baseURL+'/plugins/upfile/upfiles.html';
  16. upfile.file_callback = editor.getParam('file_callback', undefined, 'function');
  17. upfile.tinymce = tinymce;
  18. upfile.res={};
  19. var openDialog = function() {
  20. return editor.windowManager.openUrl({
  21. title: pluginName,
  22. size: 'large',
  23. width: 450,
  24. height: 450,
  25. url:iframe1,
  26. buttons: [
  27. {
  28. type: 'cancel',
  29. text: 'Close'
  30. },
  31. {
  32. type: 'custom',
  33. text: 'Save',
  34. name: 'save',
  35. primary: true
  36. },
  37. ],
  38. onAction: function (api, details) {
  39. switch (details.name) {
  40. case 'save':
  41. var res = upfile.res;
  42. var html = '<span class="attachment" contenteditable="false"><a href="'+res.url+'" target="_blank" title="'+res.text+'" >'+res.text+'<a></span>';
  43. editor.insertContent(html);
  44. upfile.res={};
  45. api.close();
  46. break;
  47. default:
  48. break;
  49. }
  50. }
  51. });
  52. };
  53. editor.ui.registry.getAll().icons.upfile || editor.ui.registry.addIcon('upfile','<svg viewBox="0 0 1280 1024" xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M1126.2,779.8V87.6c0-24-22.6-86.9-83.5-86.9H83.5C14.7,0.7,0,63.7,0,87.7v692c0,36.2,29.2,89.7,83.5,89.7l959.3-1.3c51.7,0,83.5-42.5,83.5-88.3zm-1044,4V86.3h961.6V783.7H82.2v0.1z" fill="#53565A"/><path d="M603,461.6L521.1,366.3,313,629.8,227.2,546.8,102.4,716.8H972.8v-170L768.2,235.2,603.1,461.6zM284.6,358.4a105.4,105.4,0,0,0,73.5-30c19.5-19.1,30.3-45,30.2-71.8,0-56.8-45.9-103-102.4-103-56.6,0-102.4,46.1-102.4,103C183.4,313.5,228,358.4,284.6,358.4z" fill="#9598A0"/><path d="M1197.7,153.6l-0.3,669.3s13.5,113.9-67.4,113.9H153.6c0,24.1,23.9,87.2,83.5,87.2h959.3c58.3,0,83.6-49.5,83.6-89.9V240.8c-0.1-41.8-44.9-87.2-82.3-87.2z" fill="#53565A"/></svg>');
  54. editor.ui.registry.addButton('upfile', {
  55. icon: 'upfile',
  56. tooltip: pluginName,
  57. onAction: function() {
  58. openDialog();
  59. }
  60. });
  61. editor.ui.registry.addMenuItem('upfile', {
  62. icon: 'upfile',
  63. text: '图片上传...',
  64. onAction: function() {
  65. openDialog();
  66. }
  67. });
  68. return {
  69. getMetadata: function() {
  70. return {
  71. name: pluginName,
  72. url: "https://github.com/Five-great/tinymce-plugins",
  73. };
  74. }
  75. };
  76. });