bootstrap.js 3.2 KB

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