3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
7 Ext.onReady(function(){
10 // Menus can be prebuilt and passed by reference
11 var dateMenu = new Ext.menu.DateMenu({
12 handler: function(dp, date){
13 Ext.example.msg('Date Selected', 'You chose {0}.', date.format('M j, Y'));
17 var colorMenu = new Ext.menu.ColorMenu({
18 handler: function(cm, color){
19 Ext.example.msg('Color Selected', 'You chose {0}.', color);
23 var store = new Ext.data.ArrayStore({
24 fields: ['abbr', 'state'],
25 data : Ext.exampledata.states // from states.js
28 var combo = new Ext.form.ComboBox({
30 displayField: 'state',
34 emptyText: 'Select a state...',
37 getListParent: function() {
38 return this.el.up('.x-menu');
43 var menu = new Ext.menu.Menu({
46 overflow: 'visible' // For the Combo popup
49 combo, // A Field in a Menu
52 checked: true, // when checked has a boolean value, it is assumed to be a CheckItem
53 checkHandler: onItemCheck
55 text: 'Radio Options',
56 menu: { // <-- submenu by nested config object
58 // stick any markup in a menu
59 '<b class="menu-title">Choose a Theme</b>',
64 checkHandler: onItemCheck
69 checkHandler: onItemCheck
74 checkHandler: onItemCheck
76 text: 'Default Theme',
79 checkHandler: onItemCheck
84 text: 'Choose a Date',
86 menu: dateMenu // <-- submenu by reference
88 text: 'Choose a Color',
89 menu: colorMenu // <-- submenu by reference
94 var tb = new Ext.Toolbar();
98 text:'Button w/ Menu',
99 iconCls: 'bmenu', // <-- icon
100 menu: menu // assign menu by instance
102 new Ext.Toolbar.SplitButton({
103 text: 'Split Button',
104 handler: onButtonClick,
105 tooltip: {text:'This is a an example QuickTip for a toolbar item', title:'Tip Title'},
107 // Menus can be built/referenced by using nested menu config objects
110 text: '<b>Bold</b>', handler: onItemClick
112 text: '<i>Italic</i>', handler: onItemClick
114 text: '<u>Underline</u>', handler: onItemClick
116 text: 'Pick a Color',
117 handler: onItemClick,
120 new Ext.ColorPalette({
122 select: function(cp, color){
123 Ext.example.msg('Color Selected', 'You chose {0}.', color);
128 text: 'More Colors...',
141 toggleHandler: onItemToggle,
146 // Menus have a rich api for
147 // adding and removing elements dynamically
148 var item = menu.add({
149 text: 'Dynamically added Item'
151 // items support full Observable API
152 item.on('click', onItemClick);
154 // items can easily be looked up
156 text: 'Disabled Item',
157 id: 'disableMe' // <-- Items can also have an id for easy lookup
158 // disabled: true <-- allowed but for sake of example we use long way below
160 // access items by id or index
161 menu.items.get('disableMe').disable();
163 // They can also be referenced by id in or components
165 icon: 'list-items.gif', // icons can also be specified inline
167 tooltip: '<b>Quick Tips</b><br/>Icon only button with tooltip'
170 var scrollMenu = new Ext.menu.Menu();
171 for (var i = 0; i < 50; ++i){
173 text: 'Item ' + (i + 1)
179 cls: 'x-btn-text-icon',
180 text: 'Scrolling Menu',
184 // add a combobox to the toolbar
185 var combo = new Ext.form.ComboBox({
187 displayField: 'state',
190 triggerAction: 'all',
191 emptyText:'Select a state...',
199 // functions to display feedback
200 function onButtonClick(btn){
201 Ext.example.msg('Button Click','You clicked the "{0}" button.', btn.text);
204 function onItemClick(item){
205 Ext.example.msg('Menu Click', 'You clicked the "{0}" menu item.', item.text);
208 function onItemCheck(item, checked){
209 Ext.example.msg('Item Check', 'You {1} the "{0}" menu item.', item.text, checked ? 'checked' : 'unchecked');
212 function onItemToggle(item, pressed){
213 Ext.example.msg('Button Toggled', 'Button "{0}" was toggled to {1}.', item.text, pressed);