Htmleditor.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. MWF.xDesktop.requireApp("process.Xform", "Htmleditor", null, false);
  2. MWF.xApplication.cms.Xform.Htmleditor = MWF.CMSHtmleditor = new Class({
  3. Extends: MWF.APPHtmleditor,
  4. _loadUserInterface: function(){
  5. this.node.empty();
  6. if (this.readonly){
  7. // var html = this.parseImage( this._getBusinessData() );
  8. // this.node.set("html", html);
  9. this.node.set("html", this._getBusinessData());
  10. this.node.setStyles({
  11. "-webkit-user-select": "text",
  12. "-moz-user-select": "text"
  13. });
  14. if( layout.mobile ){
  15. this.node.getElements("img").each( function( img ){
  16. //if( img.height )img.erase("height");
  17. img.setStyles({
  18. "height": "auto",
  19. "max-width" : "100%"
  20. });
  21. }.bind(this))
  22. }
  23. }else{
  24. var config = Object.clone(this.json.editorProperties);
  25. if (this.json.config){
  26. if (this.json.config.code){
  27. var obj = MWF.CMSMacro.exec(this.json.config.code, this);
  28. Object.each(obj, function(v, k){
  29. config[k] = v;
  30. });
  31. }
  32. }
  33. this.loadCkeditor(config);
  34. }
  35. },
  36. // parseImage : function( html ){
  37. // html = ( html || "" ).replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (img, capture) {
  38. // if( img.indexOf( "data-id" ) > -1 && img.indexOf("setImageSrc()") > -1 ){
  39. // var ids = img.match( /(?<=data-id=").*?(?=")/g );
  40. // if( ids && ids.length > 0 ){
  41. // var newSrc = MWF.xDesktop.getImageSrc( ids[0] );
  42. // var newImg = this.replaceAttr( img, "img", "src", newSrc );
  43. // return newImg;
  44. // }
  45. // }
  46. // return img;
  47. // }.bind(this));
  48. // return html
  49. // },
  50. // replaceAttr: function(src_str, tag, attr, val) {
  51. // if(src_str.indexOf(attr) > 0) {
  52. // //包含attr属性,替换attr
  53. // var sub_reg = new RegExp(attr + '=[\'\"]([^"]*)[\'\"]', 'gi');
  54. // return src_str.replace(sub_reg, attr +'=' + val);
  55. // }else{
  56. // //不包含attr属性,添加attr
  57. // return src_str.substr(0, tag.length + 1) + ' ' + attr + '=' + val + ' ' + src_str.substr(tag.length + 2, src_str.length);
  58. // }
  59. // },
  60. loadCkeditor: function(config){
  61. _self = this;
  62. COMMON.AjaxModule.loadDom("ckeditor", function(){
  63. CKEDITOR.disableAutoInline = true;
  64. var editorDiv = new Element("div").inject(this.node);
  65. var htmlData = this._getBusinessData();
  66. if (htmlData){
  67. editorDiv.set("html", htmlData);
  68. }else if (this.json.templateCode){
  69. editorDiv.set("html", this.json.templateCode);
  70. }
  71. var height = this.node.getSize().y;
  72. var editorConfig = config || {};
  73. if (this.form.json.mode=="Mobile"){
  74. if (!editorConfig.toolbar && !editorConfig.toolbarGroups){
  75. editorConfig.toolbar = [
  76. { name: 'paragraph', items: [ 'Bold', 'Italic', "-" , 'TextColor', "BGColor", 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', "-", 'Undo', 'Redo' ] },
  77. { name: 'basicstyles', items: [ 'Styles', 'FontSize']}
  78. ];
  79. }
  80. }
  81. // CKEDITOR.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/";
  82. // CKEDITOR.plugins.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/plugins/";
  83. //editorConfig.filebrowserCurrentDocumentImage = function( e, callback ){
  84. // _self.selectCurrentDocumentImage( e, callback );
  85. //};
  86. //editorConfig.filebrowserFilesImage = function( e, callback ){
  87. // _self.selectCloudFilesImage( e, callback );
  88. //};
  89. editorConfig.localImageMaxWidth = 800;
  90. editorConfig.reference = this.form.businessData.document.id;
  91. editorConfig.referenceType = "cmsDocument";
  92. if( editorConfig.skin )editorConfig.skin = "moono-lisa";
  93. this.editor = CKEDITOR.replace(editorDiv, editorConfig);
  94. this._loadEvents();
  95. //this.editor.on("loaded", function(){
  96. // this._loadEvents();
  97. //}.bind(this));
  98. //this.setData(data)
  99. this.editor.on("change", function(){
  100. this._setBusinessData(this.getData());
  101. }.bind(this));
  102. // this._loadEvents();
  103. }.bind(this));
  104. },
  105. getText : function(){
  106. return this.editor.document.getBody().getText();
  107. },
  108. getImages : function(){
  109. var result = [];
  110. var imgaes = this.editor.document.find("img");
  111. if( imgaes ){
  112. for( var i=0; i< imgaes.$.length; i++ ){
  113. result.push( imgaes.getItem(i).$ );
  114. }
  115. }
  116. return result;
  117. },
  118. getImageIds : function(){
  119. var result = [];
  120. var images = this.getImages();
  121. for( var i=0; i<images.length; i++ ){
  122. var img = images[i];
  123. if( img.getAttribute("data-id") ){
  124. result.push( img.getAttribute("data-id") )
  125. }
  126. }
  127. return result;
  128. },
  129. _loadStyles: function(){
  130. if (this.json.styles) this.node.setStyles(this.json.styles);
  131. this.node.setStyle("overflow","hidden");
  132. },
  133. //selectCurrentDocumentImage : function( e, callback ){
  134. // var _self = this;
  135. // MWF.xDesktop.requireApp("cms.Xform", "Attachment", function(){
  136. // //_self.form.app.content
  137. // _self.selector_doc = new MWF.xApplication.cms.Xform.Attachment( document.body , {}, _self.form, {})
  138. // _self.selector_doc.loadAttachmentSelecter({
  139. // "style" : "cms",
  140. // "title": "选择本文档图片",
  141. // "listStyle": "preview",
  142. // "toBase64" : true,
  143. // "selectType" : "images"
  144. // }, function(url, data, base64Code){
  145. // if(callback)callback(url, base64Code, data);
  146. // });
  147. //
  148. // }, true);
  149. //
  150. //},
  151. //selectCloudFilesImage : function( e, callback ){
  152. // var _self = this;
  153. // MWF.xDesktop.requireApp("File", "FileSelector", function(){
  154. // //_self.form.app.content
  155. // _self.selector_cloud = new MWF.xApplication.File.FileSelector( document.body ,{
  156. // "style" : "default",
  157. // "title": "选择云文件图片",
  158. // "toBase64" : true,
  159. // "listStyle": "preview",
  160. // "selectType" : "images",
  161. // "onPostSelectAttachment" : function(url, base64Code){
  162. // if(callback)callback(url, base64Code);
  163. // }
  164. // });
  165. // _self.selector_cloud.load();
  166. // }, true);
  167. //
  168. //},
  169. validationConfigItem: function(routeName, data){
  170. var flag = (data.status=="all") ? true: (routeName == "publish");
  171. if (flag){
  172. var n = this.getData();
  173. var v = (data.valueType=="value") ? n : n.length;
  174. switch (data.operateor){
  175. case "isnull":
  176. if (!v){
  177. this.notValidationMode(data.prompt);
  178. return false;
  179. }
  180. break;
  181. case "notnull":
  182. if (v){
  183. this.notValidationMode(data.prompt);
  184. return false;
  185. }
  186. break;
  187. case "gt":
  188. if (v>data.value){
  189. this.notValidationMode(data.prompt);
  190. return false;
  191. }
  192. break;
  193. case "lt":
  194. if (v<data.value){
  195. this.notValidationMode(data.prompt);
  196. return false;
  197. }
  198. break;
  199. case "equal":
  200. if (v==data.value){
  201. this.notValidationMode(data.prompt);
  202. return false;
  203. }
  204. break;
  205. case "neq":
  206. if (v!=data.value){
  207. this.notValidationMode(data.prompt);
  208. return false;
  209. }
  210. break;
  211. case "contain":
  212. if (v.indexOf(data.value)!=-1){
  213. this.notValidationMode(data.prompt);
  214. return false;
  215. }
  216. break;
  217. case "notcontain":
  218. if (v.indexOf(data.value)==-1){
  219. this.notValidationMode(data.prompt);
  220. return false;
  221. }
  222. break;
  223. }
  224. }
  225. return true;
  226. }
  227. });