config.js 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*! 定义编辑器标准配置 */
  2. CKEDITOR.editorConfig = function (config) {
  3. config.toolbar = [
  4. {name: 'document', items: ['Source']},
  5. {name: 'styles', items: ['Font', 'FontSize']},
  6. {name: 'basicstyles', items: ['lineheight', 'Indent', 'Outdent', 'Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat', 'TextColor', 'BGColor', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', 'NumberedList', 'BulletedList']},
  7. {name: 'element', items: ['Link', 'Unlink', 'Table', 'UploadImage', 'UploadMusic', 'UploadVideo', 'UploadHtml']},
  8. {name: 'tools', items: ['Print', 'Maximize']}
  9. ];
  10. config.language = 'zh-cn';
  11. config.format_tags = 'p;h1;h2;h3;pre';
  12. config.extraPlugins = 'uimage,umusic,uhtml,uvideo,lineheight';
  13. config.removePlugins = 'easyimage,cloudservices,exportpdf';
  14. config.removeButtons = 'Underline,Subscript,Superscript';
  15. config.removeDialogTabs = 'image:advanced;link:advanced';
  16. // 内容过滤
  17. config.disallowedContent = 'script; *[on*]';
  18. config.allowedContent = {$1: {elements: CKEDITOR.dtd, attributes: true, styles: true, classes: true}};
  19. config.font_names = '微软雅黑/Microsoft YaHei;宋体/SimSun;新宋体/NSimSun;仿宋/FangSong;楷体/KaiTi;黑体/SimHei;' + config.font_names;
  20. };
  21. /*! 自定义图片上传插件 */
  22. CKEDITOR.plugins.add("uimage", {
  23. init: function (editor) {
  24. editor.ui.addButton("UploadImage", {label: "上传本地图片", command: 'uimage', icon: 'image', toolbar: 'insert,10'});
  25. setTimeout(function () {
  26. $('#cke_' + editor.name).find('.cke_button__uploadimage_label').parent().map(function () {
  27. $(this).attr('data-type', 'png,jpg,gif,jpeg').attr('data-file', 'images').on('push', function (e, url) {
  28. editor.insertElement(CKEDITOR.dom.element.createFromHtml('<div><img style="border:0;max-width:100%;" alt="" src="' + url + '"></div>'));
  29. });
  30. });
  31. }, 100);
  32. }
  33. });
  34. /*! 自定义视频插入插件 */
  35. CKEDITOR.plugins.add('umusic', {
  36. init: function (editor) {
  37. editor.ui.addButton("UploadMusic", {label: "上传MP3文件", command: 'umusic', icon: 'specialchar', toolbar: 'insert,10'});
  38. setTimeout(function () {
  39. $('#cke_' + editor.name).find('.cke_button__uploadmusic_label').parent().map(function () {
  40. $(this).attr('data-type', 'mp3').attr('data-file', 'mul').uploadFile(function (url) {
  41. editor.insertElement(CKEDITOR.dom.element.createFromHtml('<div><audio controls="controls"><source src="' + url + '" type="audio/mpeg"></audio></div>'));
  42. });
  43. });
  44. }, 100);
  45. }
  46. });
  47. /*! 自定义视频插入插件 */
  48. CKEDITOR.plugins.add('uvideo', {
  49. init: function (editor) {
  50. editor.ui.addButton("UploadVideo", {label: "上传MP4文件", command: 'uvideo', icon: 'iframe', toolbar: 'insert,10'});
  51. setTimeout(function () {
  52. $('#cke_' + editor.name).find('.cke_button__uploadvideo_label').parent().map(function () {
  53. $(this).attr('data-type', 'mp4').attr('data-file', 'mul').uploadFile(function (url) {
  54. editor.insertElement(CKEDITOR.dom.element.createFromHtml('<div><video width="100%" controls="controls"><source src="' + url + '" type="audio/mp4"></video></div>'));
  55. // 小程序不支持
  56. // editor.insertElement(CKEDITOR.dom.element.createFromHtml('<div><iframe src="' + url + '" style="max-width:100%;max-height:100%;border:0" allowfullscreen="true"></iframe></div>'));
  57. });
  58. });
  59. }, 100);
  60. }
  61. });
  62. /*! 自定义视频插入插件 */
  63. CKEDITOR.plugins.add('uhtml', {
  64. init: function (editor) {
  65. editor.ui.addButton("UploadHtml", {label: "插入HTML代码", command: 'uhtml', icon: 'creatediv', toolbar: 'insert,10'});
  66. editor.addCommand('uhtml', {
  67. exec: function (editor) {
  68. layui.layer.prompt({title: '插入HTML代码', formType: 2, area: ['600px', '300px']}, function (html, index, element) {
  69. element = CKEDITOR.dom.element.createFromHtml('<div data-type="insert-html">' + html + '</div>');
  70. editor.insertElement(element), layui.layer.close(index);
  71. });
  72. }
  73. });
  74. }
  75. });