plugin.min.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. console.log('双击sel=', sel)
  6. var path=/\<img(.*?)src="data:image\/png;base64,[A-Za-z0-9+/=]*"(.*?)data-latex="(.*?)" \/>/g;
  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: "http://hgcserver.gitee.io",
  64. };
  65. }
  66. };
  67. });