plugin.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 newToolbar;
  38. if (origToolbar == origSmallToolbar) {
  39. newToolbar = origMaximizedToolbar;
  40. } else {
  41. newToolbar = origSmallToolbar;
  42. }
  43. // Copy data to original text element before getting rid of the old editor
  44. var data = editor.getData();
  45. var domTextElement = editor.element.$;
  46. jQuery(domTextElement).val(data);
  47. // Remove old editor and the DOM elements, else you get two editors
  48. var id = domTextElement.id;
  49. editor.destroy(true);
  50. CKEDITOR.replace(id, {
  51. customConfig : origCustomConfig,
  52. contentsCss : origContentCss,
  53. toolbar_minToolbar: origMinToolbar,
  54. toolbar_maxToolbar: origMaxToolbar,
  55. toolbar : newToolbar,
  56. smallToolbar: origSmallToolbar,
  57. maximizedToolbar: origMaximizedToolbar,
  58. extraPlugins : origExtraPlugins,
  59. on: {
  60. instanceReady: function(e) {
  61. if (typeof CKeditor_OnComplete !== 'undefined') {
  62. CKeditor_OnComplete(e.editor);
  63. }
  64. if (callback) {
  65. callback.call(null, e);
  66. }
  67. }
  68. }
  69. });
  70. }
  71. CKEDITOR.plugins.add('toolbarswitch', {
  72. requires: [ 'button', 'toolbar', 'maximize' ],
  73. 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%
  74. icons: 'toolbarswitch', // %REMOVE_LINE_CORE%
  75. hidpi: true, // %REMOVE_LINE_CORE%
  76. init: function (editor) {
  77. var lang = editor.lang;
  78. var commandFunction = {
  79. exec: function( editor ) {
  80. if ( editor.config.toolbar == editor.config.maximizedToolbar ) {
  81. // For switching to the small toolbar first minimize
  82. editor.commands.maximize.exec();
  83. switchMe(editor, function(e){
  84. var newEditor = e.editor;
  85. newEditor.fire('triggerResize');
  86. });
  87. } else {
  88. switchMe(editor, function(e){
  89. var newEditor = e.editor;
  90. newEditor.commands.maximize.exec();
  91. newEditor.fire('triggerResize');
  92. });
  93. }
  94. }
  95. }
  96. var command = editor.addCommand( 'toolbarswitch', commandFunction );
  97. command.modes = { wysiwyg:1,source:1 };
  98. command.canUndo = false;
  99. command.readOnly = 1;
  100. editor.ui.addButton && editor.ui.addButton( 'Toolbarswitch', {
  101. label: lang.toolbarswitch.toolbarswitch,
  102. command: 'toolbarswitch',
  103. toolbar: 'tools,10'
  104. });
  105. }
  106. });