Htmleditor.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. { name: 'insert', items : [ 'Image' ] }
  79. ];
  80. }
  81. }
  82. // CKEDITOR.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/";
  83. // CKEDITOR.plugins.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/plugins/";
  84. //editorConfig.filebrowserCurrentDocumentImage = function( e, callback ){
  85. // _self.selectCurrentDocumentImage( e, callback );
  86. //};
  87. //editorConfig.filebrowserFilesImage = function( e, callback ){
  88. // _self.selectCloudFilesImage( e, callback );
  89. //};
  90. editorConfig.localImageMaxWidth = 800;
  91. editorConfig.reference = this.form.businessData.document.id;
  92. editorConfig.referenceType = "cmsDocument";
  93. if( editorConfig.skin )editorConfig.skin = "moono-lisa";
  94. this.editor = CKEDITOR.replace(editorDiv, editorConfig);
  95. this._loadEvents();
  96. //this.editor.on("loaded", function(){
  97. // this._loadEvents();
  98. //}.bind(this));
  99. //this.setData(data)
  100. this.editor.on("change", function(){
  101. this._setBusinessData(this.getData());
  102. }.bind(this));
  103. // this._loadEvents();
  104. }.bind(this));
  105. },
  106. getText : function(){
  107. return this.editor.document.getBody().getText();
  108. },
  109. getImages : function(){
  110. var result = [];
  111. var imgaes = this.editor.document.find("img");
  112. if( imgaes ){
  113. for( var i=0; i< imgaes.$.length; i++ ){
  114. result.push( imgaes.getItem(i).$ );
  115. }
  116. }
  117. return result;
  118. },
  119. getImageIds : function(){
  120. var result = [];
  121. var images = this.getImages();
  122. for( var i=0; i<images.length; i++ ){
  123. var img = images[i];
  124. if( img.getAttribute("data-id") ){
  125. result.push( img.getAttribute("data-id") )
  126. }
  127. }
  128. return result;
  129. },
  130. _loadStyles: function(){
  131. if (this.json.styles) this.node.setStyles(this.json.styles);
  132. this.node.setStyle("overflow","hidden");
  133. },
  134. //selectCurrentDocumentImage : function( e, callback ){
  135. // var _self = this;
  136. // MWF.xDesktop.requireApp("cms.Xform", "Attachment", function(){
  137. // //_self.form.app.content
  138. // _self.selector_doc = new MWF.xApplication.cms.Xform.Attachment( document.body , {}, _self.form, {})
  139. // _self.selector_doc.loadAttachmentSelecter({
  140. // "style" : "cms",
  141. // "title": "选择本文档图片",
  142. // "listStyle": "preview",
  143. // "toBase64" : true,
  144. // "selectType" : "images"
  145. // }, function(url, data, base64Code){
  146. // if(callback)callback(url, base64Code, data);
  147. // });
  148. //
  149. // }, true);
  150. //
  151. //},
  152. //selectCloudFilesImage : function( e, callback ){
  153. // var _self = this;
  154. // MWF.xDesktop.requireApp("File", "FileSelector", function(){
  155. // //_self.form.app.content
  156. // _self.selector_cloud = new MWF.xApplication.File.FileSelector( document.body ,{
  157. // "style" : "default",
  158. // "title": "选择云文件图片",
  159. // "toBase64" : true,
  160. // "listStyle": "preview",
  161. // "selectType" : "images",
  162. // "onPostSelectAttachment" : function(url, base64Code){
  163. // if(callback)callback(url, base64Code);
  164. // }
  165. // });
  166. // _self.selector_cloud.load();
  167. // }, true);
  168. //
  169. //},
  170. validationConfigItem: function(routeName, data){
  171. var flag = (data.status=="all") ? true: (routeName == "publish");
  172. if (flag){
  173. var n = this.getData();
  174. var v = (data.valueType=="value") ? n : n.length;
  175. switch (data.operateor){
  176. case "isnull":
  177. if (!v){
  178. this.notValidationMode(data.prompt);
  179. return false;
  180. }
  181. break;
  182. case "notnull":
  183. if (v){
  184. this.notValidationMode(data.prompt);
  185. return false;
  186. }
  187. break;
  188. case "gt":
  189. if (v>data.value){
  190. this.notValidationMode(data.prompt);
  191. return false;
  192. }
  193. break;
  194. case "lt":
  195. if (v<data.value){
  196. this.notValidationMode(data.prompt);
  197. return false;
  198. }
  199. break;
  200. case "equal":
  201. if (v==data.value){
  202. this.notValidationMode(data.prompt);
  203. return false;
  204. }
  205. break;
  206. case "neq":
  207. if (v!=data.value){
  208. this.notValidationMode(data.prompt);
  209. return false;
  210. }
  211. break;
  212. case "contain":
  213. if (v.indexOf(data.value)!=-1){
  214. this.notValidationMode(data.prompt);
  215. return false;
  216. }
  217. break;
  218. case "notcontain":
  219. if (v.indexOf(data.value)==-1){
  220. this.notValidationMode(data.prompt);
  221. return false;
  222. }
  223. break;
  224. }
  225. }
  226. return true;
  227. }
  228. });