plugin.js 1.4 KB

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