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