addons.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. define([], function () {
  2. if (Config.modulename == 'admin' && Config.controllername == 'index' && Config.actionname == 'index') {
  3. require.config({
  4. paths: {
  5. 'fastchat': '../addons/fastchat/js/fastchat'
  6. },
  7. shim: {
  8. 'fastchat': {
  9. deps: ['css!../addons/fastchat/css/fastchat.css'],
  10. exports: 'FastChat'
  11. }
  12. }
  13. });
  14. require(['fastchat'], function (FastChat) {
  15. FastChat.initialize(document.domain, 'admin');
  16. });
  17. } else {
  18. if (window.parent.Config && window.parent.Config.modulename == 'admin') {
  19. window.FastChat = window.parent.FastChat;
  20. // 一键添加会话窗口
  21. $(document).on('click', '.fastchat_user', function (e) {
  22. FastChat.forecast_add_session(e);
  23. });
  24. } else {
  25. require.config({
  26. paths: {
  27. 'fastchat': '../addons/fastchat/js/fastchat'
  28. },
  29. shim: {
  30. 'fastchat': {
  31. deps: ['css!../addons/fastchat/css/fastchat.css'],
  32. exports: 'FastChat'
  33. }
  34. }
  35. });
  36. require(['fastchat'], function (FastChat) {
  37. FastChat.initialize(document.domain, window.parent.Config.modulename);
  38. });
  39. }
  40. }
  41. require.config({
  42. paths: {
  43. 'summernote': '../addons/summernote/lang/summernote-zh-CN.min'
  44. },
  45. shim: {
  46. 'summernote': ['../addons/summernote/js/summernote.min', 'css!../addons/summernote/css/summernote.min.css'],
  47. }
  48. });
  49. require(['form', 'upload'], function (Form, Upload) {
  50. var _bindevent = Form.events.bindevent;
  51. Form.events.bindevent = function (form) {
  52. _bindevent.apply(this, [form]);
  53. try {
  54. //绑定summernote事件
  55. if ($(Config.summernote.classname || '.editor', form).length > 0) {
  56. var selectUrl = typeof Config !== 'undefined' && Config.modulename === 'index' ? 'user/attachment' : 'general/attachment/select';
  57. require(['summernote'], function () {
  58. var imageButton = function (context) {
  59. var ui = $.summernote.ui;
  60. var button = ui.button({
  61. contents: '<i class="fa fa-file-image-o"/>',
  62. tooltip: __('Choose'),
  63. click: function () {
  64. parent.Fast.api.open(selectUrl + "?element_id=&multiple=true&mimetype=image/", __('Choose'), {
  65. callback: function (data) {
  66. var urlArr = data.url.split(/\,/);
  67. $.each(urlArr, function () {
  68. var url = Fast.api.cdnurl(this, true);
  69. context.invoke('editor.insertImage', url);
  70. });
  71. }
  72. });
  73. return false;
  74. }
  75. });
  76. return button.render();
  77. };
  78. var attachmentButton = function (context) {
  79. var ui = $.summernote.ui;
  80. var button = ui.button({
  81. contents: '<i class="fa fa-file"/>',
  82. tooltip: __('Choose'),
  83. click: function () {
  84. parent.Fast.api.open(selectUrl + "?element_id=&multiple=true&mimetype=*", __('Choose'), {
  85. callback: function (data) {
  86. var urlArr = data.url.split(/\,/);
  87. $.each(urlArr, function () {
  88. var url = Fast.api.cdnurl(this, true);
  89. var node = $("<a href='" + url + "'>" + url + "</a>");
  90. context.invoke('insertNode', node[0]);
  91. });
  92. }
  93. });
  94. return false;
  95. }
  96. });
  97. return button.render();
  98. };
  99. $(Config.summernote.classname || '.editor', form).each(function () {
  100. $(this).summernote($.extend(true, {}, {
  101. height: isNaN(Config.summernote.height) ? null : parseInt(Config.summernote.height),
  102. minHeight: parseInt(Config.summernote.minHeight || 250),
  103. toolbar: Config.summernote.toolbar,
  104. followingToolbar: parseInt(Config.summernote.followingToolbar),
  105. placeholder: Config.summernote.placeholder || '',
  106. airMode: parseInt(Config.summernote.airMode) || false,
  107. lang: 'zh-CN',
  108. fontNames: [
  109. 'Arial', 'Arial Black', 'Serif', 'Sans', 'Courier',
  110. 'Courier New', 'Comic Sans MS', 'Helvetica', 'Impact', 'Lucida Grande',
  111. "Open Sans", "Hiragino Sans GB", "Microsoft YaHei",
  112. '微软雅黑', '宋体', '黑体', '仿宋', '楷体', '幼圆',
  113. ],
  114. fontNamesIgnoreCheck: [
  115. "Open Sans", "Microsoft YaHei",
  116. '微软雅黑', '宋体', '黑体', '仿宋', '楷体', '幼圆'
  117. ],
  118. buttons: {
  119. image: imageButton,
  120. attachment: attachmentButton,
  121. },
  122. dialogsInBody: true,
  123. callbacks: {
  124. onChange: function (contents) {
  125. $(this).val(contents);
  126. $(this).trigger('change');
  127. },
  128. onInit: function () {
  129. },
  130. onImageUpload: function (files) {
  131. var that = this;
  132. //依次上传图片
  133. for (var i = 0; i < files.length; i++) {
  134. Upload.api.send(files[i], function (data) {
  135. var url = Fast.api.cdnurl(data.url, true);
  136. $(that).summernote("insertImage", url, 'filename');
  137. });
  138. }
  139. }
  140. }
  141. }, $(this).data("summernote-options") || {}));
  142. });
  143. });
  144. }
  145. } catch (e) {
  146. }
  147. };
  148. });
  149. });