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 /** 7 * Contains UI features related to an editor instance. 8 * @constructor 9 * @param {CKEDITOR.editor} editor The editor instance. 10 * @example 11 */ 12 CKEDITOR.ui = function( editor ) 13 { 14 if ( editor.ui ) 15 return editor.ui; 16 17 /** 18 * Object used to hold private stuff. 19 * @private 20 */ 21 this._ = 22 { 23 handlers : {}, 24 items : {} 25 }; 26 27 return this; 28 }; 29 30 // PACKAGER_RENAME( CKEDITOR.ui ) 31 32 CKEDITOR.ui.prototype = 33 { 34 /** 35 * Adds a UI item to the items collection. These items can be later used in 36 * the interface. 37 * @param {String} name The UI item name. 38 * @param {Object} type The item type. 39 * @param {Object} definition The item definition. The properties of this 40 * object depend on the item type. 41 * @example 42 * // Add a new button named "MyBold". 43 * editorInstance.ui.add( 'MyBold', CKEDITOR.UI_BUTTON, 44 * { 45 * label : 'My Bold', 46 * command : 'bold' 47 * }); 48 */ 49 add : function( name, type, definition ) 50 { 51 var item = this._.handlers[ type ].create( definition ); 52 item.name = name; 53 this._.items[ name ] = item; 54 }, 55 56 /** 57 * Gets a UI object. 58 * @param {String} name The UI item hame. 59 * @example 60 */ 61 get : function( name ) 62 { 63 return this._.items[ name ] || null; 64 }, 65 66 /** 67 * Adds a handler for a UI item type. The handler is responsible for 68 * transforming UI item definitions in UI objects. 69 * @param {Object} type The item type. 70 * @param {Object} handler The handler definition. 71 * @example 72 */ 73 addHandler : function( type, handler ) 74 { 75 this._.handlers[ type ] = handler; 76 } 77 }; 78 79 /** 80 * (Virtual Class) Do not call this constructor. This class is not really part 81 * of the API. It just illustrates the features of hanlder objects to be 82 * passed to the {@link CKEDITOR.ui.prototype.addHandler} function. 83 * @name CKEDITOR.ui.handlerDefinition 84 * @constructor 85 * @example 86 */ 87 88 /** 89 * Transforms an item definition into an UI item object. 90 * @name CKEDITOR.handlerDefinition.prototype.create 91 * @function 92 * @param {Object} definition The item definition. 93 * @example 94 * editorInstance.ui.addHandler( CKEDITOR.UI_BUTTON, 95 * { 96 * create : function( definition ) 97 * { 98 * return new CKEDITOR.ui.button( definition ); 99 * } 100 * }); 101 */ 102