Htmleditor.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Element", null, false);
  3. MWF.xApplication.process.FormDesigner.Module.Htmleditor = MWF.FCHtmleditor = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "/x_component_process_FormDesigner/Module/Htmleditor/htmleditor.html"
  9. },
  10. initialize: function(form, options){
  11. this.setOptions(options);
  12. this.path = "/x_component_process_FormDesigner/Module/Htmleditor/";
  13. this.cssPath = "/x_component_process_FormDesigner/Module/Htmleditor/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. this.moduleType = "element";
  16. this.moduleName = "htmleditor";
  17. this.form = form;
  18. this.container = null;
  19. this.containerNode = null;
  20. },
  21. _createMoveNode: function(){
  22. this.moveNode = new Element("div", {
  23. "MWFType": "htmleditor",
  24. "id": this.json.id,
  25. "styles": this.css.moduleNodeMove,
  26. "events": {
  27. "selectstart": function(){
  28. return false;
  29. }
  30. }
  31. }).inject(this.form.container);
  32. },
  33. _createNode: function(){
  34. this.node = this.moveNode.clone(true, true);
  35. this.node.setStyles(this.css.moduleNode);
  36. this.node.set("id", this.json.id);
  37. this.node.addEvent("selectstart", function(e){
  38. e.preventDefault();
  39. });
  40. // this.loadCkeditor();
  41. },
  42. _setEditStyle_custom: function(name){
  43. if (name=="editorProperties"){
  44. if (this.editor){
  45. Object.each(this.json.editorProperties, function(value, key){
  46. if (value=="true") this.json.editorProperties[key] = true;
  47. if (value=="false") this.json.editorProperties[key] = false;
  48. }.bind(this));
  49. this.distroyCkeditor();
  50. var config = Object.clone(this.json.editorProperties);
  51. if (this.json.config){
  52. if (this.json.config.code){
  53. var obj = MWF.Macro.exec(this.json.config.code, this);
  54. Object.each(obj, function(v, k){
  55. config[k] = v;
  56. });
  57. }
  58. }
  59. this.loadCkeditor(config);
  60. }
  61. }
  62. if (name=="templateCode"){
  63. if (this.editor) this.editor.setData(this.json.templateCode);
  64. }
  65. },
  66. //kindeditor
  67. // loadkindeditor: function(){
  68. // COMMON.AjaxModule.load("kindeditor", function(){
  69. // var editorNode = new Element("textarea#kindeditorTextarea").inject(this.node);
  70. //
  71. // // KindEditor.ready(function(K) {
  72. // this.editor = KindEditor.create("#kindeditorTextarea", {
  73. // "basePath": COMMON.contentPath+"/res/framework/htmleditor/kindeditor/",
  74. // "readonlyMode" : true,
  75. // "width": "100%",
  76. // "height": "200px"
  77. // });
  78. // // });
  79. //
  80. // this.editorType = "kindeditor";
  81. // }.bind(this));
  82. // },
  83. // distroykindeditor: function(){
  84. // KindEditor.remove("#kindeditorTextarea");
  85. // $("kindeditorTextarea").destroy();
  86. // this.editor = null;
  87. // this.editorType = "";
  88. // },
  89. //nicEdit
  90. // loadnicEdit: function(){
  91. // COMMON.AjaxModule.load("nicEdit", function(){
  92. // var editorNode = new Element("textarea", {
  93. // "styles": {
  94. // "width":"100%",
  95. // "height": "200px"
  96. // }
  97. // }).inject(this.node);
  98. // this.editor = new nicEditor({fullPanel : true}).panelInstance(editorNode);
  99. // this.editorType = "nicEdit";
  100. // }.bind(this));
  101. // },
  102. // distroynicEdit: function(){
  103. // var editorNode = this.editor.nicInstances[0].e;
  104. // this.editor.nicInstances[0].remove();
  105. // editorNode.destroy();
  106. // this.editor = null;
  107. // this.editorType = "";
  108. // },
  109. _initModule: function(){
  110. this.node.empty();
  111. var config = Object.clone(this.json.editorProperties);
  112. if (this.json.config){
  113. if (this.json.config.code){
  114. var obj = MWF.Macro.exec(this.json.config.code, this);
  115. Object.each(obj, function(v, k){
  116. config[k] = v;
  117. });
  118. }
  119. }
  120. this.loadCkeditor(config);
  121. this._setNodeProperty();
  122. if (!this.form.isSubform) this._createIconAction() ;
  123. this._setNodeEvent();
  124. },
  125. //ckeditor
  126. loadCkeditor: function(config){
  127. COMMON.AjaxModule.load("ckeditor", function(){
  128. CKEDITOR.disableAutoInline = true;
  129. var editorDiv = new Element("div").inject(this.node);
  130. if (this.json.templateCode) editorDiv.set("html", this.json.templateCode);
  131. var height = this.node.getSize().y;
  132. var editorConfig = config || {};
  133. if (this.form.options.mode=="Mobile"){
  134. // if (!editorConfig.toolbar && !editorConfig.toolbarGroups){
  135. editorConfig.toolbar = [
  136. //{ name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  137. //{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ] },
  138. //{ name: 'links' },
  139. //{ name: 'insert' },
  140. //{ name: 'forms' },
  141. //{ name: 'tools' },
  142. //{ name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  143. //{ name: 'others' },
  144. //'/',
  145. { name: 'paragraph', items: [ 'Bold', 'Italic', "-" , 'TextColor', "BGColor", 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', "-", 'Undo', 'Redo' ] },
  146. { name: 'basicstyles', items: [ 'Styles', 'FontSize']}
  147. //{ name: 'colors' },
  148. //{ name: 'about' }
  149. ];
  150. // }
  151. }
  152. // CKEDITOR.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/";
  153. this.editor = CKEDITOR.replace(editorDiv, editorConfig);
  154. this.editor.on("dataReady", function(){
  155. this.editor.setReadOnly(true);
  156. }, this);
  157. }.bind(this));
  158. },
  159. distroyCkeditor: function(){
  160. if (this.editor) this.editor.destroy();
  161. this.editor = null;
  162. }
  163. });