o2config.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. o2.TinyMCEConfig = function ( mobile ) {
  2. debugger;
  3. if( typeof mobile !== "boolean" )mobile = layout.mobile;
  4. var config = {
  5. "branding": false,
  6. //skin:'oxide-dark',
  7. // language:'zh_CN',
  8. // toolbar_sticky: true,
  9. fontsize_formats: '12px 14px 16px 18px 24px 36px 48px 56px 72px',
  10. // importcss_append: true,
  11. autosave_ask_before_unload: false,
  12. //自定义文件选择器的回调内容
  13. image_advtab: true,
  14. file_picker_types: 'image', //file image media
  15. extended_valid_elements : 'img[class|src|border|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name'+
  16. '|style|data-id|data-orgid|data-height|data-width|onerror|data-prv]',
  17. file_picker_callback: function (callback, value, meta) {
  18. //this 指向editor实例
  19. if (meta.filetype === 'image') { //'file', 'media'
  20. if( this.activeO2ImageDialog && this.activeO2ImageDialog.getData().base64enable ) {
  21. var fileNode = new Element("input", {
  22. "type" : "file",
  23. "accept":"image/*",
  24. "styles" : {"display":"none"}
  25. });
  26. fileNode.addEvent("change", function(event){
  27. var file= fileNode.files[0];
  28. if(!/image\/\w+/.test(file.type)){ //判断获取的是否为图片文件
  29. MWF.xDesktop.notice('请选择图片格式文件',"error");
  30. return false;
  31. }
  32. var reader=new FileReader();
  33. reader.readAsDataURL(file);
  34. reader.onload = function(e){
  35. callback( this.result, {
  36. "style": 'max-width:100%;', //width:' + width + 'px',
  37. "alt": file.name || '',
  38. "data-prv": 'true' //enablePreview ? 'true' : 'false'
  39. })
  40. }
  41. }.bind( this ));
  42. fileNode.click();
  43. }else{
  44. var enablePreview = this.getParam('enablePreview', true);
  45. var localImageMaxWidth = this.getParam('localImageMaxWidth', 2000);
  46. var reference = this.getParam('reference');
  47. var referenceType = this.getParam('referenceType');
  48. if( !reference || !referenceType )return;
  49. MWF.require("MWF.widget.Upload", function () {
  50. var action = new MWF.xDesktop.Actions.RestActions("/xDesktop/Actions/action.json", "x_file_assemble_control");
  51. var upload = new MWF.widget.Upload($(document.body), {
  52. "data": null,
  53. "parameter": {
  54. "reference": reference,
  55. "referencetype": referenceType,
  56. "scale": localImageMaxWidth || 2000
  57. },
  58. "action": action,
  59. "method": "uploadImageByScale",
  60. "accept": "image/*",
  61. "onEvery": function (json, index, count, file) {
  62. var id = json.data ? json.data.id : json.id;
  63. var src = MWF.xDesktop.getImageSrc( id );
  64. new Element("img", {
  65. src : src,
  66. events : {
  67. load : function (ev) {
  68. var width = ev.target.naturalWidth;
  69. var height = ev.target.naturalHeight;
  70. //按最大宽度比率缩小
  71. if( localImageMaxWidth && localImageMaxWidth < width ){
  72. height = parseInt( height * (localImageMaxWidth / width) );
  73. }
  74. width = Math.min(width, localImageMaxWidth);
  75. var attributes = {
  76. "data-id": id,
  77. "data-orgid": json.data ? json.data.origId : json.origId,
  78. "height": ''+height,
  79. "width": ''+width,
  80. "data-height": ''+height,
  81. "data-width": ''+width,
  82. "style": 'max-width:100%; width:' + width + 'px',
  83. "onerror": 'MWF.xDesktop.setImageSrc()',
  84. "alt": file ? ( file.name||"" ) : '',
  85. "data-prv": 'true' //enablePreview ? 'true' : 'false'
  86. };
  87. callback( src, attributes )
  88. }
  89. }
  90. });
  91. }.bind(this)
  92. });
  93. upload.load();
  94. }.bind(this));
  95. }
  96. }
  97. },
  98. init_instance_defaultCallback: function(editor) {
  99. var head_zindex = editor.getParam('head_zindex', 1);
  100. if(head_zindex !== 1 && editor.editorContainer && editor.editorContainer.getElementsByClassName){
  101. var list = editor.editorContainer.getElementsByClassName("tox-editor-header");
  102. if( list && list.length )list[0].setStyle("z-index", head_zindex);
  103. }
  104. editor.on("ObjectResized", function(ev){
  105. var element = ev.target;
  106. if(element.tagName && element.tagName.toUpperCase() === "IMG"){
  107. var replaceStyles = function(str, object){
  108. /*object 参数 {
  109. "width" : "100px", //添加或替换
  110. "height": "" //删除
  111. }*/
  112. var newArray = [];
  113. Object.each(object, function (value, key) {
  114. if(value)newArray.push( key + ":" + value )
  115. });
  116. var styles = str.split(/\s*;\s*/gi);
  117. for(var j=0; j<styles.length; j++){
  118. var arr = styles[j].split(/\s*:\s*/gi);
  119. if( !object.hasOwnProperty( arr[0].toLowerCase() ) ){
  120. newArray.push( styles[j] );
  121. }
  122. }
  123. return newArray.join(";");
  124. };
  125. var width = ev.width, style = element.getAttribute("style") || "";
  126. if(width && element.naturalHeight && element.naturalWidth){
  127. element.setAttribute("data-width", ''+width);
  128. element.setAttribute("style", replaceStyles(style, {"width" : width+"px"}));
  129. element.removeAttribute("width");
  130. var height = parseInt(width * ( element.naturalHeight / element.naturalWidth ));
  131. element.setAttribute("data-height", ''+height);
  132. element.removeAttribute("height");
  133. }
  134. }
  135. });
  136. }
  137. };
  138. if (o2.language === "zh-cn") {
  139. config.language = 'zh_CN';
  140. config.font_formats = '微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;' +
  141. '苹果苹方=PingFang SC,Microsoft YaHei,sans-serif;' +
  142. '宋体=simsun,serif;' +
  143. '仿宋体=FangSong,serif;' +
  144. '黑体=SimHei,sans-serif;' +
  145. 'Arial=arial,helvetica,sans-serif;' +
  146. 'Arial Black=arial black,avant garde;' +
  147. 'Book Antiqua=book antiqua,palatino;';
  148. }
  149. if( mobile ){
  150. config.mobile = {
  151. menubar : false,
  152. toolbar_mode : 'wrap'
  153. };
  154. config.menubar = false;
  155. config.head_zindex = 0;
  156. config.height = 450; //编辑器高度
  157. config.min_height = 200;
  158. config.toolbar_mode = 'wrap';
  159. config.imagetools_toolbar = 'editimage';
  160. config.plugins = 'visualchars o2image wordcount'; //autolink directionality visualblocks
  161. config.toolbar = 'forecolor backcolor bold italic |' + //restoredraft
  162. ' alignleft aligncenter alignright alignjustify |' + //\\'+
  163. ' styleselect fontsizeselect | o2image';
  164. }else{
  165. config.head_zindex = 0;
  166. config.height = 650; //编辑器高度
  167. config.min_height = 400;
  168. config.toolbar_mode = 'sliding';
  169. config.imagetools_toolbar = 'editimage imageoptions';
  170. config.plugins = 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen o2image link' +
  171. ' media template code codesample table charmap hr pagebreak nonbreaking anchor insertdatetime' +
  172. ' advlist lists wordcount o2imagetools textpattern help emoticons autosave' +
  173. ' o2indent2em o2upimgs'; //bdmap formatpainter autoresize
  174. config.toolbar = 'code undo redo | cut copy paste pastetext | forecolor backcolor bold italic underline strikethrough |' + //restoredraft
  175. ' alignleft aligncenter alignright alignjustify outdent indent o2indent2em lineheight | table o2image o2upimgs link |' + //\\'+
  176. ' styleselect formatselect fontselect fontsizeselect | bullist numlist | blockquote subscript superscript removeformat |' + // \\'+
  177. ' media charmap emoticons anchor hr pagebreak insertdatetime print preview | fullscreen'; //bdmap formatpainter
  178. }
  179. return config;
  180. }