addKityFormulaDialog.js 2.1 KB

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