plugin.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.lineheight.label,
  33. title: lang.lineheight.panelTitle,
  34. className: 'cke_' + (styleType == 'size' ? 'fontSize' : 'font'),
  35. panel :{
  36. css : [CKEDITOR.skin.getPath("editor")].concat( config.contentsCss ),
  37. multiSelect : false,
  38. attributes: { 'aria-label': lang.lineheight.panelTitle }
  39. },
  40. init : function()
  41. {
  42. this.startGroup( lang.lineheight.panelTitle );
  43. for ( var i = 0 ; i < names.length ; i++ )
  44. {
  45. var name = names[ i ];
  46. // Add the tag entry to the panel list.
  47. this.add( name, styles[ name ].buildPreview(), name );
  48. }
  49. },
  50. onClick : function( value )
  51. {
  52. editor.focus();
  53. editor.fire( 'saveSnapshot' );
  54. var style = styles[ value ];
  55. if ( this.getValue() == value )
  56. style.remove( editor.document );
  57. else
  58. style.apply( editor.document );
  59. editor.fire( 'saveSnapshot' );
  60. },
  61. onRender : function()
  62. {
  63. editor.on( 'selectionChange', function( ev )
  64. {
  65. var currentValue = this.getValue();
  66. var elementPath = ev.data.path,
  67. elements = elementPath.elements;
  68. // For each element into the elements path.
  69. for ( var i = 0, element ; i < elements.length ; i++ )
  70. {
  71. element = elements[i];
  72. // Check if the element is removable by any of
  73. // the styles.
  74. for ( var value in styles )
  75. {
  76. if ( styles[ value ].checkElementRemovable( element, true ) )
  77. {
  78. if ( value != currentValue )
  79. this.setValue( value );
  80. return;
  81. }
  82. }
  83. }
  84. // If no styles match, just empty it.
  85. this.setValue( '', defaultLabel );
  86. },
  87. this);
  88. }
  89. });
  90. }
  91. CKEDITOR.plugins.add('lineheight',
  92. {
  93. lang: ['zh-cn'],
  94. requires : [ 'richcombo'],
  95. init : function( editor )
  96. {
  97. var config = editor.config;
  98. addCombo(editor, 'lineheight', 'size', editor.lang, config.lineheight_sizes, config.fontSize_defaultLabel, config.lineheight_style);
  99. }
  100. });
  101. })();
  102. /**
  103. * The text to be displayed in the Font combo is none of the available values
  104. * matches the current cursor position or text selection.
  105. * @type String
  106. * @example
  107. * // If the default site font is Arial, we may making it more explicit to the end user.
  108. * config.font_defaultLabel = 'Arial';
  109. */
  110. CKEDITOR.config.font_defaultLabel = '';
  111. CKEDITOR.config.lineheight_sizes =
  112. 'normal;1.5em;1.75em;2em;3em;4em;5em;100%;120%;130%;150%;170%;180%;190%;200%;220%;250%;300%;400%;500%';
  113. CKEDITOR.config.lineheight_style =
  114. {
  115. element : 'span',
  116. styles : { 'line-height' : '#(size)' },
  117. overrides: [{ element: 'line', attributes: { 'height': null}}]
  118. };