plugin.min.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. tinymce.PluginManager.add('kityformula-editor', function (editor, url) {
  2. var baseURL = '/tinymce/plugins/kityformula-editor/kityFormula.html'
  3. editor.on('dblclick', function () {
  4. var sel = editor.selection.getContent()
  5. // eslint-disable-next-line no-useless-escape
  6. var path = /^<img\s+[^>]*src="data:image\/png;base64,[A-Za-z0-9+\/=]*"[^>]*data-latex="([^"]+)"[^>]*>$/
  7. var path2 = /data-latex="(.*?)"/g
  8. if (sel.search(path) == 0) {
  9. sel.replace(path2, function ($0, $1) {
  10. var param = encodeURIComponent($1)
  11. openDialog(param)
  12. return $0
  13. })
  14. }
  15. })
  16. var openDialog = function (param) {
  17. return editor.windowManager.openUrl({
  18. title: '插入公式',
  19. size: 'large',
  20. width: 785,
  21. height: 475,
  22. url: param ? baseURL + '?c=' + param : baseURL,
  23. buttons: [
  24. {
  25. type: 'cancel',
  26. text: 'Close'
  27. },
  28. {
  29. type: 'custom',
  30. text: 'Save',
  31. name: 'save',
  32. primary: true
  33. }
  34. ],
  35. onAction: function (api, details) {
  36. switch (details.name) {
  37. case 'save':
  38. api.sendMessage('save')
  39. break
  40. default:
  41. break
  42. }
  43. }
  44. })
  45. }
  46. editor.ui.registry.addButton('kityformula-editor', {
  47. text: '公式',
  48. tooltip: '插入公式',
  49. onAction: function () {
  50. openDialog()
  51. }
  52. })
  53. editor.ui.registry.addMenuItem('kityformula-editor', {
  54. text: '公式',
  55. onAction: function () {
  56. openDialog()
  57. }
  58. })
  59. return {
  60. getMetadata: function () {
  61. return {
  62. name: '公式',
  63. url: ''
  64. }
  65. }
  66. }
  67. })