Htmleditor.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. //
  34. // this.loadCkeditor(config);
  35. // }
  36. // },
  37. // parseImage : function( html ){
  38. // html = ( html || "" ).replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (img, capture) {
  39. // if( img.indexOf( "data-id" ) > -1 && img.indexOf("setImageSrc()") > -1 ){
  40. // var ids = img.match( /(?<=data-id=").*?(?=")/g );
  41. // if( ids && ids.length > 0 ){
  42. // var newSrc = MWF.xDesktop.getImageSrc( ids[0] );
  43. // var newImg = this.replaceAttr( img, "img", "src", newSrc );
  44. // return newImg;
  45. // }
  46. // }
  47. // return img;
  48. // }.bind(this));
  49. // return html
  50. // },
  51. // replaceAttr: function(src_str, tag, attr, val) {
  52. // if(src_str.indexOf(attr) > 0) {
  53. // //包含attr属性,替换attr
  54. // var sub_reg = new RegExp(attr + '=[\'\"]([^"]*)[\'\"]', 'gi');
  55. // return src_str.replace(sub_reg, attr +'=' + val);
  56. // }else{
  57. // //不包含attr属性,添加attr
  58. // return src_str.substr(0, tag.length + 1) + ' ' + attr + '=' + val + ' ' + src_str.substr(tag.length + 2, src_str.length);
  59. // }
  60. // },
  61. loadCkeditor: function (config) {
  62. _self = this;
  63. // o2.load("../o2_lib/htmleditor/ckeditor4-major/ckeditor.js", function(){
  64. COMMON.AjaxModule.loadDom("ckeditor", function () {
  65. CKEDITOR.disableAutoInline = true;
  66. var editorDiv = new Element("div").inject(this.node);
  67. var htmlData = this._getBusinessData();
  68. if (htmlData) {
  69. editorDiv.set("html", htmlData);
  70. } else if (this.json.templateCode) {
  71. editorDiv.set("html", this.json.templateCode);
  72. }
  73. var height = this.node.getSize().y;
  74. var editorConfig = config || {};
  75. if (this.form.json.mode == "Mobile") {
  76. if (!editorConfig.toolbar && !editorConfig.toolbarGroups) {
  77. editorConfig.toolbar = [
  78. {
  79. name: 'paragraph',
  80. items: ['Bold', 'Italic', "-", 'TextColor', "BGColor", 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', "-", 'Undo', 'Redo']
  81. },
  82. {name: 'basicstyles', items: ['Styles', 'FontSize']},
  83. {name: 'insert', items: ['Image']}
  84. ];
  85. }
  86. }
  87. // CKEDITOR.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/";
  88. // CKEDITOR.plugins.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/plugins/";
  89. //editorConfig.filebrowserCurrentDocumentImage = function( e, callback ){
  90. // _self.selectCurrentDocumentImage( e, callback );
  91. //};
  92. //editorConfig.filebrowserFilesImage = function( e, callback ){
  93. // _self.selectCloudFilesImage( e, callback );
  94. //};
  95. editorConfig.base64Encode = (this.json.base64Encode === "y");
  96. editorConfig.enablePreview = (this.json.enablePreview !== "n");
  97. editorConfig.localImageMaxWidth = 2000;
  98. editorConfig.reference = this.form.businessData.document.id;
  99. editorConfig.referenceType = "cmsDocument";
  100. if (editorConfig && editorConfig.extraPlugins) {
  101. var extraPlugins = editorConfig.extraPlugins;
  102. extraPlugins = typeOf(extraPlugins) === "array" ? extraPlugins : extraPlugins.split(",");
  103. extraPlugins.push( 'lineheight' );
  104. extraPlugins.push('o2image');
  105. extraPlugins.push('o2uploadimage');
  106. extraPlugins.push('o2uploadremoteimage');
  107. editorConfig.extraPlugins = extraPlugins;
  108. } else {
  109. editorConfig.extraPlugins = ['lineheight','o2image', 'o2uploadimage', 'o2uploadremoteimage'];
  110. }
  111. if (editorConfig && editorConfig.removePlugins) {
  112. var removePlugins = editorConfig.removePlugins;
  113. removePlugins = typeOf(removePlugins) === "array" ? removePlugins : removePlugins.split(",");
  114. editorConfig.removePlugins = removePlugins.concat(['image', 'easyimage', 'exportpdf', 'cloudservices']);
  115. } else {
  116. editorConfig.removePlugins = ['image', 'easyimage', 'exportpdf', 'cloudservices'];
  117. }
  118. if (!editorConfig.language) editorConfig.language = MWF.language;
  119. if (editorConfig.skin) editorConfig.skin = "moono-lisa";
  120. this.editor = CKEDITOR.replace(editorDiv, editorConfig);
  121. this._loadEvents();
  122. //this.editor.on("loaded", function(){
  123. // this._loadEvents();
  124. //}.bind(this));
  125. //this.setData(data)
  126. this.editor.on("change", function () {
  127. this._setBusinessData(this.getData());
  128. }.bind(this));
  129. // this._loadEvents();
  130. }.bind(this));
  131. },
  132. getText: function () {
  133. return (this.editor && this.editor.document) ? this.editor.document.getBody().getText() : this.node.get("text");
  134. },
  135. getImages: function () {
  136. var result = [];
  137. if( this.editor && this.editor.document ){
  138. var images = this.editor.document.find("img");
  139. if (images) {
  140. for (var i = 0; i < images.$.length; i++) {
  141. result.push(images.getItem(i).$);
  142. }
  143. }
  144. return result;
  145. }else{
  146. return this.node.getElements("img");
  147. }
  148. },
  149. getImageIds: function () {
  150. var result = [];
  151. var images = this.getImages();
  152. for (var i = 0; i < images.length; i++) {
  153. var img = images[i];
  154. if (img.getAttribute("data-id")) {
  155. result.push(img.getAttribute("data-id"))
  156. }
  157. }
  158. return result;
  159. },
  160. _loadStyles: function () {
  161. if (this.json.styles) this.node.setStyles(this.json.styles);
  162. this.node.setStyle("overflow", "hidden");
  163. },
  164. //selectCurrentDocumentImage : function( e, callback ){
  165. // var _self = this;
  166. // MWF.xDesktop.requireApp("cms.Xform", "Attachment", function(){
  167. // //_self.form.app.content
  168. // _self.selector_doc = new MWF.xApplication.cms.Xform.Attachment( document.body , {}, _self.form, {})
  169. // _self.selector_doc.loadAttachmentSelecter({
  170. // "style" : "cms",
  171. // "title": "选择本文档图片",
  172. // "listStyle": "preview",
  173. // "toBase64" : true,
  174. // "selectType" : "images"
  175. // }, function(url, data, base64Code){
  176. // if(callback)callback(url, base64Code, data);
  177. // });
  178. //
  179. // }, true);
  180. //
  181. //},
  182. //selectCloudFilesImage : function( e, callback ){
  183. // var _self = this;
  184. // MWF.xDesktop.requireApp("File", "FileSelector", function(){
  185. // //_self.form.app.content
  186. // _self.selector_cloud = new MWF.xApplication.File.FileSelector( document.body ,{
  187. // "style" : "default",
  188. // "title": "选择云文件图片",
  189. // "toBase64" : true,
  190. // "listStyle": "preview",
  191. // "selectType" : "images",
  192. // "onPostSelectAttachment" : function(url, base64Code){
  193. // if(callback)callback(url, base64Code);
  194. // }
  195. // });
  196. // _self.selector_cloud.load();
  197. // }, true);
  198. //
  199. //},
  200. validationConfigItem: function (routeName, data) {
  201. var flag = (data.status == "all") ? true : (routeName == "publish");
  202. if (flag) {
  203. var n = this.getData();
  204. var v = (data.valueType == "value") ? n : n.length;
  205. switch (data.operateor) {
  206. case "isnull":
  207. if (!v) {
  208. this.notValidationMode(data.prompt);
  209. return false;
  210. }
  211. break;
  212. case "notnull":
  213. if (v) {
  214. this.notValidationMode(data.prompt);
  215. return false;
  216. }
  217. break;
  218. case "gt":
  219. if (v > data.value) {
  220. this.notValidationMode(data.prompt);
  221. return false;
  222. }
  223. break;
  224. case "lt":
  225. if (v < data.value) {
  226. this.notValidationMode(data.prompt);
  227. return false;
  228. }
  229. break;
  230. case "equal":
  231. if (v == data.value) {
  232. this.notValidationMode(data.prompt);
  233. return false;
  234. }
  235. break;
  236. case "neq":
  237. if (v != data.value) {
  238. this.notValidationMode(data.prompt);
  239. return false;
  240. }
  241. break;
  242. case "contain":
  243. if (v.indexOf(data.value) != -1) {
  244. this.notValidationMode(data.prompt);
  245. return false;
  246. }
  247. break;
  248. case "notcontain":
  249. if (v.indexOf(data.value) == -1) {
  250. this.notValidationMode(data.prompt);
  251. return false;
  252. }
  253. break;
  254. }
  255. }
  256. return true;
  257. }
  258. });