-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdropdownmenu.js
98 lines (89 loc) · 2.23 KB
/
dropdownmenu.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Generated by CoffeeScript 1.10.0
(function() {
var cibo, cibo_data, groups, groups_data, on_selection_changed;
cibo_data = [
{
label: 'mela',
group: 'Frutta'
}, {
label: 'pera',
group: 'Frutta'
}, {
label: 'banana',
group: 'Frutta'
}, {
label: 'arancia',
group: 'Frutta'
}, {
label: 'lattuga',
group: 'Verdura'
}, {
label: 'carota',
group: 'Verdura'
}, {
label: 'cavoloooo',
group: 'Verdura'
}, {
label: 'manzo',
group: 'Carne'
}, {
label: 'pollo',
group: 'Carne'
}, {
label: 'maiale',
group: 'Carne'
}, {
label: 'triglia',
group: 'Pesce'
}, {
label: 'cernia',
group: 'Pesce'
}
];
groups_data = d3.nest().key(function(d) {
return d.group;
}).entries(cibo_data);
groups = d3.select('#example').selectAll('optgroup').data(groups_data);
groups.enter().append('optgroup').attr("label",function(d) {
return d.key;
})
.attr("id",function(d) {
return d.key;
});
for(var i=0; i<groups_data.length; i++){
cibo = d3.select("#"+groups_data[i].key).selectAll('option').data(groups_data[i].values)
cibo.enter().append('option')
.attr("value", function(d) {
return d.label;
})
.text(function(d) {
return d.label;
});
}
on_selection_changed = function() {
var i, len, ref, so, so_values;
so_values = [];
ref = d3.select('#example').node().selectedOptions;
for (i = 0, len = ref.length; i < len; i++) {
so = ref[i];
so_values.push(so.value);
}
};
$('#example').multiselect({
buttonWidth: '300px',
maxHeight: 400,
enableClickableOptGroups: true,
enableCollapsibleOptGroups: true,
enableFiltering: true,
filterPlaceholder: 'Cerca',
includeSelectAllOption: true,
selectAllJustVisible: false,
selectAllText: 'Select All',
nSelectedText: ' elementi selezionati',
allSelectedText: 'Tutti gli elementi selezionati',
nonSelectedText: 'List',
onChange: on_selection_changed,
onSelectAll: on_selection_changed,
onDeselectAll: on_selection_changed
});
}).call(this);