Skip to content

Commit

Permalink
Merge pull request #1383 from /issues/1381@v2
Browse files Browse the repository at this point in the history
menu: two _onKeyDown handler binds if block is inited on focus (close #1381)
  • Loading branch information
dfilatov committed Mar 2, 2015
2 parents 2f9ca2f + 0b3a348 commit 84a9124
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
4 changes: 2 additions & 2 deletions common.blocks/control/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ provide(BEMDOM.decl(this.name, /** @lends control.prototype */{
'inited' : function() {
this._focused = dom.containsFocus(this.elem('control'));
this._focused?
// if control is already in focus, we need to set focused mod
this.setMod('focused') :
// if control is already in focus, we need to force _onFocus
this._onFocus() :
// if block already has focused mod, we need to focus control
this.hasMod('focused') && this._focus();

Expand Down
36 changes: 17 additions & 19 deletions common.blocks/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,6 @@ provide(BEMDOM.decl({ block : this.name, baseBlock : Control }, /** @lends menu.
index : 0,
time : 0
};

this.hasMod('focused') && this.bindToDoc('keydown', this._onKeyDown);
}
},

'focused' : {
'true' : function() {
this.__base.apply(this, arguments);
this
.bindToDoc('keydown', this._onKeyDown) // NOTE: should be called after __base
.bindToDoc('keypress', this._onKeyPress);
},

'' : function() {
this
.unbindFromDoc('keydown', this._onKeyDown)
.unbindFromDoc('keypress', this._onKeyPress)
.__base.apply(this, arguments);
this._hoveredItem && this._hoveredItem.delMod('hovered');
}
},

Expand Down Expand Up @@ -131,6 +112,23 @@ provide(BEMDOM.decl({ block : this.name, baseBlock : Control }, /** @lends menu.
return null;
},

/** @override **/
_onFocus : function() {
this.__base.apply(this, arguments);
this
.bindToDoc('keydown', this._onKeyDown) // NOTE: should be called after __base
.bindToDoc('keypress', this._onKeyPress);
},

/** @override **/
_onBlur : function() {
this
.unbindFromDoc('keydown', this._onKeyDown)
.unbindFromDoc('keypress', this._onKeyPress)
.__base.apply(this, arguments);
this._hoveredItem && this._hoveredItem.delMod('hovered');
},

_onItemHover : function(item) {
if(item.hasMod('hovered')) {
this._hoveredItem && this._hoveredItem.delMod('hovered');
Expand Down

0 comments on commit 84a9124

Please sign in to comment.