config.js 4.1 KB

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