snappymail/dev/ViewModels/Popups/PopupsKeyboardShortcutsHelpViewModel.js

64 lines
1.5 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
2014-08-27 23:59:44 +08:00
kn = require('App:Knoin'),
KnoinAbstractViewModel = require('Knoin:AbstractViewModel')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsKeyboardShortcutsHelpViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsKeyboardShortcutsHelp');
this.sDefaultKeyScope = Enums.KeyState.PopupKeyboardShortcutsHelp;
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View:Popup:KeyboardShortcutsHelp', 'PopupsKeyboardShortcutsHelpViewModel'], PopupsKeyboardShortcutsHelpViewModel);
_.extend(PopupsKeyboardShortcutsHelpViewModel.prototype, KnoinAbstractViewModel.prototype);
2014-08-21 23:08:34 +08:00
PopupsKeyboardShortcutsHelpViewModel.prototype.onBuild = function (oDom)
{
key('tab, shift+tab, left, right', Enums.KeyState.PopupKeyboardShortcutsHelp, _.bind(function (event, handler) {
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-08-21 23:08:34 +08:00
}, this));
};
2014-08-22 23:08:56 +08:00
module.exports = PopupsKeyboardShortcutsHelpViewModel;
2014-09-05 06:49:03 +08:00
}());