addons.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. define([], function () {
  2. require.config({
  3. paths: {
  4. 'summernote': '../addons/summernote/lang/summernote-zh-CN.min'
  5. },
  6. shim: {
  7. 'summernote': ['../addons/summernote/js/summernote.min', 'css!../addons/summernote/css/summernote.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. //绑定summernote事件
  16. if ($(".summernote,.editor", form).size() > 0) {
  17. require(['summernote'], function () {
  18. var imageButton = function (context) {
  19. var ui = $.summernote.ui;
  20. var button = ui.button({
  21. contents: '<i class="fa fa-file-image-o"/>',
  22. tooltip: __('Choose'),
  23. click: function () {
  24. parent.Fast.api.open("general/attachment/select?element_id=&multiple=true&mimetype=image/*", __('Choose'), {
  25. callback: function (data) {
  26. var urlArr = data.url.split(/\,/);
  27. $.each(urlArr, function () {
  28. var url = Fast.api.cdnurl(this);
  29. context.invoke('editor.insertImage', url);
  30. });
  31. }
  32. });
  33. return false;
  34. }
  35. });
  36. return button.render();
  37. };
  38. var attachmentButton = function (context) {
  39. var ui = $.summernote.ui;
  40. var button = ui.button({
  41. contents: '<i class="fa fa-file"/>',
  42. tooltip: __('Choose'),
  43. click: function () {
  44. parent.Fast.api.open("general/attachment/select?element_id=&multiple=true&mimetype=*", __('Choose'), {
  45. callback: function (data) {
  46. var urlArr = data.url.split(/\,/);
  47. $.each(urlArr, function () {
  48. var url = Fast.api.cdnurl(this);
  49. var node = $("<a href='" + url + "'>" + url + "</a>");
  50. context.invoke('insertNode', node[0]);
  51. });
  52. }
  53. });
  54. return false;
  55. }
  56. });
  57. return button.render();
  58. };
  59. $(".summernote,.editor", form).summernote({
  60. height: 250,
  61. lang: 'zh-CN',
  62. fontNames: [
  63. 'Arial', 'Arial Black', 'Serif', 'Sans', 'Courier',
  64. 'Courier New', 'Comic Sans MS', 'Helvetica', 'Impact', 'Lucida Grande',
  65. "Open Sans", "Hiragino Sans GB", "Microsoft YaHei",
  66. '微软雅黑', '宋体', '黑体', '仿宋', '楷体', '幼圆',
  67. ],
  68. fontNamesIgnoreCheck: [
  69. "Open Sans", "Microsoft YaHei",
  70. '微软雅黑', '宋体', '黑体', '仿宋', '楷体', '幼圆'
  71. ],
  72. toolbar: [
  73. ['style', ['style', 'undo', 'redo']],
  74. ['font', ['bold', 'underline', 'strikethrough', 'clear']],
  75. ['fontname', ['color', 'fontname', 'fontsize']],
  76. ['para', ['ul', 'ol', 'paragraph', 'height']],
  77. ['table', ['table', 'hr']],
  78. ['insert', ['link', 'picture', 'video']],
  79. ['select', ['image', 'attachment']],
  80. ['view', ['fullscreen', 'codeview', 'help']],
  81. ],
  82. buttons: {
  83. image: imageButton,
  84. attachment: attachmentButton,
  85. },
  86. dialogsInBody: true,
  87. followingToolbar: false,
  88. callbacks: {
  89. onChange: function (contents) {
  90. $(this).val(contents);
  91. $(this).trigger('change');
  92. },
  93. onInit: function () {
  94. },
  95. onImageUpload: function (files) {
  96. var that = this;
  97. //依次上传图片
  98. for (var i = 0; i < files.length; i++) {
  99. Upload.api.send(files[i], function (data) {
  100. var url = Fast.api.cdnurl(data.url);
  101. $(that).summernote("insertImage", url, 'filename');
  102. });
  103. }
  104. }
  105. }
  106. });
  107. });
  108. }
  109. } catch (e) {
  110. }
  111. };
  112. });
  113. });