ue.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. var _min_toolbars=[
  2. [ 'undo', 'redo'
  3. ,'|', 'indent',"bold","italic","underline", 'strikethrough'
  4. ,"|","insertorderedlist","insertunorderedlist"
  5. ,'|','paragraph','fontfamily','fontsize', 'justifyleft', 'justifycenter','justifyright', 'justifyjustify'
  6. ,"|",'removeformat','forecolor','backcolor'
  7. ,'|','date','time',"fullscreen"
  8. ,'|','insertimage'
  9. ]
  10. ]
  11. var empty_toolbars=[];
  12. function _addCustomButton() {
  13. UE.registerUI('插入变量',function(editor,uiName){
  14. //注册按钮执行时的command命令,用uiName作为command名字,使用命令默认就会带有回退操作
  15. editor.registerCommand(uiName,{
  16. execCommand:function(cmdName,value){
  17. this.execCommand('insertHTML',value);
  18. }
  19. });
  20. var selectOptions = [];
  21. selectOptions.push({label:'文件编号',value:'${_文件编号}'});
  22. selectOptions.push({label:'发送人',value:'${_发送人}'});
  23. selectOptions.push({label:'部门',value:'${_部门}'});
  24. selectOptions.push({label:'发送时间',value:'${_发送时间}'});
  25. selectOptions.push({label:'自定义变量',value:'${}'});
  26. var items = [];
  27. for(var i=0;i<selectOptions.length;i++){
  28. var so = selectOptions[i];
  29. items.push({
  30. label:so.label
  31. ,value:so.value
  32. ,renderLabelHtml:function () {
  33. //这个是希望每个条目的字体是不同的
  34. return '<div class="edui-label %%-label" style="line-height:2;font-size:' +
  35. this.value + 'px;">' + (this.label || '') + '</div>';
  36. }
  37. });
  38. }
  39. //创建下来框
  40. var combox = new UE.ui.Combox({
  41. //需要指定当前的编辑器实例
  42. editor:editor,
  43. //添加条目
  44. items:items,
  45. //当选中时要做的事情
  46. onselect:function (t, index) {
  47. //拿到选中条目的值
  48. editor.execCommand(uiName, this.items[index].value);
  49. },
  50. //提示
  51. title:uiName,
  52. //当编辑器没有焦点时,combox默认显示的内容
  53. initValue:uiName
  54. });
  55. return combox;
  56. });
  57. }
  58. function checkVar(value){
  59. var $findRegExp = /\${([^\$}]*?)}/gm;
  60. var result;
  61. while(result=$findRegExp.exec(value)){
  62. var variableName = result[1];
  63. if(variableName==''){
  64. return "请填写变量名"
  65. }
  66. if(variableName.length>20){
  67. return "请确认变量表达式填写正确"
  68. }
  69. }
  70. return true;
  71. }