addons.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. define([], function () {
  2. require.config({
  3. paths: {
  4. 'easymde': '../addons/easymde/easymde.min',
  5. },
  6. shim: {
  7. 'easymde': ['css!../addons/easymde/css/easymde.min.css','css!../addons/easymde/css/font-awesome.min.css']
  8. }
  9. });
  10. require(['form', 'upload'], function(Form, Upload) {
  11. var _bindevent = Form.events.bindevent;
  12. Form.events.bindevent = function(form) {
  13. _bindevent.apply(this, [form]);
  14. try {
  15. if ($('.markdown', form).length > 0) {
  16. require(['easymde'], function(EasyMDE) {
  17. var insert = function(e, url, type) {
  18. var urlArr = url.split(/\,/);
  19. $.each(urlArr, function() {
  20. var url = Yzn.api.cdnurl(this, true);
  21. if (type && type == 'image') {
  22. e.codemirror.replaceSelection("\n" + '![输入图片说明](' + url + ')');
  23. } else {
  24. e.codemirror.replaceSelection("\n" + '[输入链接说明](' + url + ')');
  25. }
  26. });
  27. };
  28. var easymdes = {};
  29. $('.markdown', form).each(function() {
  30. var that = this;
  31. var id = $(that).attr('id');
  32. var easyMDE = new EasyMDE({
  33. element: that,
  34. promptURLs: true,
  35. autoDownloadFontAwesome:false,
  36. promptTexts: {
  37. link: "URL地址:",
  38. },
  39. forceSync: true,
  40. toolbar: [
  41. "bold", "strikethrough", "italic", "heading", "heading-2", "heading-3", "|",
  42. "code", "quote", "|",
  43. "unordered-list", "ordered-list", "table", "|",
  44. "link", "upload-image", "|", "preview", "side-by-side", "fullscreen", "|",
  45. "guide"
  46. ],
  47. lineNumbers: true,
  48. uploadImage: true,
  49. status: false,
  50. imageUploadFunction: (file, onSuccess, onError) => {
  51. Upload.api.send(file, function(data) {
  52. url = Yzn.api.cdnurl(data.url, true);
  53. if (file.type.indexOf("image") !== -1) {
  54. insert(easyMDE, url, 'image');
  55. } else {
  56. insert(easyMDE, url, 'file');
  57. }
  58. })
  59. }
  60. });
  61. /*easyMDE.codemirror.on("change", () => {
  62. $(that).val(easyMDE.value());
  63. });*/
  64. easymdes[id] = easyMDE;
  65. })
  66. })
  67. }
  68. } catch (e) {}
  69. }
  70. })
  71. //ueditor.config.js,编辑器所在的目录
  72. window.UEDITOR_HOME_URL = Config.__CDN__ + "/assets/addons/ueditor/";
  73. require.config({
  74. paths: {
  75. 'ueditor.config': '../addons/ueditor/ueditor.config',
  76. 'ueditor': '../addons/ueditor/ueditor.all',
  77. 'zeroclipboard': '../addons/ueditor/third-party/zeroclipboard/ZeroClipboard',
  78. },
  79. shim: {
  80. 'ueditor': {
  81. //注意:此处的依赖顺序不能颠倒
  82. deps: ['zeroclipboard', 'ueditor.config'],
  83. exports: 'UE',
  84. init: function(ZeroClipboard) {
  85. //导出到全局变量,供ueditor使用
  86. window.ZeroClipboard = ZeroClipboard;
  87. },
  88. }
  89. }
  90. });
  91. require(['form', 'upload'], function(Form, Upload) {
  92. var _bindevent = Form.events.bindevent;
  93. Form.events.bindevent = function(form) {
  94. _bindevent.apply(this, [form]);
  95. try {
  96. //绑定editor事件
  97. if ($('.editor', form).length > 0) {
  98. require(['ueditor'], function(UE, undefined) {
  99. UE.list = [];
  100. $('.editor', form).each(function() {
  101. var id = $(this).attr("id");
  102. var name = $(this).attr("name");
  103. $(this).removeClass('layui-textarea');
  104. var simple_mode = Yzn.api.parame($(this).data('simple-mode'), false);
  105. var config = {
  106. serverUrl: Yzn.api.fixurl('/addons/ueditor/api/index'),
  107. allowDivTransToP: false, //转换p标签
  108. initialFrameWidth: '100%',
  109. initialFrameHeight: 400, //初始化编辑器高度,默认320
  110. maximumWords: 50000, //允许的最大字符数
  111. }
  112. if (simple_mode) {
  113. // 如果是精简模式,设置精简的工具栏按钮
  114. config.toolbars = [
  115. ['fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'pasteplain', '|',
  116. 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', '|', 'paragraph', 'fontfamily', 'fontsize', '|',
  117. 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', '|', 'simpleupload', 'insertimage', 'insertvideo',
  118. 'attachment', 'insertframe', 'pagebreak', '|', 'horizontal', 'inserttable', '|', 'preview'
  119. ]
  120. ];
  121. }
  122. UE.list[id] = UE.getEditor(id, config);
  123. UE.list[id].addListener("contentChange", function () {
  124. $('#' + id).val(this.getContent());
  125. $('textarea[name="' + name + '"]').val(this.getContent());
  126. })
  127. //打开图片管理
  128. UE.list[id].addListener("upload.online", function(e, editor, dialog) {
  129. dialog.close(false);
  130. Yzn.api.open("general.attachments/select?element_id=&multiple=true&mimetype=image/*", "选择", {
  131. callback: function(data) {
  132. var urlArr = data.url.split(/\,/);
  133. urlArr.forEach(function(item, index) {
  134. var url = Yzn.api.cdnurl(item);
  135. editor.execCommand('insertimage', {
  136. src: url
  137. });
  138. });
  139. }
  140. });
  141. });
  142. //打开附件管理
  143. UE.list[id].addListener("file.online", function(e, editor, dialog) {
  144. dialog.close(false);
  145. Yzn.api.open("general.attachments/select?element_id=&multiple=true&mimetype=application/*", "选择", {
  146. callback: function(data) {
  147. var urlArr = data.url.split(/\,/);
  148. urlArr.forEach(function(item, index) {
  149. var url = Yzn.api.cdnurl(item);
  150. editor.execCommand('insertfile', {
  151. url: url
  152. });
  153. });
  154. }
  155. });
  156. });
  157. });
  158. })
  159. }
  160. } catch (e) {}
  161. }
  162. });
  163. });