plugin.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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( 'menubutton', {
  6. requires: 'button,menu',
  7. onLoad: function() {
  8. var clickFn = function( editor ) {
  9. var _ = this._,
  10. menu = _.menu;
  11. // Do nothing if this button is disabled.
  12. if ( _.state === CKEDITOR.TRISTATE_DISABLED )
  13. return;
  14. if ( _.on && menu ) {
  15. menu.hide();
  16. return;
  17. }
  18. _.previousState = _.state;
  19. // Check if we already have a menu for it, otherwise just create it.
  20. if ( !menu ) {
  21. menu = _.menu = new CKEDITOR.menu( editor, {
  22. panel: {
  23. className: 'cke_menu_panel',
  24. attributes: { 'aria-label': editor.lang.common.options }
  25. }
  26. } );
  27. menu.onHide = CKEDITOR.tools.bind( function() {
  28. var modes = this.command ? editor.getCommand( this.command ).modes : this.modes;
  29. this.setState( !modes || modes[ editor.mode ] ? _.previousState : CKEDITOR.TRISTATE_DISABLED );
  30. _.on = 0;
  31. }, this );
  32. // Initialize the menu items at this point.
  33. if ( this.onMenu )
  34. menu.addListener( this.onMenu );
  35. }
  36. this.setState( CKEDITOR.TRISTATE_ON );
  37. _.on = 1;
  38. // This timeout is needed to give time for the panel get focus
  39. // when JAWS is running. (#9842)
  40. setTimeout( function() {
  41. menu.show( CKEDITOR.document.getById( _.id ), 4 );
  42. }, 0 );
  43. };
  44. /**
  45. * @class
  46. * @extends CKEDITOR.ui.button
  47. * @todo
  48. */
  49. CKEDITOR.ui.menuButton = CKEDITOR.tools.createClass( {
  50. base: CKEDITOR.ui.button,
  51. /**
  52. * Creates a menuButton class instance.
  53. *
  54. * @constructor
  55. * @param Object definition
  56. * @todo
  57. */
  58. $: function( definition ) {
  59. // We don't want the panel definition in this object.
  60. delete definition.panel;
  61. this.base( definition );
  62. this.hasArrow = true;
  63. this.click = clickFn;
  64. },
  65. statics: {
  66. handler: {
  67. create: function( definition ) {
  68. return new CKEDITOR.ui.menuButton( definition );
  69. }
  70. }
  71. }
  72. } );
  73. },
  74. beforeInit: function( editor ) {
  75. editor.ui.addHandler( CKEDITOR.UI_MENUBUTTON, CKEDITOR.ui.menuButton.handler );
  76. }
  77. } );
  78. /**
  79. * Button UI element.
  80. *
  81. * @readonly
  82. * @property {String} [='menubutton']
  83. * @member CKEDITOR
  84. */
  85. CKEDITOR.UI_MENUBUTTON = 'menubutton';