addKityFormulaDialog.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* eslint-disable */
  2. UE.registerUI('kityformula', function(editor, uiname){
  3. // console.log(editor);
  4. // 创建dialog
  5. var kfDialog = new UE.ui.Dialog({
  6. // 指定弹出层路径
  7. iframeUrl: editor.options.UEDITOR_HOME_URL + 'kityformula-plugin/kityFormulaDialog.html',
  8. // iframeUrl: '../../public/ueditor/kityformula-plugin/kityFormulaDialog.html',
  9. // 编辑器实例
  10. editor: editor,
  11. // dialog 名称
  12. name: uiname,
  13. // dialog 标题
  14. title: '插入公式 - zhixinhuixue',
  15. // dialog 外围 css
  16. cssRules: 'width:783px; height: 386px;',
  17. //如果给出了buttons就代表dialog有确定和取消
  18. buttons:[
  19. {
  20. className:'edui-okbutton',
  21. label:'确定',
  22. onclick:function () {
  23. kfDialog.close(true);
  24. // editor.getKfContent(function(content){
  25. // console.log(content)
  26. // });//将公式图片base64替换成链接
  27. // setTimeout(function (){
  28. // editor.getKfContent(function(content){
  29. // console.log(content)
  30. // });//将公式图片base64替换成链接
  31. // },100)
  32. }
  33. },
  34. {
  35. className:'edui-cancelbutton',
  36. label:'取消',
  37. onclick:function () {
  38. kfDialog.close(false);
  39. }
  40. }
  41. ]});
  42. editor.ready(function(){
  43. UE.utils.cssRule('kfformula', 'img.kfformula{vertical-align: middle;}', editor.document);
  44. });
  45. var iconUrl = editor.options.UEDITOR_HOME_URL + 'kityformula-plugin/kf-icon.png';
  46. // var iconUrl = '/ueditor/kityformula-plugin/kf-icon.png';
  47. var tmpLink = document.createElement('a');
  48. tmpLink.href = iconUrl;
  49. tmpLink.href = tmpLink.href;
  50. iconUrl = tmpLink.href;
  51. var kfBtn = new UE.ui.Button({
  52. name:'插入' + uiname,
  53. title:'插入公式',
  54. //需要添加的额外样式,指定icon图标
  55. cssRules :'background: url("' + iconUrl + '") !important',
  56. onclick:function () {
  57. //渲染dialog
  58. kfDialog.render();
  59. kfDialog.open();
  60. }
  61. });
  62. //当点到编辑内容上时,按钮要做的状态反射
  63. editor.addListener('selectionchange', function () {
  64. var state = editor.queryCommandState(uiname);
  65. if (state == -1) {
  66. kfBtn.setDisabled(true);
  67. kfBtn.setChecked(false);
  68. } else {
  69. kfBtn.setDisabled(false);
  70. kfBtn.setChecked(state);
  71. }
  72. });
  73. return kfBtn;
  74. });