--- /dev/null
+/*\r
+Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+CKEDITOR.plugins.add( 'menubutton',\r
+{\r
+ requires : [ 'button', 'contextmenu' ],\r
+ beforeInit : function( editor )\r
+ {\r
+ editor.ui.addHandler( CKEDITOR.UI_MENUBUTTON, CKEDITOR.ui.menuButton.handler );\r
+ }\r
+});\r
+\r
+/**\r
+ * Button UI element.\r
+ * @constant\r
+ * @example\r
+ */\r
+CKEDITOR.UI_MENUBUTTON = 5;\r
+\r
+(function()\r
+{\r
+ var clickFn = function( editor )\r
+ {\r
+ var _ = this._;\r
+\r
+ // Do nothing if this button is disabled.\r
+ if ( _.state === CKEDITOR.TRISTATE_DISABLED )\r
+ return;\r
+\r
+ _.previousState = _.state;\r
+\r
+ // Check if we already have a menu for it, otherwise just create it.\r
+ var menu = _.menu;\r
+ if ( !menu )\r
+ {\r
+ menu = _.menu = new CKEDITOR.plugins.contextMenu( editor );\r
+\r
+ menu.onHide = CKEDITOR.tools.bind( function()\r
+ {\r
+ this.setState( _.previousState );\r
+ },\r
+ this );\r
+\r
+ // Initialize the menu items at this point.\r
+ if ( this.onMenu )\r
+ {\r
+ menu.addListener( this.onMenu );\r
+ }\r
+ }\r
+\r
+ if ( _.on )\r
+ {\r
+ menu.hide();\r
+ return;\r
+ }\r
+\r
+ this.setState( CKEDITOR.TRISTATE_ON );\r
+\r
+ menu.show( CKEDITOR.document.getById( this._.id ), 4 );\r
+ };\r
+\r
+\r
+ CKEDITOR.ui.menuButton = CKEDITOR.tools.createClass(\r
+ {\r
+ base : CKEDITOR.ui.button,\r
+\r
+ $ : function( definition )\r
+ {\r
+ // We don't want the panel definition in this object.\r
+ var panelDefinition = definition.panel;\r
+ delete definition.panel;\r
+\r
+ this.base( definition );\r
+\r
+ this.hasArrow = true;\r
+\r
+ this.click = clickFn;\r
+ },\r
+\r
+ statics :\r
+ {\r
+ handler :\r
+ {\r
+ create : function( definition )\r
+ {\r
+ return new CKEDITOR.ui.menuButton( definition );\r
+ }\r
+ }\r
+ }\r
+ });\r
+})();\r