2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.plugins.add( 'menubutton',
\r
8 requires : [ 'button', 'menu' ],
\r
9 beforeInit : function( editor )
\r
11 editor.ui.addHandler( CKEDITOR.UI_MENUBUTTON, CKEDITOR.ui.menuButton.handler );
\r
16 * Button UI element.
\r
20 CKEDITOR.UI_MENUBUTTON = 5;
\r
24 var clickFn = function( editor )
\r
28 // Do nothing if this button is disabled.
\r
29 if ( _.state === CKEDITOR.TRISTATE_DISABLED )
\r
32 _.previousState = _.state;
\r
34 // Check if we already have a menu for it, otherwise just create it.
\r
38 menu = _.menu = new CKEDITOR.menu( editor,
\r
42 className : editor.skinClass + ' cke_contextmenu',
\r
43 attributes : { 'aria-label' : editor.lang.common.options }
\r
47 menu.onHide = CKEDITOR.tools.bind( function()
\r
49 this.setState( this.modes && this.modes[ editor.mode ] ? _.previousState : CKEDITOR.TRISTATE_DISABLED );
\r
53 // Initialize the menu items at this point.
\r
55 menu.addListener( this.onMenu );
\r
64 this.setState( CKEDITOR.TRISTATE_ON );
\r
66 menu.show( CKEDITOR.document.getById( this._.id ), 4 );
\r
70 CKEDITOR.ui.menuButton = CKEDITOR.tools.createClass(
\r
72 base : CKEDITOR.ui.button,
\r
74 $ : function( definition )
\r
76 // We don't want the panel definition in this object.
\r
77 var panelDefinition = definition.panel;
\r
78 delete definition.panel;
\r
80 this.base( definition );
\r
82 this.hasArrow = true;
\r
84 this.click = clickFn;
\r
91 create : function( definition )
\r
93 return new CKEDITOR.ui.menuButton( definition );
\r