bootstrap.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. window.UMEDITOR_HOME_URL = Config.__CDN__ + "/assets/addons/umeditor/";
  2. require.config({
  3. paths: {
  4. 'umeditor': '../addons/umeditor/umeditor',
  5. 'umeditor.config': '../addons/umeditor/umeditor.config',
  6. 'umeditor.lang': '../addons/umeditor/lang/zh-cn/zh-cn',
  7. },
  8. shim: {
  9. 'umeditor': {
  10. deps: [
  11. 'umeditor.config',
  12. 'css!../addons/umeditor/themes/default/css/umeditor.min.css'
  13. ],
  14. exports: 'UM',
  15. },
  16. 'umeditor.lang': ['umeditor']
  17. }
  18. });
  19. require(['form', 'upload'], function (Form, Upload) {
  20. //监听上传文本框的事件
  21. $(document).on("edui.file.change", ".edui-image-file", function (e, up, me, input, callback) {
  22. for (var i = 0; i < this.files.length; i++) {
  23. Upload.api.send(this.files[i], function (data) {
  24. var url = data.url;
  25. me.uploadComplete(JSON.stringify({url: url, state: "SUCCESS"}));
  26. });
  27. }
  28. up.updateInput(input);
  29. me.toggleMask("Loading....");
  30. callback && callback();
  31. });
  32. var _bindevent = Form.events.bindevent;
  33. Form.events.bindevent = function (form) {
  34. _bindevent.apply(this, [form]);
  35. require(['umeditor', 'umeditor.lang'], function (UME, undefined) {
  36. //重写编辑器加载
  37. UME.plugins['autoupload'] = function () {
  38. var me = this;
  39. me.setOpt('pasteImageEnabled', true);
  40. me.setOpt('dropFileEnabled', true);
  41. var sendAndInsertImage = function (file, editor) {
  42. try {
  43. Upload.api.send(file, function (data) {
  44. var url = Fast.api.cdnurl(data.url, true);
  45. editor.execCommand('insertimage', {
  46. src: url,
  47. _src: url
  48. });
  49. });
  50. } catch (er) {
  51. }
  52. };
  53. function getPasteImage(e) {
  54. return e.clipboardData && e.clipboardData.items && e.clipboardData.items.length == 1 && /^image\//.test(e.clipboardData.items[0].type) ? e.clipboardData.items : null;
  55. }
  56. function getDropImage(e) {
  57. return e.dataTransfer && e.dataTransfer.files ? e.dataTransfer.files : null;
  58. }
  59. me.addListener('ready', function () {
  60. if (window.FormData && window.FileReader) {
  61. var autoUploadHandler = function (e) {
  62. var hasImg = false,
  63. items;
  64. //获取粘贴板文件列表或者拖放文件列表
  65. items = e.type == 'paste' ? getPasteImage(e.originalEvent) : getDropImage(e.originalEvent);
  66. if (items) {
  67. var len = items.length,
  68. file;
  69. while (len--) {
  70. file = items[len];
  71. if (file.getAsFile)
  72. file = file.getAsFile();
  73. if (file && file.size > 0 && /image\/\w+/i.test(file.type)) {
  74. sendAndInsertImage(file, me);
  75. hasImg = true;
  76. }
  77. }
  78. if (hasImg)
  79. return false;
  80. }
  81. };
  82. me.getOpt('pasteImageEnabled') && me.$body.on('paste', autoUploadHandler);
  83. me.getOpt('dropFileEnabled') && me.$body.on('drop', autoUploadHandler);
  84. //取消拖放图片时出现的文字光标位置提示
  85. me.$body.on('dragover', function (e) {
  86. if (e.originalEvent.dataTransfer.types[0] == 'Files') {
  87. return false;
  88. }
  89. });
  90. }
  91. });
  92. };
  93. $(".editor", form).each(function () {
  94. var id = $(this).attr("id");
  95. $(this).removeClass('form-control');
  96. UME.list[id] = UME.getEditor(id, {
  97. serverUrl: Fast.api.fixurl('/addons/umeditor/api/'),
  98. initialFrameWidth: '100%',
  99. zIndex: 90,
  100. xssFilterRules: false,
  101. outputXssFilter: false,
  102. inputXssFilter: false,
  103. autoFloatEnabled: false,
  104. imageUrl: '',
  105. imagePath: Config.upload.cdnurl
  106. });
  107. });
  108. });
  109. }
  110. });