in toolkit/jb/svg.js [380:438]
function initBlendSwitchInGroup(target, id, count, width, height) {
var lastSelected;
var lastSelectedText;
var switchStates = {};
function switchBlend(blend, text) {
return function() {
if (lastSelected && (lastSelected.value !== blend.value) && lastSelectedText) {
switchStates[lastSelected.value] = false;
lastSelectedText.attr('fill', 'black');
}
if (!blend) return;
var selected = switchStates[blend.value] ? false : true;
switchStates[blend.value] = selected;
text.attr('fill', selected ? 'white' : 'black');
if (selected) {
lastSelected = blend;
lastSelectedText = text;
return blend.value;
} else {
lastSelected = null;
lastSelectedText = text;
return '';
}
};
}
var submit, text, clicks;
var texts;
d3.select(target).append('g')
.attr('transform', 'translate(0,' + ((id * height) + (height / 2) - (count * height / 2)) + ')')
.call(function(target) {
texts = BLENDS.map(function(blend, i) {
return target.append('text').style('cursor', 'pointer')
.text(blend.label)
.attr('transform', 'translate(' + (i * LETTER_WIDTH) + ',0)');
})
texts.forEach(function(text, i) {
text.append('title').text(BLENDS[i].name);
});
submit = Kefir.merge(
BLENDS.map(function(blend, i) {
return Kefir.fromEvents(texts[i].node(), 'click')
.map(switchBlend(blend, texts[i]));
})
);
});
if (DEFAULT_LAYERS_BLENDS[id]) {
var blendIdx = blendToIndex[DEFAULT_LAYERS_BLENDS[id]];
switchBlend(BLENDS[blendIdx], texts[blendIdx])();
}
return submit;
}