Ext.JS: Global shortcuts (e.g. close current tab)

Permanent Link: Ext.JS: Global shortcuts (e.g. close current tab) 17. März 2010 RSS Feed for comments on RSS-Feed für Kommentare zu: Ext.JS: Global shortcuts (e.g. close current tab) comments feed

Ext.JS has an easy way of configuring keyboard shortcuts using Ext.KeyMap. If you wanna use global shortcuts you simply have to bind it to document. I wanna show you in an example how you can bind Alt+X to closing the current tab of a TabPanel layout accessible by the JavaScript variable tabPanelLayout.

new Ext.KeyMap(
document,
[
{
// Alt + X: Close current tab
key: 'x',
alt: true,
// Prevent any browser actions triggered by the shortcut that may occur
stopEvent: true,
fn: function() {
var activePanel = tabPanelLayout.getActiveTab();
Layout.closeTab(activePanel);
}
}
]
);

That's about it! If you only have this one shortcut, you can leave out the JS array.

3 comments


09.07.2010, 10:33 o'clock

But what if you have two tab panels in the same document? Wouldn't it be better to let the tab panel handle its own actions?

book author
s Gravatar

book author
04.10.2010, 09:10 o'clock

Wow, this was a really quality post. In theory I' d like to erase like this too - entrancing heyday and tangible effort to dream up a gigantic article… but what can I say… I procrastinate alot and in no mo = 'modus operandi' appear to get something done.

PHP Development Companys Gravatar

PHP Development Company
03.12.2011, 12:46 o'clock

Wow this keyword short cut technique is really great and the way of explanation is nice.

Write a comment

(will not be published)