config.js 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.allowedContent = true;
  12. config.format_tags = 'p;h1;h2;h3;pre';
  13. config.extraPlugins = 'uimage,umusic,uhtml,uvideo';
  14. config.removeButtons = 'Underline,Subscript,Superscript';
  15. config.removeDialogTabs = 'image:advanced;link:advanced';
  16. config.font_names = '微软雅黑/Microsoft YaHei;宋体/SimSun;新宋体/NSimSun;仿宋/FangSong;楷体/KaiTi;黑体/SimHei;' + config.font_names;
  17. };
  18. /*! 自定义图片上传插件 */
  19. CKEDITOR.plugins.add("uimage", {
  20. init: function (editor) {
  21. editor.ui.addButton("UploadImage", {label: "上传本地图片", command: 'uimage', icon: 'image', toolbar: 'insert,10'});
  22. setTimeout(function () {
  23. $('#cke_' + editor.name).find('.cke_button__uploadimage_label').parent().map(function () {
  24. $(this).attr('data-type', 'png,jpg,gif').attr('data-file', 'mul').uploadFile(function (url) {
  25. editor.insertElement(CKEDITOR.dom.element.createFromHtml('<span><img style="max-width:100%;border:0" alt="" src="' + url + '"></span>'));
  26. });
  27. });
  28. }, 100);
  29. }
  30. });
  31. /*! 自定义视频插入插件 */
  32. CKEDITOR.plugins.add('umusic', {
  33. init: function (editor) {
  34. editor.ui.addButton("UploadMusic", {label: "上传MP3文件", command: 'umusic', icon: 'specialchar', toolbar: 'insert,10'});
  35. setTimeout(function () {
  36. $('#cke_' + editor.name).find('.cke_button__uploadmusic_label').parent().map(function () {
  37. $(this).attr('data-type', 'mp3').attr('data-file', 'mul').uploadFile(function (url) {
  38. editor.insertElement(CKEDITOR.dom.element.createFromHtml('<div><audio controls="controls"><source src="' + url + '" type="audio/mpeg"></audio></div>'));
  39. });
  40. });
  41. }, 100);
  42. }
  43. });
  44. /*! 自定义视频插入插件 */
  45. CKEDITOR.plugins.add('uvideo', {
  46. init: function (editor) {
  47. editor.ui.addButton("UploadVideo", {label: "上传MP4文件", command: 'uvideo', icon: 'flash', toolbar: 'insert,10'});
  48. setTimeout(function () {
  49. $('#cke_' + editor.name).find('.cke_button__uploadvideo_label').parent().map(function () {
  50. $(this).attr('data-type', 'mp4').attr('data-file', 'mul').uploadFile(function (url) {
  51. editor.insertElement(CKEDITOR.dom.element.createFromHtml('<div><video width="100%" controls="controls"><source src="' + url + '" type="audio/mp4"></video></div>'));
  52. // 小程序不支持
  53. // editor.insertElement(CKEDITOR.dom.element.createFromHtml('<div><iframe src="' + url + '" style="max-width:100%;max-height:100%;border:0" allowfullscreen="true"></iframe></div>'));
  54. });
  55. });
  56. }, 100);
  57. }
  58. });
  59. /*! 自定义视频插入插件 */
  60. CKEDITOR.plugins.add('uhtml', {
  61. init: function (editor) {
  62. editor.ui.addButton("UploadHtml", {label: "插入HTML代码", command: 'uhtml', icon: 'creatediv', toolbar: 'insert,10'});
  63. editor.addCommand('uhtml', {
  64. exec: function (editor) {
  65. layer.prompt({title: '插入HTML代码', formType: 2, area: ['600px', '300px']}, function (html, index, element) {
  66. element = CKEDITOR.dom.element.createFromHtml('<div data-type="insert-html">' + html + '</div>');
  67. editor.insertElement(element);
  68. layer.close(index);
  69. });
  70. }
  71. });
  72. }
  73. });