Skip to content

Commit

Permalink
Do not add i-bem class to element with js
Browse files Browse the repository at this point in the history
This reverts commit e4d41c4.
  • Loading branch information
mishanga committed Jan 28, 2015
1 parent 274aeeb commit 3b06fd8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/bh.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,8 @@ BH.prototype = {
}
}

var addJSInitClass = jsParams && !json.elem;

var mixes = json.mix;
if (mixes && mixes.length) {
for (i = 0, l = mixes.length; i < l; i++) {
Expand All @@ -948,14 +950,15 @@ BH.prototype = {
if (mix.js) {
(jsParams = jsParams || {})[mixBase] = mix.js === true ? {} : mix.js;
hasMixJsParams = true;
if (!addJSInitClass) addJSInitClass = mixBlock && !mixElem;
}
}
}
}
}

if (jsParams) {
cls = cls + ' i-bem';
if (addJSInitClass) cls += ' i-bem';
var jsData = (!hasMixJsParams && json.js === true ?
'{&quot;' + base + '&quot;:{}}' :
attrEscape(JSON.stringify(jsParams)));
Expand Down
7 changes: 7 additions & 0 deletions test/test.js.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,36 @@ describe('ctx.js()', function() {
beforeEach(function() {
bh = new BH();
});

it('should return js', function() {
bh.match('button', function(ctx) {
ctx.js().should.equal(true);
});
bh.apply({ block: 'button', js: true });
});

it('should set js', function() {
bh.match('button', function(ctx) {
ctx.js(true);
});
bh.apply({ block: 'button' }).should.equal('<div class="button i-bem" onclick="return {&quot;button&quot;:{}}"></div>');
});

it('should not set js', function() {
bh.match('button', function(ctx) {
ctx.js(false);
});
bh.apply({ block: 'button' }).should.equal('<div class="button"></div>');
});

it('should extend user js', function() {
bh.match('button', function(ctx) {
ctx.js({ a: 2 });
});
bh.apply({ block: 'button', js: { x: 1 } })
.should.equal('<div class="button i-bem" onclick="return {&quot;button&quot;:{&quot;x&quot;:1,&quot;a&quot;:2}}"></div>');
});

it('should not override later declarations', function() {
bh.match('button', function(ctx) {
ctx.js(false);
Expand All @@ -40,6 +45,7 @@ describe('ctx.js()', function() {
});
bh.apply({ block: 'button' }).should.equal('<div class="button i-bem" onclick="return {&quot;button&quot;:{}}"></div>');
});

it('should override later declarations with force flag', function() {
bh.match('button', function(ctx) {
ctx.js(true, true);
Expand All @@ -49,6 +55,7 @@ describe('ctx.js()', function() {
});
bh.apply({ block: 'button' }).should.equal('<div class="button i-bem" onclick="return {&quot;button&quot;:{}}"></div>');
});

it('should override user declarations with force flag', function() {
bh.match('button', function(ctx) {
ctx.js(false, true);
Expand Down
8 changes: 4 additions & 4 deletions test/test.toHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,13 @@ describe('bh.toHtml()', function() {
beforeEach(function() {
bh = new BH();
});
it('should set `i-bem` class on element', function() {
it('should not set `i-bem` class on element', function() {
bh.apply({ block: 'button', elem: 'control', js: true, content: 'submit' }).should.equal(
'<div class="button__control i-bem" onclick="return {&quot;button__control&quot;:{}}">submit</div>');
'<div class="button__control" onclick="return {&quot;button__control&quot;:{}}">submit</div>');
});
it('should set `i-bem` class on mixed element', function() {
it('should not set `i-bem` class on mixed element', function() {
bh.apply({ block: 'icon', content: 'submit', mix: { block: 'button', elem: 'control', js: true } }).should.equal(
'<div class="icon button__control i-bem" onclick="return {&quot;button__control&quot;:{}}">submit</div>');
'<div class="icon button__control" onclick="return {&quot;button__control&quot;:{}}">submit</div>');
});
});

Expand Down

0 comments on commit 3b06fd8

Please sign in to comment.