2021-03-16 23:06:16 +08:00
|
|
|
import { Scope } from 'Common/Enums';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-01-24 17:25:23 +08:00
|
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-01-24 17:25:23 +08:00
|
|
|
class KeyboardShortcutsHelpPopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('KeyboardShortcutsHelp');
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onBuild(dom) {
|
2020-08-30 16:30:50 +08:00
|
|
|
dom.querySelectorAll('a[data-toggle="tab"]').forEach(node => node.Tab || new BSN.Tab(node));
|
|
|
|
|
2020-09-26 06:02:29 +08:00
|
|
|
// shortcuts.add('tab', 'shift',
|
2020-09-26 16:20:24 +08:00
|
|
|
shortcuts.add('tab,arrowleft,arrowright', '',
|
2021-03-16 23:06:16 +08:00
|
|
|
Scope.KeyboardShortcutsHelp,
|
2020-08-19 02:24:17 +08:00
|
|
|
((event, handler)=>{
|
|
|
|
if (event && handler) {
|
2020-08-30 16:30:50 +08:00
|
|
|
const tabs = dom.querySelectorAll('.nav.nav-tabs > li'),
|
|
|
|
last = tabs.length - 1;
|
|
|
|
let next = 0;
|
|
|
|
tabs.forEach((node, index) => {
|
|
|
|
if (node.matches('.active')) {
|
2020-09-26 06:02:29 +08:00
|
|
|
if (['tab','arrowright'].includes(handler.shortcut)) {
|
2020-08-30 16:30:50 +08:00
|
|
|
next = index < last ? index+1 : 0;
|
|
|
|
} else {
|
|
|
|
next = index ? index-1 : last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-07-30 03:49:41 +08:00
|
|
|
|
2020-08-30 16:30:50 +08:00
|
|
|
tabs[next].querySelector('a[data-toggle="tab"]').Tab.show();
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2020-08-19 02:24:17 +08:00
|
|
|
}).throttle(100)
|
2019-07-05 03:19:24 +08:00
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
}
|
2014-04-13 08:32:07 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { KeyboardShortcutsHelpPopupView, KeyboardShortcutsHelpPopupView as default };
|