plugin.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or http://ckeditor.com/license
  4. */
  5. CKEDITOR.plugins.add( 'basicstyles', {
  6. // jscs:disable maximumLineLength
  7. lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en,en-au,en-ca,en-gb,eo,es,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
  8. // jscs:enable maximumLineLength
  9. icons: 'bold,italic,underline,strike,subscript,superscript', // %REMOVE_LINE_CORE%
  10. hidpi: true, // %REMOVE_LINE_CORE%
  11. init: function( editor ) {
  12. var order = 0;
  13. // All buttons use the same code to register. So, to avoid
  14. // duplications, let's use this tool function.
  15. var addButtonCommand = function( buttonName, buttonLabel, commandName, styleDefiniton ) {
  16. // Disable the command if no definition is configured.
  17. if ( !styleDefiniton )
  18. return;
  19. var style = new CKEDITOR.style( styleDefiniton ),
  20. forms = contentForms[ commandName ];
  21. // Put the style as the most important form.
  22. forms.unshift( style );
  23. // Listen to contextual style activation.
  24. editor.attachStyleStateChange( style, function( state ) {
  25. !editor.readOnly && editor.getCommand( commandName ).setState( state );
  26. } );
  27. // Create the command that can be used to apply the style.
  28. editor.addCommand( commandName, new CKEDITOR.styleCommand( style, {
  29. contentForms: forms
  30. } ) );
  31. // Register the button, if the button plugin is loaded.
  32. if ( editor.ui.addButton ) {
  33. editor.ui.addButton( buttonName, {
  34. label: buttonLabel,
  35. command: commandName,
  36. toolbar: 'basicstyles,' + ( order += 10 )
  37. } );
  38. }
  39. };
  40. var contentForms = {
  41. bold: [
  42. 'strong',
  43. 'b',
  44. [ 'span', function( el ) {
  45. var fw = el.styles[ 'font-weight' ];
  46. return fw == 'bold' || +fw >= 700;
  47. } ]
  48. ],
  49. italic: [
  50. 'em',
  51. 'i',
  52. [ 'span', function( el ) {
  53. return el.styles[ 'font-style' ] == 'italic';
  54. } ]
  55. ],
  56. underline: [
  57. 'u',
  58. [ 'span', function( el ) {
  59. return el.styles[ 'text-decoration' ] == 'underline';
  60. } ]
  61. ],
  62. strike: [
  63. 's',
  64. 'strike',
  65. [ 'span', function( el ) {
  66. return el.styles[ 'text-decoration' ] == 'line-through';
  67. } ]
  68. ],
  69. subscript: [
  70. 'sub'
  71. ],
  72. superscript: [
  73. 'sup'
  74. ]
  75. },
  76. config = editor.config,
  77. lang = editor.lang.basicstyles;
  78. addButtonCommand( 'Bold', lang.bold, 'bold', config.coreStyles_bold );
  79. addButtonCommand( 'Italic', lang.italic, 'italic', config.coreStyles_italic );
  80. addButtonCommand( 'Underline', lang.underline, 'underline', config.coreStyles_underline );
  81. addButtonCommand( 'Strike', lang.strike, 'strike', config.coreStyles_strike );
  82. addButtonCommand( 'Subscript', lang.subscript, 'subscript', config.coreStyles_subscript );
  83. addButtonCommand( 'Superscript', lang.superscript, 'superscript', config.coreStyles_superscript );
  84. editor.setKeystroke( [
  85. [ CKEDITOR.CTRL + 66 /*B*/, 'bold' ],
  86. [ CKEDITOR.CTRL + 73 /*I*/, 'italic' ],
  87. [ CKEDITOR.CTRL + 85 /*U*/, 'underline' ]
  88. ] );
  89. }
  90. } );
  91. // Basic Inline Styles.
  92. /**
  93. * The style definition that applies the **bold** style to the text.
  94. *
  95. * config.coreStyles_bold = { element: 'b', overrides: 'strong' };
  96. *
  97. * config.coreStyles_bold = {
  98. * element: 'span',
  99. * attributes: { 'class': 'Bold' }
  100. * };
  101. *
  102. * @cfg
  103. * @member CKEDITOR.config
  104. */
  105. CKEDITOR.config.coreStyles_bold = { element: 'strong', overrides: 'b' };
  106. /**
  107. * The style definition that applies the *italics* style to the text.
  108. *
  109. * config.coreStyles_italic = { element: 'i', overrides: 'em' };
  110. *
  111. * CKEDITOR.config.coreStyles_italic = {
  112. * element: 'span',
  113. * attributes: { 'class': 'Italic' }
  114. * };
  115. *
  116. * @cfg
  117. * @member CKEDITOR.config
  118. */
  119. CKEDITOR.config.coreStyles_italic = { element: 'em', overrides: 'i' };
  120. /**
  121. * The style definition that applies the <u>underline</u> style to the text.
  122. *
  123. * CKEDITOR.config.coreStyles_underline = {
  124. * element: 'span',
  125. * attributes: { 'class': 'Underline' }
  126. * };
  127. *
  128. * @cfg
  129. * @member CKEDITOR.config
  130. */
  131. CKEDITOR.config.coreStyles_underline = { element: 'u' };
  132. /**
  133. * The style definition that applies the <strike>strikethrough</strike> style to the text.
  134. *
  135. * CKEDITOR.config.coreStyles_strike = {
  136. * element: 'span',
  137. * attributes: { 'class': 'Strikethrough' },
  138. * overrides: 'strike'
  139. * };
  140. *
  141. * @cfg
  142. * @member CKEDITOR.config
  143. */
  144. CKEDITOR.config.coreStyles_strike = { element: 's', overrides: 'strike' };
  145. /**
  146. * The style definition that applies the subscript style to the text.
  147. *
  148. * CKEDITOR.config.coreStyles_subscript = {
  149. * element: 'span',
  150. * attributes: { 'class': 'Subscript' },
  151. * overrides: 'sub'
  152. * };
  153. *
  154. * @cfg
  155. * @member CKEDITOR.config
  156. */
  157. CKEDITOR.config.coreStyles_subscript = { element: 'sub' };
  158. /**
  159. * The style definition that applies the superscript style to the text.
  160. *
  161. * CKEDITOR.config.coreStyles_superscript = {
  162. * element: 'span',
  163. * attributes: { 'class': 'Superscript' },
  164. * overrides: 'sup'
  165. * };
  166. *
  167. * @cfg
  168. * @member CKEDITOR.config
  169. */
  170. CKEDITOR.config.coreStyles_superscript = { element: 'sup' };