Skip to content

Commit

Permalink
ensure that popup's and dropdown__switcher's mixes work
Browse files Browse the repository at this point in the history
  • Loading branch information
aristov committed Jul 23, 2015
1 parent 720a838 commit 565e3f3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
19 changes: 12 additions & 7 deletions common.blocks/dropdown/dropdown.bemhtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ block('dropdown')(
}),
elem('switcher').mix()(function() {
var dropdown = this._dropdown,
dropdownMix = dropdown.mix;
dropdownMix = dropdown.mix,
switcherMix = dropdown.switcher.mix || [];

return dropdownMix?
Array.isArray(dropdownMix)?
dropdownMix.concat([dropdown]) :
[dropdownMix, dropdown] :
dropdown;
Array.isArray(switcherMix) || (switcherMix = [switcherMix]);

return switcherMix.concat(dropdownMix?
Array.isArray(dropdownMix)?
dropdownMix.concat([dropdown]) :
[dropdownMix, dropdown] :
dropdown);
}),
elem('popup').def()(function() {
var dropdown = this._dropdown,
Expand All @@ -43,7 +46,9 @@ block('dropdown')(

popupMods.target = 'anchor';

popup.mix = dropdown;
var popupMix = popup.mix || [];
Array.isArray(popupMix) || (popupMix = [popupMix]);
popup.mix = popupMix.concat([dropdown]);

applyCtx(popup);
})
Expand Down
13 changes: 9 additions & 4 deletions common.blocks/dropdown/dropdown.bh.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ module.exports = function(bh) {
bh.match({
'dropdown' : function(ctx) {
var dropdown = ctx.json(),
dropdownMix = dropdown.mix;
dropdownMix = dropdown.mix,
switcherMix = dropdown.switcher.mix || [];

Array.isArray(switcherMix) || (switcherMix = [switcherMix]);

ctx
.js(ctx.extend({ id : ctx.generateId() }, ctx.js()))
.tParam('dropdown', dropdown)
.tParam('theme', ctx.mod('theme'))
.tParam('mix', dropdownMix?
.tParam('mix', switcherMix.concat(dropdownMix?
Array.isArray(dropdownMix)?
dropdownMix.concat([dropdown]) :
[dropdownMix, dropdown] :
dropdown);
dropdown));

return [{ elem : 'switcher' }, { elem : 'popup' }];
},
Expand All @@ -32,7 +35,9 @@ module.exports = function(bh) {

popupMods.target = 'anchor';

popup.mix = dropdown;
var popupMix = popup.mix || [];
Array.isArray(popupMix) || (popupMix = [popupMix]);
popup.mix = popupMix.concat([dropdown]);

return popup;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
js : { id : 'uniq14257605137441' },
mods : { switcher : 'button', theme : 'islands', size : 'm' },
mix : { block : 'b1' },
switcher : 'button',
popup : 'bemjson'
switcher : {
block : 'button',
mix : { block : 'b2' },
text : 'button'
},
popup : {
block : 'popup',
mix : { block : 'b3' },
content : 'bemjson'
}
});
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<button class="button button_size_m button_theme_islands button__control dropdown dropdown_switcher_button dropdown_theme_islands dropdown_size_m b1 i-bem" data-bem="{&quot;button&quot;:{},&quot;dropdown&quot;:{&quot;id&quot;:&quot;uniq14257605137441&quot;}}" role="button" type="button"><span class="button__text">button</span></button><div class="popup popup_theme_islands popup_autoclosable popup_target_anchor dropdown dropdown_switcher_button dropdown_theme_islands dropdown_size_m i-bem" data-bem="{&quot;popup&quot;:{},&quot;dropdown&quot;:{&quot;id&quot;:&quot;uniq14257605137441&quot;}}">bemjson</div>
<button class="button button_size_m button_theme_islands button__control dropdown dropdown_switcher_button dropdown_theme_islands dropdown_size_m b1 b2 i-bem" data-bem="{&quot;button&quot;:{},&quot;dropdown&quot;:{&quot;id&quot;:&quot;uniq14257605137441&quot;}}" role="button" type="button"><span class="button__text">button</span></button><div class="popup popup_theme_islands popup_autoclosable popup_target_anchor dropdown dropdown_switcher_button dropdown_theme_islands dropdown_size_m b3 i-bem" data-bem="{&quot;popup&quot;:{},&quot;dropdown&quot;:{&quot;id&quot;:&quot;uniq14257605137441&quot;}}">bemjson</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
js : { id : 'uniq14257605137441' },
mods : { switcher : 'link', theme : 'islands' },
mix : [{ block : 'b1' }, { block : 'b2' }],
switcher : 'link',
popup : 'bemjson'
switcher : {
block : 'link',
mods : { pseudo : true },
mix : [{ block : 'b3' }, { block : 'b4' }],
content : 'link'
},
popup : {
block : 'popup',
mix : [{ block : 'b5' }, { block : 'b6' }],
content : 'bemjson'
}
});
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<span class="link link_pseudo link_theme_islands link__control dropdown dropdown_switcher_link dropdown_theme_islands b1 b2 i-bem" data-bem="{&quot;link&quot;:{},&quot;dropdown&quot;:{&quot;id&quot;:&quot;uniq14257605137441&quot;}}" tabindex="0">link</span><div class="popup popup_theme_islands popup_autoclosable popup_target_anchor dropdown dropdown_switcher_link dropdown_theme_islands i-bem" data-bem="{&quot;popup&quot;:{},&quot;dropdown&quot;:{&quot;id&quot;:&quot;uniq14257605137441&quot;}}">bemjson</div>
<span class="link link_pseudo link_theme_islands link__control dropdown dropdown_switcher_link dropdown_theme_islands b1 b2 b3 b4 i-bem" data-bem="{&quot;link&quot;:{},&quot;dropdown&quot;:{&quot;id&quot;:&quot;uniq14257605137441&quot;}}" tabindex="0">link</span><div class="popup popup_theme_islands popup_autoclosable popup_target_anchor dropdown dropdown_switcher_link dropdown_theme_islands b5 b6 i-bem" data-bem="{&quot;popup&quot;:{},&quot;dropdown&quot;:{&quot;id&quot;:&quot;uniq14257605137441&quot;}}">bemjson</div>

0 comments on commit 565e3f3

Please sign in to comment.