JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0
[ckeditor.git] / _source / core / ui.js
diff --git a/_source/core/ui.js b/_source/core/ui.js
new file mode 100644 (file)
index 0000000..1d152e2
--- /dev/null
@@ -0,0 +1,106 @@
+/*\r
+Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+/**\r
+ * Contains UI features related to an editor instance.\r
+ * @constructor\r
+ * @param {CKEDITOR.editor} editor The editor instance.\r
+ * @example\r
+ */\r
+CKEDITOR.ui = function( editor )\r
+{\r
+       if ( editor.ui )\r
+               return editor.ui;\r
+\r
+       /**\r
+        * Object used to hold private stuff.\r
+        * @private\r
+        */\r
+       this._ =\r
+       {\r
+               handlers : {},\r
+               items : {}\r
+       };\r
+\r
+       return this;\r
+};\r
+\r
+// PACKAGER_RENAME( CKEDITOR.ui )\r
+\r
+CKEDITOR.ui.prototype =\r
+{\r
+       /**\r
+        * Adds a UI item to the items collection. These items can be later used in\r
+        * the interface.\r
+        * @param {String} name The UI item name.\r
+        * @param {Object} type The item type.\r
+        * @param {Object} definition The item definition. The properties of this\r
+        *              object depend on the item type.\r
+        * @example\r
+        * // Add a new button named "MyBold".\r
+        * editorInstance.ui.add( 'MyBold', CKEDITOR.UI_BUTTON,\r
+        *     {\r
+        *         label : 'My Bold',\r
+        *         command : 'bold'\r
+        *     });\r
+        */\r
+       add : function( name, type, definition )\r
+       {\r
+               this._.items[ name ] =\r
+               {\r
+                       type : type,\r
+                       args : Array.prototype.slice.call( arguments, 2 )\r
+               };\r
+       },\r
+\r
+       /**\r
+        * Gets a UI object.\r
+        * @param {String} name The UI item hame.\r
+        * @example\r
+        */\r
+       create : function( name )\r
+       {\r
+               var item        = this._.items[ name ],\r
+                       handler = item && this._.handlers[ item.type ];\r
+\r
+               return handler && handler.create.apply( this, item.args );\r
+       },\r
+\r
+       /**\r
+        * Adds a handler for a UI item type. The handler is responsible for\r
+        * transforming UI item definitions in UI objects.\r
+        * @param {Object} type The item type.\r
+        * @param {Object} handler The handler definition.\r
+        * @example\r
+        */\r
+       addHandler : function( type, handler )\r
+       {\r
+               this._.handlers[ type ] = handler;\r
+       }\r
+};\r
+\r
+/**\r
+ * (Virtual Class) Do not call this constructor. This class is not really part\r
+ *             of the API. It just illustrates the features of hanlder objects to be\r
+ *             passed to the {@link CKEDITOR.ui.prototype.addHandler} function.\r
+ * @name CKEDITOR.ui.handlerDefinition\r
+ * @constructor\r
+ * @example\r
+ */\r
+\r
+ /**\r
+ * Transforms an item definition into an UI item object.\r
+ * @name CKEDITOR.handlerDefinition.prototype.create\r
+ * @function\r
+ * @param {Object} definition The item definition.\r
+ * @example\r
+ * editorInstance.ui.addHandler( CKEDITOR.UI_BUTTON,\r
+ *     {\r
+ *         create : function( definition )\r
+ *         {\r
+ *             return new CKEDITOR.ui.button( definition );\r
+ *         }\r
+ *     });\r
+ */\r