Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var undef,
expect = chai.expect;

describe('DOM events', function() {
var Block1, Block2, Block3, block1, spy1, spy2, spy3, spy4, spy5, spy6, spy7, spy8,
var Block1, Block2, Block3, block1, spy1, spy2, spy3, spy4, spy5, spy6, spy7, spy8, spy9,
wrapSpy = function(spy) {
return function(e) {
// NOTE: we need to pass bemTarget and data explicitly, as `e` is being
Expand All @@ -26,6 +26,7 @@ describe('DOM events', function() {
spy6 = sinon.spy();
spy7 = sinon.spy();
spy8 = sinon.spy();
spy9 = sinon.spy();
});

afterEach(function() {
Expand Down Expand Up @@ -1038,6 +1039,38 @@ describe('DOM events', function() {
});
});
});

describe('window events', function() {
beforeEach(function() {
Block1 = bemDom.declBlock('block1', {}, {
onInit : function() {
this._domEvents(window).on('resize', spy9);
}
});

block1 = initBemEntity({ block : 'block1' }, Block1);
});

it('should properly bind handlers', function() {
windowDispatchEvent('resize');

spy9.should.have.been.called;
});

it('should properly unbind all handlers', function() {
Block1._domEvents(window).un('resize');
windowDispatchEvent('resize');

spy9.should.not.have.been.called;
});

it('should properly unbind specified handler', function() {
Block1._domEvents(window).un('resize', spy9);
windowDispatchEvent('resize');

spy9.should.not.have.been.called;
});
});
});
});

Expand Down
4 changes: 4 additions & 0 deletions common.blocks/i-bem-dom/__events/i-bem-dom__events.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ var undef,
} else {
do {
if(!targetDomNode) {
if(domNode === window) {
return { instance : window, targetDomNode : window };
}

if(domNode.classList.contains(params.bindClassName)) {
targetDomNode = domNode;
} else continue;
Expand Down
4 changes: 2 additions & 2 deletions common.blocks/i-bem-dom/i-bem-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ var BemDomEntity = inherit(/** @lends BemDomEntity.prototype */{
*/
_findParentEntities : function(entity, onlyFirst) {
return this._findEntities(entity, onlyFirst, function(domNode, _initEntity, className) {
while(domNode = domNode.parentNode)
if(domNode.classList && domNode.classList.contains(className) && !_initEntity(domNode))
while(domNode = domNode.parentElement)
if(domNode.classList.contains(className) && !_initEntity(domNode))
return false;
});
},
Expand Down