plugin.js 3.8 KB

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