bootstrap.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.min.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 ($(Config.summernote.classname || '.editor', form).length > 0) {
  16. var selectUrl = typeof Config !== 'undefined' && Config.modulename === 'index' ? 'user/attachment' : 'general/attachment/select';
  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(selectUrl + "?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, true);
  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(selectUrl + "?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, true);
  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. $(Config.summernote.classname || '.editor', form).each(function () {
  60. $(this).summernote($.extend(true, {}, {
  61. height: 250,
  62. lang: 'zh-CN',
  63. fontNames: [
  64. 'Arial', 'Arial Black', 'Serif', 'Sans', 'Courier',
  65. 'Courier New', 'Comic Sans MS', 'Helvetica', 'Impact', 'Lucida Grande',
  66. "Open Sans", "Hiragino Sans GB", "Microsoft YaHei",
  67. '微软雅黑', '宋体', '黑体', '仿宋', '楷体', '幼圆',
  68. ],
  69. fontNamesIgnoreCheck: [
  70. "Open Sans", "Microsoft YaHei",
  71. '微软雅黑', '宋体', '黑体', '仿宋', '楷体', '幼圆'
  72. ],
  73. toolbar: [
  74. ['style', ['style', 'undo', 'redo']],
  75. ['font', ['bold', 'underline', 'strikethrough', 'clear']],
  76. ['fontname', ['color', 'fontname', 'fontsize']],
  77. ['para', ['ul', 'ol', 'paragraph', 'height']],
  78. ['table', ['table', 'hr']],
  79. ['insert', ['link', 'picture', 'video']],
  80. ['select', ['image', 'attachment']],
  81. ['view', ['fullscreen', 'codeview', 'help']],
  82. ],
  83. buttons: {
  84. image: imageButton,
  85. attachment: attachmentButton,
  86. },
  87. dialogsInBody: true,
  88. followingToolbar: false,
  89. callbacks: {
  90. onChange: function (contents) {
  91. $(this).val(contents);
  92. $(this).trigger('change');
  93. },
  94. onInit: function () {
  95. },
  96. onImageUpload: function (files) {
  97. var that = this;
  98. //依次上传图片
  99. for (var i = 0; i < files.length; i++) {
  100. Upload.api.send(files[i], function (data) {
  101. var url = Fast.api.cdnurl(data.url, true);
  102. $(that).summernote("insertImage", url, 'filename');
  103. });
  104. }
  105. }
  106. }
  107. }, $(this).data("summernote-options") || {}));
  108. });
  109. });
  110. }
  111. } catch (e) {
  112. }
  113. };
  114. });