[2862] | 1 | /*
|
---|
| 2 | Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
|
---|
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | CKEDITOR.plugins.add( 'menubutton',
|
---|
| 7 | {
|
---|
| 8 | requires : [ 'button', 'contextmenu' ],
|
---|
| 9 | beforeInit : function( editor )
|
---|
| 10 | {
|
---|
| 11 | editor.ui.addHandler( CKEDITOR.UI_MENUBUTTON, CKEDITOR.ui.menuButton.handler );
|
---|
| 12 | }
|
---|
| 13 | });
|
---|
| 14 |
|
---|
| 15 | /**
|
---|
| 16 | * Button UI element.
|
---|
| 17 | * @constant
|
---|
| 18 | * @example
|
---|
| 19 | */
|
---|
| 20 | CKEDITOR.UI_MENUBUTTON = 5;
|
---|
| 21 |
|
---|
| 22 | (function()
|
---|
| 23 | {
|
---|
| 24 | var clickFn = function( editor )
|
---|
| 25 | {
|
---|
| 26 | var _ = this._;
|
---|
| 27 |
|
---|
| 28 | // Do nothing if this button is disabled.
|
---|
| 29 | if ( _.state === CKEDITOR.TRISTATE_DISABLED )
|
---|
| 30 | return;
|
---|
| 31 |
|
---|
| 32 | _.previousState = _.state;
|
---|
| 33 |
|
---|
| 34 | // Check if we already have a menu for it, otherwise just create it.
|
---|
| 35 | var menu = _.menu;
|
---|
| 36 | if ( !menu )
|
---|
| 37 | {
|
---|
| 38 | menu = _.menu = new CKEDITOR.plugins.contextMenu( editor );
|
---|
| 39 | menu.definition.panel.attributes[ 'aria-label' ] = editor.lang.common.options;
|
---|
| 40 |
|
---|
| 41 | menu.onHide = CKEDITOR.tools.bind( function()
|
---|
| 42 | {
|
---|
| 43 | this.setState( _.previousState );
|
---|
| 44 | },
|
---|
| 45 | this );
|
---|
| 46 |
|
---|
| 47 | // Initialize the menu items at this point.
|
---|
| 48 | if ( this.onMenu )
|
---|
| 49 | {
|
---|
| 50 | menu.addListener( this.onMenu );
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | if ( _.on )
|
---|
| 55 | {
|
---|
| 56 | menu.hide();
|
---|
| 57 | return;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | this.setState( CKEDITOR.TRISTATE_ON );
|
---|
| 61 |
|
---|
| 62 | menu.show( CKEDITOR.document.getById( this._.id ), 4 );
|
---|
| 63 | };
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | CKEDITOR.ui.menuButton = CKEDITOR.tools.createClass(
|
---|
| 67 | {
|
---|
| 68 | base : CKEDITOR.ui.button,
|
---|
| 69 |
|
---|
| 70 | $ : function( definition )
|
---|
| 71 | {
|
---|
| 72 | // We don't want the panel definition in this object.
|
---|
| 73 | var panelDefinition = definition.panel;
|
---|
| 74 | delete definition.panel;
|
---|
| 75 |
|
---|
| 76 | this.base( definition );
|
---|
| 77 |
|
---|
| 78 | this.hasArrow = true;
|
---|
| 79 |
|
---|
| 80 | this.click = clickFn;
|
---|
| 81 | },
|
---|
| 82 |
|
---|
| 83 | statics :
|
---|
| 84 | {
|
---|
| 85 | handler :
|
---|
| 86 | {
|
---|
| 87 | create : function( definition )
|
---|
| 88 | {
|
---|
| 89 | return new CKEDITOR.ui.menuButton( definition );
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 | });
|
---|
| 94 | })();
|
---|