Repository: bem/bh
Pull request #122 (2015-03-13 07:39:15)

Class `i-bem` on elems with `js`

coveralls: 
[![Coverage Status](https://coveralls.io/builds/2105554/badge)](https://coveralls.io/builds/2105554)

Coverage increased (+0.0%) to 99.73% when pulling **b1c4fad85431e94ace21b1ee407fa22d7a0e93d6 on jselem** into **c1bd8461b2d26a19b95d8018979eefd847eb0fb4 on master**.

mishanga: /cc @denchistyakov @matmuchrapna @narqo 
Для bem-core@v3 потребовалось обратно вернуть класс i-bem на элементах.
mishanga: @xdghcnt

Patch:
diff --git a/lib/bh.js b/lib/bh.js
index 8bd12a3..7d56f14 100644
--- a/lib/bh.js
+++ b/lib/bh.js
@@ -47,6 +47,7 @@ function BH() {
     this._options = {};
     this._optJsAttrName = 'onclick';
     this._optJsAttrIsJs = true;
+    this._optJsCls = 'i-bem';
     this._optEscapeContent = false;
     this.utils = {
         _expandoId: new Date().getTime(),
@@ -559,6 +560,9 @@ BH.prototype = {
         if (options.jsAttrScheme) {
             this._optJsAttrIsJs = options.jsAttrScheme === 'js';
         }
+        if (options.jsCls !== undefined) {
+            this._optJsCls = options.jsCls;
+        }
         if (options.escapeContent) {
             this._optEscapeContent = options.escapeContent;
         }
@@ -936,8 +940,6 @@ BH.prototype = {
                     }
                 }
 
-                var addJSInitClass = jsParams && !json.elem;
-
                 var mixes = json.mix;
                 if (mixes && mixes.length) {
                     for (i = 0, l = mixes.length; i < l; i++) {
@@ -952,7 +954,6 @@ BH.prototype = {
                                 if (mix.js) {
                                     (jsParams = jsParams || {})[mixBase] = mix.js === true ? {} : mix.js;
                                     hasMixJsParams = true;
-                                    if (!addJSInitClass) addJSInitClass = mixBlock && !mixElem;
                                 }
                             }
                         }
@@ -960,7 +961,7 @@ BH.prototype = {
                 }
 
                 if (jsParams) {
-                    if (addJSInitClass) cls += ' i-bem';
+                    if (this._optJsCls) cls += ' ' + this._optJsCls;
                     var jsData = (!hasMixJsParams && json.js === true ?
                         '{"' + base + '":{}}' :
                         jsAttrEscape(JSON.stringify(jsParams)));


Test patch:
diff --git a/test/test.options.js b/test/test.options.js
index f8f0523..3556605 100644
--- a/test/test.options.js
+++ b/test/test.options.js
@@ -7,15 +7,18 @@ describe('options', function() {
         beforeEach(function() {
             bh = new BH();
         });
+
         it('should use onclick and js format as default', function() {
             bh.apply({ block: 'button', js: true }).should.equal(
                 '<div class="button i-bem" onclick=\'return {"button":{}}\'></div>'
             );
         });
+
         it('should return current options', function() {
             bh.setOptions({ foo: 'bar' });
             bh.getOptions().foo.should.equal('bar');
         });
+
         it('should use js format as default and use jsAttrName option', function() {
             bh.setOptions({
                 jsAttrName: 'ondblclick'
@@ -24,6 +27,7 @@ describe('options', function() {
                 '<div class="button i-bem" ondblclick=\'return {"button":{}}\'></div>'
             );
         });
+
         it('should use onclick as default and use jsAttrScheme option', function() {
             bh.setOptions({
                 jsAttrScheme: 'json'
@@ -32,6 +36,7 @@ describe('options', function() {
                 '<div class="button i-bem" onclick=\'{"button":{}}\'></div>'
             );
         });
+
         it('should use jsAttrName and jsAttrScheme options', function() {
             bh.setOptions({
                 jsAttrName: 'data-bem',
@@ -41,5 +46,19 @@ describe('options', function() {
                 '<div class="button i-bem" data-bem=\'{"button":{}}\'></div>'
             );
         });
+
+        it('should use jsCls option', function() {
+            bh.setOptions({ jsCls: 'js' });
+            bh.apply({ block: 'button', js: true }).should.equal(
+                '<div class="button js" onclick=\'return {"button":{}}\'></div>'
+            );
+        });
+
+        it('should use empty jsCls option', function() {
+            bh.setOptions({ jsCls: false });
+            bh.apply({ block: 'button', js: true }).should.equal(
+                '<div class="button" onclick=\'return {"button":{}}\'></div>'
+            );
+        });
     });
 });
diff --git a/test/test.toHtml.js b/test/test.toHtml.js
index 552c007..3ed3fb9 100644
--- a/test/test.toHtml.js
+++ b/test/test.toHtml.js
@@ -252,13 +252,13 @@ describe('bh.toHtml()', function() {
         beforeEach(function() {
             bh = new BH();
         });
-        it('should not set `i-bem` class on element', function() {
+        it('should set `i-bem` class on element', function() {
             bh.apply({ block: 'button', elem: 'control', js: true, content: 'submit' }).should.equal(
-                '<div class="button__control" onclick=\'return {"button__control":{}}\'>submit</div>');
+                '<div class="button__control i-bem" onclick=\'return {"button__control":{}}\'>submit</div>');
         });
-        it('should not set `i-bem` class on mixed element', function() {
+        it('should 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" onclick=\'return {"button__control":{}}\'>submit</div>');
+                '<div class="icon button__control i-bem" onclick=\'return {"button__control":{}}\'>submit</div>');
         });
     });