plugin.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.html or http://ckeditor.com/license
  4. */
  5. /**
  6. * @fileOverview Plugin that changes the toolbar and maximizes the editor
  7. * for the big toolbar.
  8. *
  9. * You need a custom config to define the small and big toolbars.
  10. * Also the maximize plug-in is needed but not the maximize button.
  11. * For this plugin you should use the 'Toolbarswitch' button instead.
  12. *
  13. * CKEDITOR.replace('sometextcomponentname', {
  14. * customConfig: '/...custom_ckeditor_config.js'
  15. * toolbar: 'yoursmalltoolbarname',
  16. * smallToolbar: 'yoursmalltoolbarname',
  17. * maximizedToolbar: 'yourbigtoolbarname' });
  18. *
  19. * Requires:
  20. * - Maximize plugin. But not the button that goes with it.
  21. * - All toolbars used in the ckeditor instance have to use the 'Toolbarswitch' button instead.
  22. * - A custom config to define the small and big toolbars.
  23. * - function CKeditor_OnComplete(ckEditorInstance){ ... your own custom code or leave empty... }
  24. * This was added to the plugin for those that wrap the ckeditor in other java script to shield
  25. * the rest of their code from ckeditor version particularities.
  26. * - jQuery
  27. */
  28. function switchMe(editor, callback) {
  29. var origCustomConfig = editor.config.customConfig;
  30. var origContentCss = editor.config.contentsCss;
  31. var origExtraPlugins = editor.config.extraPlugins;
  32. var origMinToolbar = editor.config.toolbar_minToolbar;
  33. var origMaxToolbar = editor.config.toolbar_maxToolbar;
  34. var origToolbar = editor.config.toolbar;
  35. var origSmallToolbar = editor.config.smallToolbar;
  36. var origMaximizedToolbar = editor.config.maximizedToolbar;
  37. var origStartupOutlineBlocks = editor.config.startupOutlineBlocks;
  38. var newToolbar;
  39. if (origToolbar == origSmallToolbar) {
  40. newToolbar = origMaximizedToolbar;
  41. } else {
  42. newToolbar = origSmallToolbar;
  43. }
  44. // Copy data to original text element before getting rid of the old editor
  45. var data = editor.getData();
  46. var domTextElement = editor.element.$;
  47. jQuery(domTextElement).val(data);
  48. // Remove old editor and the DOM elements, else you get two editors
  49. var id = domTextElement.id;
  50. editor.destroy(true);
  51. CKEDITOR.replace(id, {
  52. startupOutlineBlocks: origStartupOutlineBlocks,
  53. customConfig : origCustomConfig,
  54. contentsCss : origContentCss,
  55. toolbar_minToolbar: origMinToolbar,
  56. toolbar_maxToolbar: origMaxToolbar,
  57. toolbar : newToolbar,
  58. smallToolbar: origSmallToolbar,
  59. maximizedToolbar: origMaximizedToolbar,
  60. extraPlugins : origExtraPlugins,
  61. on: {
  62. instanceReady: function(e) {
  63. if (typeof CKeditor_OnComplete !== 'undefined') {
  64. CKeditor_OnComplete(e.editor);
  65. }
  66. if (callback) {
  67. callback.call(null, e);
  68. }
  69. }
  70. }
  71. });
  72. }
  73. CKEDITOR.plugins.add('toolbarswitch', {
  74. requires: [ 'button', 'toolbar', 'maximize' ],
  75. 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,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
  76. icons: 'toolbarswitch', // %REMOVE_LINE_CORE%
  77. hidpi: true, // %REMOVE_LINE_CORE%
  78. init: function (editor) {
  79. var lang = editor.lang;
  80. var commandFunction = {
  81. exec: function( editor ) {
  82. if ( editor.config.toolbar == editor.config.maximizedToolbar ) {
  83. // For switching to the small toolbar first minimize
  84. editor.commands.maximize.exec();
  85. switchMe(editor, function(e){
  86. var newEditor = e.editor;
  87. newEditor.fire('triggerResize');
  88. });
  89. } else {
  90. switchMe(editor, function(e){
  91. var newEditor = e.editor;
  92. newEditor.commands.maximize.exec();
  93. newEditor.fire('triggerResize');
  94. });
  95. }
  96. }
  97. }
  98. var command = editor.addCommand( 'toolbarswitch', commandFunction );
  99. command.modes = { wysiwyg:1,source:1 };
  100. command.canUndo = false;
  101. command.readOnly = 1;
  102. editor.ui.addButton && editor.ui.addButton( 'Toolbarswitch', {
  103. label: lang.toolbarswitch.toolbarswitch,
  104. command: 'toolbarswitch',
  105. toolbar: 'tools,10'
  106. });
  107. }
  108. });