o2config.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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|data-filename]',
  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. debugger;
  63. var id = json.data ? json.data.id : json.id;
  64. var src = MWF.xDesktop.getImageSrc( id );
  65. new Element("img", {
  66. src : src,
  67. events : {
  68. load : function (ev) {
  69. var width = ev.target.naturalWidth;
  70. var height = ev.target.naturalHeight;
  71. //按最大宽度比率缩小
  72. if( localImageMaxWidth && localImageMaxWidth < width ){
  73. height = parseInt( height * (localImageMaxWidth / width) );
  74. }
  75. width = Math.min(width, localImageMaxWidth);
  76. var attributes = {
  77. "data-id": id,
  78. "data-orgid": json.data ? json.data.origId : json.origId,
  79. "height": ''+height,
  80. "width": ''+width,
  81. "data-height": ''+height,
  82. "data-width": ''+width,
  83. "data-filename": file ? ( file.name||"" ) : '',
  84. "style": 'max-width:100%; width:' + width + 'px',
  85. "onerror": 'MWF.xDesktop.setImageSrc()',
  86. "alt": file ? ( file.name||"" ) : '',
  87. "data-prv": 'true' //enablePreview ? 'true' : 'false'
  88. };
  89. callback( src, attributes )
  90. }
  91. }
  92. });
  93. }.bind(this)
  94. });
  95. upload.load();
  96. }.bind(this));
  97. }
  98. }
  99. },
  100. init_instance_defaultCallback: function(editor) {
  101. var head_zindex = editor.getParam('head_zindex', 1);
  102. if(head_zindex !== 1 && editor.editorContainer && editor.editorContainer.getElementsByClassName){
  103. var list = editor.editorContainer.getElementsByClassName("tox-editor-header");
  104. if( list && list.length )list[0].setStyle("z-index", head_zindex);
  105. }
  106. editor.on("ObjectResized", function(ev){
  107. var element = ev.target;
  108. if(element.tagName && element.tagName.toUpperCase() === "IMG"){
  109. var replaceStyles = function(str, object){
  110. /*object 参数 {
  111. "width" : "100px", //添加或替换
  112. "height": "" //删除
  113. }*/
  114. var newArray = [];
  115. Object.each(object, function (value, key) {
  116. if(value)newArray.push( key + ":" + value )
  117. });
  118. var styles = str.split(/\s*;\s*/gi);
  119. for(var j=0; j<styles.length; j++){
  120. var arr = styles[j].split(/\s*:\s*/gi);
  121. if( !object.hasOwnProperty( arr[0].toLowerCase() ) ){
  122. newArray.push( styles[j] );
  123. }
  124. }
  125. return newArray.join(";");
  126. };
  127. var width = ev.width, style = element.getAttribute("style") || "";
  128. if(width && element.naturalHeight && element.naturalWidth){
  129. element.setAttribute("data-width", ''+width);
  130. element.setAttribute("style", replaceStyles(style, {"width" : width+"px"}));
  131. element.removeAttribute("width");
  132. var height = parseInt(width * ( element.naturalHeight / element.naturalWidth ));
  133. element.setAttribute("data-height", ''+height);
  134. element.removeAttribute("height");
  135. }
  136. }
  137. });
  138. }
  139. };
  140. if (o2.language === "zh-cn") {
  141. config.language = 'zh_CN';
  142. config.font_formats = '微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;' +
  143. '苹果苹方=PingFang SC,Microsoft YaHei,sans-serif;' +
  144. '宋体=simsun,serif;' +
  145. '仿宋体=FangSong,serif;' +
  146. '黑体=SimHei,sans-serif;' +
  147. 'Arial=arial,helvetica,sans-serif;' +
  148. 'Arial Black=arial black,avant garde;' +
  149. 'Book Antiqua=book antiqua,palatino;';
  150. }
  151. if( mobile ){
  152. config.mobile = {
  153. menubar : false,
  154. toolbar_mode : 'wrap'
  155. };
  156. config.menubar = false;
  157. config.head_zindex = 0;
  158. config.height = 450; //编辑器高度
  159. config.min_height = 200;
  160. config.toolbar_mode = 'wrap';
  161. config.imagetools_toolbar = 'editimage';
  162. config.plugins = 'visualchars o2image wordcount'; //autolink directionality visualblocks
  163. config.toolbar = 'forecolor backcolor bold italic |' + //restoredraft
  164. ' alignleft aligncenter alignright alignjustify |' + //\\'+
  165. ' styleselect fontsizeselect | o2image';
  166. }else{
  167. config.head_zindex = 0;
  168. config.height = 650; //编辑器高度
  169. config.min_height = 400;
  170. config.toolbar_mode = 'sliding';
  171. config.imagetools_toolbar = 'editimage imageoptions';
  172. config.plugins = 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen o2image link' +
  173. ' media template code codesample table charmap hr pagebreak nonbreaking anchor insertdatetime' +
  174. ' advlist lists wordcount o2imagetools textpattern help emoticons autosave' +
  175. ' o2indent2em o2upimgs'; //bdmap formatpainter autoresize
  176. config.toolbar = 'code undo redo | cut copy paste pastetext | forecolor backcolor bold italic underline strikethrough |' + //restoredraft
  177. ' alignleft aligncenter alignright alignjustify outdent indent o2indent2em lineheight | table o2image o2upimgs link |' + //\\'+
  178. ' styleselect formatselect fontselect fontsizeselect | bullist numlist | blockquote subscript superscript removeformat |' + // \\'+
  179. ' media charmap emoticons anchor hr pagebreak insertdatetime print preview | fullscreen'; //bdmap formatpainter
  180. }
  181. return config;
  182. }