Skip to content

Commit fc0a0eb

Browse files
knyghtyjacobtylerwalls
authored andcommitted
Formatted JavaScript files.
1 parent 47789e3 commit fc0a0eb

31 files changed

Lines changed: 3025 additions & 1655 deletions
Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,60 @@
1-
'use strict';
1+
"use strict";
22
{
33
const getOptionGroupName = (option) => option.parentElement.label;
44
const SelectBox = {
55
cache: {},
6-
init: function(id) {
6+
init: function (id) {
77
const box = document.getElementById(id);
88
SelectBox.cache[id] = [];
99
const cache = SelectBox.cache[id];
1010
for (const node of box.options) {
1111
const group = getOptionGroupName(node);
12-
cache.push({group, value: node.value, text: node.text, displayed: 1});
12+
cache.push({
13+
group,
14+
value: node.value,
15+
text: node.text,
16+
displayed: 1,
17+
});
1318
}
1419
// Only sort if there are any groups (to preserve existing behavior for non-grouped selects)
15-
if (cache.some(item => item.group)) {
20+
if (cache.some((item) => item.group)) {
1621
SelectBox.sort(id);
1722
}
1823
},
19-
redisplay: function(id) {
24+
redisplay: function (id) {
2025
// Repopulate HTML select box from cache
2126
const box = document.getElementById(id);
2227
const scroll_value_from_top = box.scrollTop;
23-
box.innerHTML = '';
28+
box.innerHTML = "";
2429
let node = box;
2530
let currentOptgroup = null;
2631
for (const option of SelectBox.cache[id]) {
2732
if (option.displayed) {
2833
// Create a new optgroup when the group changes
2934
if (option.group && option.group !== currentOptgroup) {
3035
currentOptgroup = option.group;
31-
node = document.createElement('optgroup');
32-
node.setAttribute('label', option.group);
36+
node = document.createElement("optgroup");
37+
node.setAttribute("label", option.group);
3338
box.appendChild(node);
3439
} else if (!option.group && currentOptgroup !== null) {
3540
// Back to ungrouped options
3641
currentOptgroup = null;
3742
node = box;
3843
}
39-
const new_option = new Option(option.text, option.value, false, false);
44+
const new_option = new Option(
45+
option.text,
46+
option.value,
47+
false,
48+
false,
49+
);
4050
// Shows a tooltip when hovering over the option
4151
new_option.title = option.text;
4252
node.appendChild(new_option);
4353
}
4454
}
4555
box.scrollTop = scroll_value_from_top;
4656
},
47-
filter: function(id, text) {
57+
filter: function (id, text) {
4858
// Redisplay the HTML select box, displaying only the choices containing ALL
4959
// the words in text. (It's an AND search.)
5060
const tokens = text.toLowerCase().split(/\s+/);
@@ -62,9 +72,9 @@
6272
},
6373
get_hidden_node_count(id) {
6474
const cache = SelectBox.cache[id] || [];
65-
return cache.filter(node => node.displayed === 0).length;
75+
return cache.filter((node) => node.displayed === 0).length;
6676
},
67-
delete_from_cache: function(id, value) {
77+
delete_from_cache: function (id, value) {
6878
let delete_index = null;
6979
const cache = SelectBox.cache[id];
7080
for (const [i, node] of cache.entries()) {
@@ -75,10 +85,15 @@
7585
}
7686
cache.splice(delete_index, 1);
7787
},
78-
add_to_cache: function(id, option) {
79-
SelectBox.cache[id].push({group: option.group, value: option.value, text: option.text, displayed: 1});
88+
add_to_cache: function (id, option) {
89+
SelectBox.cache[id].push({
90+
group: option.group,
91+
value: option.value,
92+
text: option.text,
93+
displayed: 1,
94+
});
8095
},
81-
cache_contains: function(id, value) {
96+
cache_contains: function (id, value) {
8297
// Check if an item is contained in the cache
8398
for (const node of SelectBox.cache[id]) {
8499
if (node.value === value) {
@@ -87,59 +102,76 @@
87102
}
88103
return false;
89104
},
90-
move: function(from, to) {
105+
move: function (from, to) {
91106
const from_box = document.getElementById(from);
92107
for (const option of from_box.options) {
93108
const option_value = option.value;
94-
if (option.selected && SelectBox.cache_contains(from, option_value)) {
109+
if (
110+
option.selected &&
111+
SelectBox.cache_contains(from, option_value)
112+
) {
95113
const group = getOptionGroupName(option);
96-
SelectBox.add_to_cache(to, {group, value: option_value, text: option.text, displayed: 1});
114+
SelectBox.add_to_cache(to, {
115+
group,
116+
value: option_value,
117+
text: option.text,
118+
displayed: 1,
119+
});
97120
SelectBox.delete_from_cache(from, option_value);
98121
}
99122
}
100123
// Only sort if there are any groups (to preserve existing behavior for non-grouped selects)
101-
if (SelectBox.cache[to].some(item => item.group)) {
124+
if (SelectBox.cache[to].some((item) => item.group)) {
102125
SelectBox.sort(to);
103126
}
104127
SelectBox.redisplay(from);
105128
SelectBox.redisplay(to);
106129
},
107-
move_all: function(from, to) {
130+
move_all: function (from, to) {
108131
const from_box = document.getElementById(from);
109132
for (const option of from_box.options) {
110133
const option_value = option.value;
111134
if (SelectBox.cache_contains(from, option_value)) {
112135
const group = getOptionGroupName(option);
113-
SelectBox.add_to_cache(to, {group, value: option_value, text: option.text, displayed: 1});
136+
SelectBox.add_to_cache(to, {
137+
group,
138+
value: option_value,
139+
text: option.text,
140+
displayed: 1,
141+
});
114142
SelectBox.delete_from_cache(from, option_value);
115143
}
116144
}
117145
// Only sort if there are any groups (to preserve existing behavior for non-grouped selects)
118-
if (SelectBox.cache[to].some(item => item.group)) {
146+
if (SelectBox.cache[to].some((item) => item.group)) {
119147
SelectBox.sort(to);
120148
}
121149
SelectBox.redisplay(from);
122150
SelectBox.redisplay(to);
123151
},
124-
sort: function(id) {
125-
SelectBox.cache[id].sort(function(a, b) {
126-
a = (a.group && a.group.toLowerCase() || '') + a.text.toLowerCase();
127-
b = (b.group && b.group.toLowerCase() || '') + b.text.toLowerCase();
152+
sort: function (id) {
153+
SelectBox.cache[id].sort(function (a, b) {
154+
a =
155+
((a.group && a.group.toLowerCase()) || "") +
156+
a.text.toLowerCase();
157+
b =
158+
((b.group && b.group.toLowerCase()) || "") +
159+
b.text.toLowerCase();
128160
if (a > b) {
129161
return 1;
130162
}
131163
if (a < b) {
132164
return -1;
133165
}
134166
return 0;
135-
} );
167+
});
136168
},
137-
select_all: function(id) {
169+
select_all: function (id) {
138170
const box = document.getElementById(id);
139171
for (const option of box.options) {
140172
option.selected = true;
141173
}
142-
}
174+
},
143175
};
144176
window.SelectBox = SelectBox;
145177
}

0 commit comments

Comments
 (0)