1 /* 2 * CKEditor - The text editor for Internet - http://ckeditor.com 3 * Copyright (C) 2003-2008 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 */ 21 22 /** 23 * Contains UI features related to an editor instance. 24 * @constructor 25 * @param {CKEDITOR.editor} editor The editor instance. 26 * @example 27 */ 28 CKEDITOR.ui = function( editor ) 29 { 30 if ( editor.ui ) 31 return editor.ui; 32 33 this._ = 34 { 35 handlers : {}, 36 items : {} 37 }; 38 39 return this; 40 }; 41 42 CKEDITOR.ui.prototype = 43 { 44 /** 45 * Adds a UI item to the items collection. These items can be later used in 46 * the interface. 47 * @param {String} name The UI item name. 48 * @param {Object} type The item type. 49 * @param {Object} definition The item definition. The properties of this 50 * object depend on the item type. 51 * @example 52 * // Add a new button named "MyBold". 53 * editorInstance.ui.add( 'MyBold', CKEDITOR.UI_BUTTON, 54 * { 55 * label : 'My Bold', 56 * command : 'bold' 57 * }); 58 */ 59 add : function( name, type, definition ) 60 { 61 var item = this._.handlers[ type ].create( definition ); 62 item.name = name; 63 this._.items[ name ] = item; 64 }, 65 66 /** 67 * Gets a UI object. 68 * @param {String} name The UI item hame. 69 * @example 70 */ 71 get : function( name ) 72 { 73 return this._.items[ name ] || null; 74 }, 75 76 /** 77 * Adds a handler for a UI item type. The handler is responsible for 78 * transforming UI item definitions in UI objects. 79 * @param {Object} type The item type. 80 * @param {Object} handler The handler definition. 81 * @example 82 */ 83 addHandler : function( type, handler ) 84 { 85 this._.handlers[ type ] = handler; 86 } 87 }; 88 89 /** 90 * (Virtual Class) Do not call this constructor. This class is not really part 91 * of the API. It just illustrates the features of hanlder objects to be 92 * passed to the {@link CKEDITOR.ui.prototype.addHandler} function. 93 * @name CKEDITOR.ui.handlerDefinition 94 * @constructor 95 * @example 96 */ 97 98 /** 99 * Transforms an item definition into an UI item object. 100 * @name CKEDITOR.handlerDefinition.prototype.create 101 * @function 102 * @param {Object} definition The item definition. 103 * @example 104 * editorInstance.ui.addHandler( CKEDITOR.UI_BUTTON, 105 * { 106 * create : function( definition ) 107 * { 108 * return new CKEDITOR.ui.button( definition ); 109 * } 110 * }); 111 */ 112