addons.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. define([], function () {
  2. require.config({
  3. paths: {
  4. 'simditor': '../addons/simditor/js/simditor.min',
  5. },
  6. shim: {
  7. 'simditor': [
  8. 'css!../addons/simditor/css/simditor.min.css',
  9. ]
  10. }
  11. });
  12. require(['form'], function (Form) {
  13. var _bindevent = Form.events.bindevent;
  14. Form.events.bindevent = function (form) {
  15. _bindevent.apply(this, [form]);
  16. if ($(Config.simditor.classname || '.editor', form).size() > 0) {
  17. //修改上传的接口调用
  18. require(['upload', 'simditor'], function (Upload, Simditor) {
  19. var editor, mobileToolbar, toolbar;
  20. Simditor.locale = 'zh-CN';
  21. Simditor.list = {};
  22. toolbar = ['title', 'bold', 'italic', 'underline', 'strikethrough', 'fontScale', 'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link', 'image', 'hr', '|', 'indent', 'outdent', 'alignment'];
  23. mobileToolbar = ["bold", "underline", "strikethrough", "color", "ul", "ol"];
  24. $(Config.simditor.classname || '.editor', form).each(function () {
  25. var id = $(this).attr("id");
  26. editor = new Simditor({
  27. textarea: this,
  28. toolbarFloat: false,
  29. toolbar: toolbar,
  30. pasteImage: true,
  31. defaultImage: Config.__CDN__ + '/assets/addons/simditor/images/image.png',
  32. upload: {url: '/'},
  33. allowedTags: ['div', 'br', 'span', 'a', 'img', 'b', 'strong', 'i', 'strike', 'u', 'font', 'p', 'ul', 'ol', 'li', 'blockquote', 'pre', 'code', 'h1', 'h2', 'h3', 'h4', 'hr'],
  34. allowedAttributes: {
  35. div: ['data-tpl', 'data-source', 'data-id'],
  36. span: ['data-id']
  37. },
  38. allowedStyles: {
  39. div: ['width', 'height', 'padding', 'background', 'color', 'display', 'justify-content', 'border', 'box-sizing', 'max-width', 'min-width', 'position', 'margin-left', 'bottom', 'left', 'margin', 'float'],
  40. p: ['margin', 'color', 'height', 'line-height', 'position', 'width', 'border', 'bottom', 'float'],
  41. span: ['text-decoration', 'color', 'margin-left', 'float', 'background', 'padding', 'margin-right', 'border-radius', 'font-size', 'border', 'float'],
  42. img: ['vertical-align', 'width', 'height', 'object-fit', 'float', 'margin', 'float'],
  43. a: ['text-decoration']
  44. }
  45. });
  46. editor.uploader.on('beforeupload', function (e, file) {
  47. Upload.api.send(file.obj, function (data) {
  48. var url = Fast.api.cdnurl(data.url);
  49. editor.uploader.trigger("uploadsuccess", [file, {success: true, file_path: url}]);
  50. });
  51. return false;
  52. });
  53. editor.on("blur", function () {
  54. this.textarea.trigger("blur");
  55. });
  56. Simditor.list[id] = editor;
  57. });
  58. });
  59. }
  60. }
  61. });
  62. });