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