config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // 定义编辑器标准配置
  2. CKEDITOR.editorConfig = function (config) {
  3. config.language = 'zh-cn';
  4. config.toolbar = [
  5. {name: 'document', items: ['Source']},
  6. {name: 'clipboard', items: ['Undo', 'Redo']},
  7. {name: 'styles', items: ['Font', 'FontSize']},
  8. {name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat', 'CopyFormatting', 'TextColor', 'BGColor']},
  9. {name: 'align', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']},
  10. {name: 'paragraph', items: ['NumberedList', 'BulletedList', 'Outdent', 'Indent', 'Blockquote', 'Link', 'Unlink']},
  11. {name: 'uimage', items: ['Table', 'UploadImage']},
  12. {name: 'tools', items: ['Maximize']}
  13. ];
  14. config.allowedContent = true;
  15. config.extraPlugins = 'uimage';
  16. config.format_tags = 'p;h1;h2;h3;pre';
  17. config.removeButtons = 'Underline,Subscript,Superscript';
  18. config.removeDialogTabs = 'image:advanced;link:advanced';
  19. config.font_names = '宋体/SimSun;新宋体/NSimSun;仿宋_GB2312/FangSong_GB2312;楷体_GB2312/KaiTi_GB2312;黑体/SimHei;微软雅黑/Microsoft YaHei;' + 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. editor.addCommand('uimage', {
  26. exec: function (editor) {
  27. var field = '_editor_upload_' + Math.floor(Math.random() * 100000);
  28. var url = window.ROOT_URL + '/index.php/admin/plugs/upfile.html?mode=one&type=png,jpg,gif,jpeg&field=' + field;
  29. $('<input type="hidden">').attr('name', field).appendTo(editor.element.$).on('change', function () {
  30. var element = CKEDITOR.dom.element.createFromHtml('<img src="' + this.value + '" style="max-width:500px" border="0" title="image" />');
  31. editor.insertElement(element), $(this).remove();
  32. });
  33. $.form.iframe(url, '插入图片');
  34. }
  35. });
  36. }
  37. });