4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
12 var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
15 * This class is base class for all menu types like DropMenus etc. This class should not
16 * be instantiated directly other menu controls should inherit from this one.
18 * @class tinymce.ui.Menu
19 * @extends tinymce.ui.MenuItem
21 tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', {
23 * Constructs a new button control instance.
27 * @param {String} id Button control id for the button.
28 * @param {Object} s Optional name/value settings object.
30 Menu : function(id, s) {
37 t.onAddItem = new tinymce.util.Dispatcher(this);
41 * Expands the menu, this will show them menu and all menu items.
44 * @param {Boolean} d Optional deep state. If this is set to true all children will be expanded as well.
46 expand : function(d) {
60 * Collapses the menu, this will hide the menu and all menu items.
63 * @param {Boolean} d Optional deep state. If this is set to true all children will be collapsed as well.
65 collapse : function(d) {
79 * Returns true/false if the menu has been collapsed or not.
82 * @return {Boolean} True/false state if the menu has been collapsed or not.
84 isCollapsed : function() {
85 return this.collapsed;
89 * Adds a new menu, menu item or sub classes of them to the drop menu.
92 * @param {tinymce.ui.Control} o Menu or menu item to add to the drop menu.
93 * @return {tinymce.ui.Control} Same as the input control, the menu or menu item.
97 o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o);
99 this.onAddItem.dispatch(this, o);
101 return this.items[o.id] = o;
105 * Adds a menu separator between the menu items.
107 * @method addSeparator
108 * @return {tinymce.ui.MenuItem} Menu item instance for the separator.
110 addSeparator : function() {
111 return this.add({separator : true});
115 * Adds a sub menu to the menu.
118 * @param {Object} o Menu control or a object with settings to be created into an control.
119 * @return {tinymce.ui.Menu} Menu control instance passed in or created.
121 addMenu : function(o) {
123 o = this.createMenu(o);
131 * Returns true/false if the menu has sub menus or not.
134 * @return {Boolean} True/false state if the menu has sub menues or not.
136 hasMenus : function() {
137 return this.menuCount !== 0;
141 * Removes a specific sub menu or menu item from the menu.
144 * @param {tinymce.ui.Control} o Menu item or menu to remove from menu.
145 * @return {tinymce.ui.Control} Control instance or null if it wasn't found.
147 remove : function(o) {
148 delete this.items[o.id];
152 * Removes all menu items and sub menu items from the menu.
156 removeAll : function() {
159 walk(t, function(o) {
172 * Created a new sub menu for the menu control.
175 * @param {Object} s Optional name/value settings object.
176 * @return {tinymce.ui.Menu} New drop menu instance.
178 createMenu : function(o) {
179 var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o);
181 m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem);