plugin.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
  3. For licensing, see LICENSE.html or http://ckeditor.com/license
  4. */
  5. (function()
  6. {
  7. function addCombo( editor, comboName, styleType, lang, entries, defaultLabel, styleDefinition )
  8. {
  9. var config = editor.config;
  10. // Gets the list of fonts from the settings.
  11. var names = entries.split( ';' ),
  12. values = [];
  13. // Create style objects for all fonts.
  14. var styles = {};
  15. for ( var i = 0 ; i < names.length ; i++ )
  16. {
  17. var parts = names[ i ];
  18. if ( parts )
  19. {
  20. parts = parts.split( '/' );
  21. var vars = {},
  22. name = names[ i ] = parts[ 0 ];
  23. vars[ styleType ] = values[ i ] = parts[ 1 ] || name;
  24. styles[ name ] = new CKEDITOR.style( styleDefinition, vars );
  25. styles[ name ]._.definition.name = name;
  26. }
  27. else
  28. names.splice( i--, 1 );
  29. }
  30. editor.ui.addRichCombo( comboName,
  31. {
  32. label : lang.label,
  33. title: lang.panelTitle,
  34. className: 'cke_' + (styleType == 'size' ? 'fontSize' : 'font'),
  35. panel :
  36. {
  37. css : editor.skin.editor.css.concat( config.contentsCss ),
  38. multiSelect : false,
  39. attributes: { 'aria-label': lang.panelTitle }
  40. },
  41. init : function()
  42. {
  43. this.startGroup( lang.panelTitle );
  44. for ( var i = 0 ; i < names.length ; i++ )
  45. {
  46. var name = names[ i ];
  47. // Add the tag entry to the panel list.
  48. this.add( name, styles[ name ].buildPreview(), name );
  49. }
  50. },
  51. onClick : function( value )
  52. {
  53. editor.focus();
  54. editor.fire( 'saveSnapshot' );
  55. var style = styles[ value ];
  56. if ( this.getValue() == value )
  57. style.remove( editor.document );
  58. else
  59. style.apply( editor.document );
  60. editor.fire( 'saveSnapshot' );
  61. },
  62. onRender : function()
  63. {
  64. editor.on( 'selectionChange', function( ev )
  65. {
  66. var currentValue = this.getValue();
  67. var elementPath = ev.data.path,
  68. elements = elementPath.elements;
  69. // For each element into the elements path.
  70. for ( var i = 0, element ; i < elements.length ; i++ )
  71. {
  72. element = elements[i];
  73. // Check if the element is removable by any of
  74. // the styles.
  75. for ( var value in styles )
  76. {
  77. if ( styles[ value ].checkElementRemovable( element, true ) )
  78. {
  79. if ( value != currentValue )
  80. this.setValue( value );
  81. return;
  82. }
  83. }
  84. }
  85. // If no styles match, just empty it.
  86. this.setValue( '', defaultLabel );
  87. },
  88. this);
  89. }
  90. });
  91. }
  92. CKEDITOR.plugins.add('lineheight',
  93. {
  94. lang: ['zh-cn'],
  95. requires : [ 'richcombo', 'styles' ],
  96. init : function( editor )
  97. {
  98. var config = editor.config;
  99. addCombo(editor, 'lineheight', 'size', editor.lang, config.lineheight_sizes, config.fontSize_defaultLabel, config.lineheight_style);
  100. }
  101. });
  102. })();
  103. /**
  104. * The text to be displayed in the Font combo is none of the available values
  105. * matches the current cursor position or text selection.
  106. * @type String
  107. * @example
  108. * // If the default site font is Arial, we may making it more explicit to the end user.
  109. * config.font_defaultLabel = 'Arial';
  110. */
  111. CKEDITOR.config.font_defaultLabel = '';
  112. CKEDITOR.config.lineheight_sizes =
  113. '100%;120%;130%;150%;170%;180%;190%;200%;220%;250%;300%;400%;500%';
  114. CKEDITOR.config.lineheight_style =
  115. {
  116. element : 'span',
  117. styles : { 'line-height' : '#(size)' },
  118. overrides: [{ element: 'line', attributes: { 'height': null}}]
  119. };