Small refactoring (popup key scope optimization)

This commit is contained in:
RainLoop Team 2014-04-08 02:36:38 +04:00
parent 77cdc4690b
commit a96e1d80c3
22 changed files with 226 additions and 254 deletions

View file

@ -11,6 +11,9 @@ function KnoinAbstractViewModel(sPosition, sTemplate)
this.sPosition = Utils.pString(sPosition);
this.sTemplate = Utils.pString(sTemplate);
this.sDefaultKeyScope = Enums.KeyState.None;
this.sCurrentKeyScope = this.sDefaultKeyScope;
this.viewModelName = '';
this.viewModelVisibility = ko.observable(false);
if ('Popups' === this.sPosition)
@ -61,13 +64,27 @@ KnoinAbstractViewModel.prototype.cancelCommand = KnoinAbstractViewModel.prototyp
{
};
KnoinAbstractViewModel.prototype.storeAndSetKeyScope = function ()
{
this.sCurrentKeyScope = RL.data().keyScope();
RL.data().keyScope(this.sDefaultKeyScope);
};
KnoinAbstractViewModel.prototype.restoreKeyScope = function ()
{
RL.data().keyScope(this.sCurrentKeyScope);
};
KnoinAbstractViewModel.prototype.registerPopupEscapeKey = function ()
{
key('esc', _.bind(function () {
if (this.modalVisibility && this.modalVisibility())
var self = this;
$window.on('keydown', function (oEvent) {
if (oEvent && Enums.EventKeyCode.Esc === oEvent.keyCode && self.modalVisibility && self.modalVisibility())
{
Utils.delegateRun(this, 'cancelCommand');
Utils.delegateRun(self, 'cancelCommand');
return false;
}
}, this));
return true;
});
};

View file

@ -143,6 +143,7 @@ Knoin.prototype.hideScreenPopup = function (ViewModelClassToHide)
{
ViewModelClassToHide.__vm.modalVisibility(false);
Utils.delegateRun(ViewModelClassToHide.__vm, 'onHide');
ViewModelClassToHide.__vm.restoreKeyScope();
RL.popupVisibilityNames.remove(ViewModelClassToHide.__name);
@ -168,8 +169,10 @@ Knoin.prototype.showScreenPopup = function (ViewModelClassToShow, aParameters)
{
ViewModelClassToShow.__dom.show();
ViewModelClassToShow.__vm.modalVisibility(true);
Utils.delegateRun(ViewModelClassToShow.__vm, 'onShow', aParameters || []);
ViewModelClassToShow.__vm.storeAndSetKeyScope();
RL.popupVisibilityNames.push(ViewModelClassToShow.__name);
Plugins.runHook('view-model-on-show', [ViewModelClassToShow.__name, ViewModelClassToShow.__vm, aParameters || []]);