1 | /*
|
---|
2 | Copyright (c) 2003-2010, 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 | editor : editor
|
---|
26 | };
|
---|
27 |
|
---|
28 | return this;
|
---|
29 | };
|
---|
30 |
|
---|
31 | // PACKAGER_RENAME( CKEDITOR.ui )
|
---|
32 |
|
---|
33 | CKEDITOR.ui.prototype =
|
---|
34 | {
|
---|
35 | /**
|
---|
36 | * Adds a UI item to the items collection. These items can be later used in
|
---|
37 | * the interface.
|
---|
38 | * @param {String} name The UI item name.
|
---|
39 | * @param {Object} type The item type.
|
---|
40 | * @param {Object} definition The item definition. The properties of this
|
---|
41 | * object depend on the item type.
|
---|
42 | * @example
|
---|
43 | * // Add a new button named "MyBold".
|
---|
44 | * editorInstance.ui.add( 'MyBold', CKEDITOR.UI_BUTTON,
|
---|
45 | * {
|
---|
46 | * label : 'My Bold',
|
---|
47 | * command : 'bold'
|
---|
48 | * });
|
---|
49 | */
|
---|
50 | add : function( name, type, definition )
|
---|
51 | {
|
---|
52 | this._.items[ name ] =
|
---|
53 | {
|
---|
54 | type : type,
|
---|
55 | // The name of {@link CKEDITOR.command} which associate with this UI.
|
---|
56 | command : definition.command || null,
|
---|
57 | args : Array.prototype.slice.call( arguments, 2 )
|
---|
58 | };
|
---|
59 | },
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Gets a UI object.
|
---|
63 | * @param {String} name The UI item hame.
|
---|
64 | * @example
|
---|
65 | */
|
---|
66 | create : function( name )
|
---|
67 | {
|
---|
68 | var item = this._.items[ name ],
|
---|
69 | handler = item && this._.handlers[ item.type ],
|
---|
70 | command = item && item.command && this._.editor.getCommand( item.command );
|
---|
71 |
|
---|
72 | var result = handler && handler.create.apply( this, item.args );
|
---|
73 |
|
---|
74 | // Add reference inside command object.
|
---|
75 | if ( command )
|
---|
76 | command.uiItems.push( result );
|
---|
77 |
|
---|
78 | return result;
|
---|
79 | },
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Adds a handler for a UI item type. The handler is responsible for
|
---|
83 | * transforming UI item definitions in UI objects.
|
---|
84 | * @param {Object} type The item type.
|
---|
85 | * @param {Object} handler The handler definition.
|
---|
86 | * @example
|
---|
87 | */
|
---|
88 | addHandler : function( type, handler )
|
---|
89 | {
|
---|
90 | this._.handlers[ type ] = handler;
|
---|
91 | }
|
---|
92 | };
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * (Virtual Class) Do not call this constructor. This class is not really part
|
---|
96 | * of the API. It just illustrates the features of hanlder objects to be
|
---|
97 | * passed to the {@link CKEDITOR.ui.prototype.addHandler} function.
|
---|
98 | * @name CKEDITOR.ui.handlerDefinition
|
---|
99 | * @constructor
|
---|
100 | * @example
|
---|
101 | */
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Transforms an item definition into an UI item object.
|
---|
105 | * @name CKEDITOR.handlerDefinition.prototype.create
|
---|
106 | * @function
|
---|
107 | * @param {Object} definition The item definition.
|
---|
108 | * @example
|
---|
109 | * editorInstance.ui.addHandler( CKEDITOR.UI_BUTTON,
|
---|
110 | * {
|
---|
111 | * create : function( definition )
|
---|
112 | * {
|
---|
113 | * return new CKEDITOR.ui.button( definition );
|
---|
114 | * }
|
---|
115 | * });
|
---|
116 | */
|
---|