snappymail/dev/View/Popup/KeyboardShortcutsHelp.js

64 lines
1.4 KiB
JavaScript
Raw Normal View History

2014-09-05 06:49:03 +08:00
(function () {
2014-08-25 23:49:01 +08:00
'use strict';
2014-08-21 23:08:34 +08:00
var
2014-08-25 23:49:01 +08:00
_ = require('_'),
key = require('key'),
2014-08-25 15:10:51 +08:00
2014-09-05 06:49:03 +08:00
Enums = require('Common/Enums'),
2014-08-25 15:10:51 +08:00
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
* @extends AbstractView
2014-08-21 23:08:34 +08:00
*/
function KeyboardShortcutsHelpPopupView()
2014-08-21 23:08:34 +08:00
{
AbstractView.call(this, 'Popups', 'PopupsKeyboardShortcutsHelp');
2014-08-21 23:08:34 +08:00
this.sDefaultKeyScope = Enums.KeyState.PopupKeyboardShortcutsHelp;
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View/Popup/KeyboardShortcutsHelp', 'PopupsKeyboardShortcutsHelpViewModel'], KeyboardShortcutsHelpPopupView);
_.extend(KeyboardShortcutsHelpPopupView.prototype, AbstractView.prototype);
2014-08-21 23:08:34 +08:00
KeyboardShortcutsHelpPopupView.prototype.onBuild = function (oDom)
2014-08-21 23:08:34 +08:00
{
2014-10-06 02:37:31 +08:00
key('tab, shift+tab, left, right', Enums.KeyState.PopupKeyboardShortcutsHelp, _.throttle(_.bind(function (event, handler) {
2014-08-21 23:08:34 +08:00
if (event && handler)
{
2014-08-21 23:08:34 +08:00
var
$tabs = oDom.find('.nav.nav-tabs > li'),
bNext = handler && ('tab' === handler.shortcut || 'right' === handler.shortcut),
iIndex = $tabs.index($tabs.filter('.active'))
;
if (!bNext && iIndex > 0)
{
iIndex--;
}
else if (bNext && iIndex < $tabs.length - 1)
{
iIndex++;
}
else
{
iIndex = bNext ? 0 : $tabs.length - 1;
}
$tabs.eq(iIndex).find('a[data-toggle="tab"]').tab('show');
return false;
}
2014-10-06 02:37:31 +08:00
}, this), 100));
2014-08-21 23:08:34 +08:00
};
module.exports = KeyboardShortcutsHelpPopupView;
2014-09-05 06:49:03 +08:00
}());