[2000] | 1 | /*
|
---|
| 2 | Copyright (c) 2003-2009, 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 |
|
---|
| 40 | menu.onHide = CKEDITOR.tools.bind( function()
|
---|
| 41 | {
|
---|
| 42 | this.setState( _.previousState );
|
---|
| 43 | },
|
---|
| 44 | this );
|
---|
| 45 |
|
---|
| 46 | // Initialize the menu items at this point.
|
---|
| 47 | if ( this.onMenu )
|
---|
| 48 | {
|
---|
| 49 | menu.addListener( this.onMenu );
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | if ( _.on )
|
---|
| 54 | {
|
---|
| 55 | menu.hide();
|
---|
| 56 | return;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | this.setState( CKEDITOR.TRISTATE_ON );
|
---|
| 60 |
|
---|
| 61 | menu.show( CKEDITOR.document.getById( this._.id ), 4 );
|
---|
| 62 | };
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | CKEDITOR.ui.menuButton = CKEDITOR.tools.createClass(
|
---|
| 66 | {
|
---|
| 67 | base : CKEDITOR.ui.button,
|
---|
| 68 |
|
---|
| 69 | $ : function( definition )
|
---|
| 70 | {
|
---|
| 71 | // We don't want the panel definition in this object.
|
---|
| 72 | var panelDefinition = definition.panel;
|
---|
| 73 | delete definition.panel;
|
---|
| 74 |
|
---|
| 75 | this.base( definition );
|
---|
| 76 |
|
---|
| 77 | this.hasArrow = true;
|
---|
| 78 |
|
---|
| 79 | this.click = clickFn;
|
---|
| 80 | },
|
---|
| 81 |
|
---|
| 82 | statics :
|
---|
| 83 | {
|
---|
| 84 | handler :
|
---|
| 85 | {
|
---|
| 86 | create : function( definition )
|
---|
| 87 | {
|
---|
| 88 | return new CKEDITOR.ui.menuButton( definition );
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | });
|
---|
| 93 | })();
|
---|