2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * Contains UI features related to an editor instance.
\r
9 * @param {CKEDITOR.editor} editor The editor instance.
\r
12 CKEDITOR.ui = function( editor )
\r
18 * Object used to hold private stuff.
\r
31 // PACKAGER_RENAME( CKEDITOR.ui )
\r
33 CKEDITOR.ui.prototype =
\r
36 * Adds a UI item to the items collection. These items can be later used in
\r
38 * @param {String} name The UI item name.
\r
39 * @param {Object} type The item type.
\r
40 * @param {Object} definition The item definition. The properties of this
\r
41 * object depend on the item type.
\r
43 * // Add a new button named "MyBold".
\r
44 * editorInstance.ui.add( 'MyBold', CKEDITOR.UI_BUTTON,
\r
46 * label : 'My Bold',
\r
50 add : function( name, type, definition )
\r
52 this._.items[ name ] =
\r
55 // The name of {@link CKEDITOR.command} which associate with this UI.
\r
56 command : definition.command || null,
\r
57 args : Array.prototype.slice.call( arguments, 2 )
\r
63 * @param {String} name The UI item hame.
\r
66 create : function( name )
\r
68 var item = this._.items[ name ],
\r
69 handler = item && this._.handlers[ item.type ],
\r
70 command = item && item.command && this._.editor.getCommand( item.command );
\r
72 var result = handler && handler.create.apply( this, item.args );
\r
74 // Add reference inside command object.
\r
76 command.uiItems.push( result );
\r
82 * Adds a handler for a UI item type. The handler is responsible for
\r
83 * transforming UI item definitions in UI objects.
\r
84 * @param {Object} type The item type.
\r
85 * @param {Object} handler The handler definition.
\r
88 addHandler : function( type, handler )
\r
90 this._.handlers[ type ] = handler;
\r
94 CKEDITOR.event.implementOn( CKEDITOR.ui );
\r
97 * (Virtual Class) Do not call this constructor. This class is not really part
\r
98 * of the API. It just illustrates the features of hanlder objects to be
\r
99 * passed to the {@link CKEDITOR.ui.prototype.addHandler} function.
\r
100 * @name CKEDITOR.ui.handlerDefinition
\r
106 * Transforms an item definition into an UI item object.
\r
107 * @name CKEDITOR.handlerDefinition.prototype.create
\r
109 * @param {Object} definition The item definition.
\r
111 * editorInstance.ui.addHandler( CKEDITOR.UI_BUTTON,
\r
113 * create : function( definition )
\r
115 * return new CKEDITOR.ui.button( definition );
\r
121 * Internal event fired when a new UI element is ready
\r
122 * @name CKEDITOR.ui#ready
\r
124 * @param {Object} element The new element
\r