JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
1d152e24d38f7be5341207690a05e84a054b3dc7
[ckeditor.git] / _source / core / ui.js
1 /*\r
2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 /**\r
7  * Contains UI features related to an editor instance.\r
8  * @constructor\r
9  * @param {CKEDITOR.editor} editor The editor instance.\r
10  * @example\r
11  */\r
12 CKEDITOR.ui = function( editor )\r
13 {\r
14         if ( editor.ui )\r
15                 return editor.ui;\r
16 \r
17         /**\r
18          * Object used to hold private stuff.\r
19          * @private\r
20          */\r
21         this._ =\r
22         {\r
23                 handlers : {},\r
24                 items : {}\r
25         };\r
26 \r
27         return this;\r
28 };\r
29 \r
30 // PACKAGER_RENAME( CKEDITOR.ui )\r
31 \r
32 CKEDITOR.ui.prototype =\r
33 {\r
34         /**\r
35          * Adds a UI item to the items collection. These items can be later used in\r
36          * the interface.\r
37          * @param {String} name The UI item name.\r
38          * @param {Object} type The item type.\r
39          * @param {Object} definition The item definition. The properties of this\r
40          *              object depend on the item type.\r
41          * @example\r
42          * // Add a new button named "MyBold".\r
43          * editorInstance.ui.add( 'MyBold', CKEDITOR.UI_BUTTON,\r
44          *     {\r
45          *         label : 'My Bold',\r
46          *         command : 'bold'\r
47          *     });\r
48          */\r
49         add : function( name, type, definition )\r
50         {\r
51                 this._.items[ name ] =\r
52                 {\r
53                         type : type,\r
54                         args : Array.prototype.slice.call( arguments, 2 )\r
55                 };\r
56         },\r
57 \r
58         /**\r
59          * Gets a UI object.\r
60          * @param {String} name The UI item hame.\r
61          * @example\r
62          */\r
63         create : function( name )\r
64         {\r
65                 var item        = this._.items[ name ],\r
66                         handler = item && this._.handlers[ item.type ];\r
67 \r
68                 return handler && handler.create.apply( this, item.args );\r
69         },\r
70 \r
71         /**\r
72          * Adds a handler for a UI item type. The handler is responsible for\r
73          * transforming UI item definitions in UI objects.\r
74          * @param {Object} type The item type.\r
75          * @param {Object} handler The handler definition.\r
76          * @example\r
77          */\r
78         addHandler : function( type, handler )\r
79         {\r
80                 this._.handlers[ type ] = handler;\r
81         }\r
82 };\r
83 \r
84 /**\r
85  * (Virtual Class) Do not call this constructor. This class is not really part\r
86  *              of the API. It just illustrates the features of hanlder objects to be\r
87  *              passed to the {@link CKEDITOR.ui.prototype.addHandler} function.\r
88  * @name CKEDITOR.ui.handlerDefinition\r
89  * @constructor\r
90  * @example\r
91  */\r
92 \r
93  /**\r
94  * Transforms an item definition into an UI item object.\r
95  * @name CKEDITOR.handlerDefinition.prototype.create\r
96  * @function\r
97  * @param {Object} definition The item definition.\r
98  * @example\r
99  * editorInstance.ui.addHandler( CKEDITOR.UI_BUTTON,\r
100  *     {\r
101  *         create : function( definition )\r
102  *         {\r
103  *             return new CKEDITOR.ui.button( definition );\r
104  *         }\r
105  *     });\r
106  */\r