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 this._.items[ name ] = 52 { 53 type : type, 54 args : Array.prototype.slice.call( arguments, 2 ) 55 }; 56 }, 57 58 /** 59 * Gets a UI object. 60 * @param {String} name The UI item hame. 61 * @example 62 */ 63 create : function( name ) 64 { 65 var item = this._.items[ name ], 66 handler = item && this._.handlers[ item.type ]; 67 68 return handler && handler.create.apply( this, item.args ); 69 }, 70 71 /** 72 * Adds a handler for a UI item type. The handler is responsible for 73 * transforming UI item definitions in UI objects. 74 * @param {Object} type The item type. 75 * @param {Object} handler The handler definition. 76 * @example 77 */ 78 addHandler : function( type, handler ) 79 { 80 this._.handlers[ type ] = handler; 81 } 82 }; 83 84 /** 85 * (Virtual Class) Do not call this constructor. This class is not really part 86 * of the API. It just illustrates the features of hanlder objects to be 87 * passed to the {@link CKEDITOR.ui.prototype.addHandler} function. 88 * @name CKEDITOR.ui.handlerDefinition 89 * @constructor 90 * @example 91 */ 92 93 /** 94 * Transforms an item definition into an UI item object. 95 * @name CKEDITOR.handlerDefinition.prototype.create 96 * @function 97 * @param {Object} definition The item definition. 98 * @example 99 * editorInstance.ui.addHandler( CKEDITOR.UI_BUTTON, 100 * { 101 * create : function( definition ) 102 * { 103 * return new CKEDITOR.ui.button( definition ); 104 * } 105 * }); 106 */ 107