-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtransceiver.js
61 lines (60 loc) · 2.48 KB
/
transceiver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
HTMLWidgets.widget({
name: 'transceiver', // see also transmitter, receiver
type: 'output',
factory: function(el, width, height) {
var antenna = {channel_1: null, channel_2: null};
return {
renderValue: function(x) {
if(x.crosstalk_group) {
if(x.channel == "filter") {
antenna.channel_1 = new crosstalk.FilterHandle();
antenna.channel_2 = new crosstalk.FilterHandle();
} else if(x.channel == "filter->select") {
antenna.channel_1 = new crosstalk.FilterHandle();
antenna.channel_2 = new crosstalk.SelectionHandle();
} else if(x.channel == "select->filter") {
antenna.channel_1 = new crosstalk.SelectionHandle();
antenna.channel_2 = new crosstalk.FilterHandle();
} else {
antenna.channel_1 = new crosstalk.SelectionHandle();
antenna.channel_2 = new crosstalk.SelectionHandle();
}
antenna.channel_1.setGroup(x.crosstalk_group);
antenna.channel_2.setGroup(x.crosstalk_group2);
} else return;
el.innerHTML = x.innerHTML;
var cf = function(e) {
if(e.sender === antenna.channel_1 || e.sender === antenna.channel_2) return;
if(x.alldone) return;
if(x.reset && e.sender) {
antenna.channel_2.set(x.reset);
x.alldone = true;
return;
}
var val;
if(Array.isArray(e.value)) {
// the usual crosstalk selection array values
if(x.lookup) {
val = e.value.map(function(i) {return x.lookup[x.crosstalk_key.indexOf(i)];});
} else val = e.value;
if(! Array.isArray(val)) val = [val];
if(Array.isArray(val[0])) val = [].concat.apply([], val); // flatten
} else val = e.value;
if(el.children && el.children.length > 0) el.children[0][x.value] = val;
antenna.channel_2.set(val);
};
antenna.channel_1.on("change", cf);
if(el.children && el.children.length > 0) {
el.children[0].addEventListener("change", function() {
var val = el.children[0][x.value];
if(!Array.isArray(val)) val = [val];
if(Array.isArray(val[0])) val = [].concat.apply([], val); // flatten
antenna.channel_2.set(val); // send HTML element values
});
}
if(x.init) cf({sender: null, value: [x.init]});
},
resize: function(width, height) { }
};
}
});