3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
17 // TODO: The "Users" menu containing buttons is completely screwed: ButtonGroup needs work.
19 Ext.onReady(function(){
22 var dateMenu = Ext.create('Ext.menu.DatePicker', {
23 handler: function(dp, date){
24 Ext.example.msg('Date Selected', 'You choose {0}.', Ext.Date.format(date, 'M j, Y'));
29 var colorMenu = Ext.create('Ext.menu.ColorPicker', {
30 handler: function(cm, color){
31 Ext.example.msg('Color Selected', '<span style="color:#' + color + ';">You choose {0}.</span>', color);
35 var store = Ext.create('Ext.data.ArrayStore', {
36 fields: ['abbr', 'state'],
37 data : Ext.example.states
40 var combo = Ext.create('Ext.form.field.ComboBox', {
43 displayField: 'state',
47 emptyText: 'Select a state...',
53 var menu = Ext.create('Ext.menu.Menu', {
56 overflow: 'visible' // For the Combo popup
59 combo, // A Field in a Menu
62 checked: true, // when checked has a boolean value, it is assumed to be a CheckItem
63 checkHandler: onItemCheck
65 text: 'Radio Options',
66 menu: { // <-- submenu by nested config object
68 // stick any markup in a menu
69 '<b class="menu-title">Choose a Theme</b>',
74 checkHandler: onItemCheck
79 checkHandler: onItemCheck
84 checkHandler: onItemCheck
86 text: 'Default Theme',
89 checkHandler: onItemCheck
94 text: 'Choose a Date',
96 menu: dateMenu // <-- submenu by reference
98 text: 'Choose a Color',
99 menu: colorMenu // <-- submenu by reference
104 var tb = Ext.create('Ext.toolbar.Toolbar');
105 tb.suspendLayout = true;
106 tb.render('toolbar');
109 text:'Button w/ Menu',
110 iconCls: 'bmenu', // <-- icon
111 menu: menu // assign menu by instance
119 xtype: 'buttongroup',
120 title: 'User options',
128 text: 'User<br/>manager',
143 text: 'Who is online?',
150 Ext.create('Ext.button.Split', {
151 text: 'Split Button',
152 handler: onButtonClick,
153 tooltip: {text:'This is a an example QuickTip for a toolbar item', title:'Tip Title'},
155 // Menus can be built/referenced by using nested menu config objects
158 text: '<b>Bold</b>', handler: onItemClick
160 text: '<i>Italic</i>', handler: onItemClick
162 text: '<u>Underline</u>', handler: onItemClick
164 text: 'Pick a Color',
165 handler: onItemClick,
167 showSeparator: false,
169 Ext.create('Ext.ColorPalette', {
171 select: function(cp, color){
172 Ext.example.msg('Color Selected', 'You chose {0}.', color);
177 text: 'More Colors...',
190 toggleHandler: onItemToggle,
196 // Menus have a rich api for
197 // adding and removing elements dynamically
198 var item = menu.add({
199 text: 'Dynamically added Item'
201 // items support full Observable API
202 item.on('click', onItemClick);
204 // items can easily be looked up
206 text: 'Disabled Item',
207 id: 'disableMe' // <-- Items can also have an id for easy lookup
208 // disabled: true <-- allowed but for sake of example we use long way below
210 // access items by id or index
211 menu.items.get('disableMe').disable();
213 // They can also be referenced by id in or components
215 icon: 'list-items.gif', // icons can also be specified inline
217 tooltip: '<b>Quick Tips</b><br/>Icon only button with tooltip',
219 Ext.example.msg('Button Click','You clicked the "icon only" button.');
223 var scrollMenu = Ext.create('Ext.menu.Menu');
224 for (var i = 0; i < 50; ++i){
226 text: 'Item ' + (i + 1),
233 cls: 'x-btn-text-icon',
234 text: 'Scrolling Menu',
240 url: 'http://www.google.com/search',
244 tooltip: 'This is a link. You can right click. You can see where it will take you'
247 // add a combobox to the toolbar
248 var combo = Ext.create('Ext.form.field.ComboBox', {
251 displayField: 'state',
254 triggerAction: 'all',
255 emptyText:'Select a state...',
260 tb.suspendLayout = false;
263 // functions to display feedback
264 function onButtonClick(btn){
265 Ext.example.msg('Button Click','You clicked the "{0}" button.', btn.text);
268 function onItemClick(item){
269 Ext.example.msg('Menu Click', 'You clicked the "{0}" menu item.', item.text);
272 function onItemCheck(item, checked){
273 Ext.example.msg('Item Check', 'You {1} the "{0}" menu item.', item.text, checked ? 'checked' : 'unchecked');
276 function onItemToggle(item, pressed){
277 Ext.example.msg('Button Toggled', 'Button "{0}" was toggled to {1}.', item.text, pressed);