2014-04-08 05:03:58 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import _ from '_';
|
|
|
|
import key from 'key';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import {KeyState, Magics} from 'Common/Enums';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
import {popup} from 'Knoin/Knoin';
|
2016-08-17 06:01:20 +08:00
|
|
|
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
@popup({
|
2016-08-17 06:01:20 +08:00
|
|
|
name: 'View/Popup/KeyboardShortcutsHelp',
|
|
|
|
templateID: 'PopupsKeyboardShortcutsHelp'
|
|
|
|
})
|
|
|
|
class KeyboardShortcutsHelpPopupView extends AbstractViewNext
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.sDefaultKeyScope = KeyState.PopupKeyboardShortcutsHelp;
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onBuild(dom) {
|
|
|
|
key('tab, shift+tab, left, right', KeyState.PopupKeyboardShortcutsHelp, _.throttle((event, handler) => {
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (event && handler)
|
2014-04-13 08:32:07 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
const
|
|
|
|
$tabs = dom.find('.nav.nav-tabs > li'),
|
|
|
|
isNext = handler && ('tab' === handler.shortcut || 'right' === handler.shortcut);
|
|
|
|
|
|
|
|
let index = $tabs.index($tabs.filter('.active'));
|
|
|
|
if (!isNext && 0 < index)
|
|
|
|
{
|
|
|
|
index -= 1;
|
|
|
|
}
|
|
|
|
else if (isNext && index < $tabs.length - 1)
|
|
|
|
{
|
|
|
|
index += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
index = isNext ? 0 : $tabs.length - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tabs.eq(index).find('a[data-toggle="tab"]').tab('show');
|
|
|
|
return false;
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-07-01 06:50:11 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
return true;
|
2016-07-01 06:50:11 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
}, Magics.Time100ms));
|
|
|
|
}
|
|
|
|
}
|
2014-04-13 08:32:07 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
export {KeyboardShortcutsHelpPopupView, KeyboardShortcutsHelpPopupView as default};
|