bootstrap.js 5.5 KB

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