plugin.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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: "http://hgcserver.gitee.io",
  63. };
  64. }
  65. };
  66. });