Skip to content

Commit 105e5f3

Browse files
committed
Fix multiple events subscription
1 parent fac560e commit 105e5f3

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

common.blocks/i-bem-dom/__events/_type/i-bem-dom__events_type_bem.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ var EVENT_PREFIX = '__bem__',
3737
var event = EVENT_PREFIX + params.bindEntityCls.getEntityName() +
3838
(typeof e === 'object'?
3939
e instanceof events.Event?
40-
' ' + e.type :
40+
':' + e.type :
4141
bemInternal.buildModPostfix(e.modName, e.modVal) :
42-
' ' + e);
42+
':' + e);
4343

4444
eventMethod === 'on' && // TODO: count usage and remove on 'un'
4545
!eventsInUse[event] &&

common.blocks/i-bem-dom/__events/_type/i-bem-dom__events_type_dom.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('DOM events', function() {
4444
'js' : {
4545
'inited' : function() {
4646
this._domEvents()
47-
.on('click', spy1)
47+
.on('click keypress', spy1)
4848
.on('click', spy2)
4949
.on('click', data, wrapSpy(spy3))
5050
.once('click', spy4);

common.blocks/i-bem-dom/__events/i-bem-dom__events.js

+16
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ var undef,
5252
* @returns {EventManager} this
5353
*/
5454
on : function(e, data, fn, _fnCtx, _isOnce) {
55+
if(typeof e === 'string' && e.indexOf(' ') > -1) {
56+
e.split(' ').forEach(function(event) {
57+
this.on(event, data, fn, _fnCtx, _isOnce);
58+
}, this);
59+
60+
return this;
61+
}
62+
5563
var params = this._params,
5664
event = this._eventBuilder(e, params, 'on');
5765

@@ -114,6 +122,14 @@ var undef,
114122
un : function(e, fn, _fnCtx) {
115123
var argsLen = arguments.length;
116124
if(argsLen) {
125+
if(typeof e === 'string' && e.indexOf(' ') > -1) {
126+
e.split(' ').forEach(function(event) {
127+
this.un(event, fn, _fnCtx);
128+
}, this);
129+
130+
return this;
131+
}
132+
117133
var params = this._params,
118134
event = this._eventBuilder(e, params, 'un');
119135

0 commit comments

Comments
 (0)