snappymail/dev/View/Popup/KeyboardShortcutsHelp.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-08-14 04:58:41 +08:00
import { KeyState } from 'Common/Enums';
2016-06-30 08:02:45 +08:00
2019-07-05 03:19:24 +08:00
import { popup } from 'Knoin/Knoin';
import { AbstractViewNext } from 'Knoin/AbstractViewNext';
2016-06-30 08:02:45 +08:00
2016-09-10 06:38:16 +08:00
@popup({
name: 'View/Popup/KeyboardShortcutsHelp',
templateID: 'PopupsKeyboardShortcutsHelp'
})
2019-07-05 03:19:24 +08:00
class KeyboardShortcutsHelpPopupView extends AbstractViewNext {
constructor() {
super();
this.sDefaultKeyScope = KeyState.PopupKeyboardShortcutsHelp;
}
2016-06-30 08:02:45 +08:00
onBuild(dom) {
dom.querySelectorAll('a[data-toggle="tab"]').forEach(node => node.Tab || new BSN.Tab(node));
2019-07-05 03:19:24 +08:00
key(
'tab, shift+tab, left, right',
KeyState.PopupKeyboardShortcutsHelp,
((event, handler)=>{
if (event && handler) {
const tabs = dom.querySelectorAll('.nav.nav-tabs > li'),
last = tabs.length - 1;
let next = 0;
tabs.forEach((node, index) => {
if (node.matches('.active')) {
if (['tab','right'].includes(handler.shortcut)) {
next = index < last ? index+1 : 0;
} else {
next = index ? index-1 : last;
}
}
});
tabs[next].querySelector('a[data-toggle="tab"]').Tab.show();
}
}).throttle(100)
2019-07-05 03:19:24 +08:00
);
}
}
2019-07-05 03:19:24 +08:00
export { KeyboardShortcutsHelpPopupView, KeyboardShortcutsHelpPopupView as default };