addChineseLatticeDialog.js 2.6 KB

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