Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
BaseElement.prototype._initHandlers = function () {
var self = this;
self.on('focus', function () {
logger.debug('focus', util.typeOf(self));
if (!self.focusable) self.focusNext();
});
self.on('blur', function () { logger.debug('blur', util.typeOf(self)); });
self.on('show', function () { self.setFront(); });
self.on('keypress', _.noop); // 'element keypress' doesn't work correctly without this
self.on('element keypress', function (el, ch, key) {
switch (util.getBinding(self.options.bindings, key)) {
case 'hide': self.hide(); return false;
case 'focusNext': self.focusNext(); return false;
case 'focusPrev': self.focusPrev(); return false;
}
});
};
.filter(function (child) { return child instanceof BaseModal; })
.without(self);
self.on('element blur', function () {
if (!self.screen.focused.hasAncestor(self) && self.screen.focused !== self) self.hide();
});
self.on('click', function () {
process.nextTick(function () {
// TODO: don't change focus if contained element has focus already
var firstChild = self.children[0];
if (firstChild) firstChild.focus();
});
});
self.on('keypress', _.noop); // 'element keypress' doesn't work correctly without this
self.on('element keypress', function (el, ch, key) {
switch (util.getBinding(self.options.bindings, key)) {
case 'hide': self.hide(); break;
case 'focusNext': self.focusEl(1); break;
case 'focusPrev': self.focusEl(-1); break;
}
});
self.on('show', function () {
self.otherModals.invoke('hide');
// if (self.otherModals.pluck('visible').compact().none()) self.screen.saveFocus();
process.nextTick(function () { self.parent.render(); });
});
self.on('hide', function () {
if (self.otherModals.pluck('visible').compact().none()) {
self.parent.lockKeys = true; process.nextTick(function () { self.parent.lockKeys = false; }); // FIXME: ugly hack to stop enter from last event from propagating to editor