plugin.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. CKEDITOR.plugins.add('spacing', {
  2. init: function(editor) {
  3. // 添加段前间距命令
  4. editor.addCommand('setSpacingBefore', {
  5. exec: function(editor) {
  6. var style = new CKEDITOR.style({
  7. element: 'p',
  8. attributes: {
  9. 'style': 'margin-top: ' + this.value + ';line-height: 1;'
  10. }
  11. });
  12. editor.applyStyle(style);
  13. }
  14. });
  15. // 添加段后间距命令
  16. editor.addCommand('setSpacingAfter', {
  17. exec: function(editor) {
  18. var style = new CKEDITOR.style({
  19. element: 'p',
  20. attributes: {
  21. 'style': 'margin-bottom: ' + this.value + ';line-height: 1;'
  22. }
  23. });
  24. editor.applyStyle(style);
  25. }
  26. });
  27. // 创建段前间距下拉菜单
  28. editor.ui.addRichCombo('SpacingBefore', {
  29. label: '段前间距',
  30. title: '设置段前间距',
  31. panel: {
  32. css: [CKEDITOR.skin.getPath('editor')].concat(editor.config.contentsCss)
  33. },
  34. init: function() {
  35. this.startGroup('段前间距');
  36. this.add('0', '0行');
  37. this.add('1em', '1行');
  38. this.add('1.5em', '1.5行');
  39. this.add('2em', '2行');
  40. },
  41. onClick: function(value) {
  42. editor.execCommand('setSpacingBefore', { value: value });
  43. }
  44. });
  45. // 创建段后间距下拉菜单
  46. editor.ui.addRichCombo('SpacingAfter', {
  47. label: '段后间距',
  48. title: '设置段后间距',
  49. panel: {
  50. css: [CKEDITOR.skin.getPath('editor')].concat(editor.config.contentsCss)
  51. },
  52. init: function() {
  53. this.startGroup('段后间距');
  54. this.add('0', '0行');
  55. this.add('1em', '1行');
  56. this.add('1.5em', '1.5行');
  57. this.add('2em', '2行');
  58. },
  59. onClick: function(value) {
  60. editor.execCommand('setSpacingAfter', { value: value });
  61. }
  62. });
  63. }
  64. });