Skip to content

Commit 27014b1

Browse files
committed
Use new version of tinysort in multiple_select
1 parent cc26a86 commit 27014b1

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

python/nav/web/static/js/require_config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ var require = {
2222
"underscore": "libs/underscore",
2323
"marionette": "libs/backbone.marionette.min",
2424
"vue": "libs/vue.min",
25-
"driver": "libs/driver-1.3.6.min"
25+
"driver": "libs/driver-1.3.6.min",
26+
"tinysort": "libs/tinysort-3.1.4.min",
2627
},
2728
shim: {
2829
'libs/jquery-ui-timepicker-addon': ['libs/jquery-ui.min'],

python/nav/web/static/js/src/plugins/multiple_select.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
define(['libs/jquery.tinysort'], function () {
1+
define(['tinysort'], function (tinysort) {
22

33
/**
44
* MultipleSelect - an alternative to QuickSelect
@@ -90,13 +90,21 @@ define(['libs/jquery.tinysort'], function () {
9090
},
9191
sortInitial: function () {
9292
this.findInitialOptions();
93-
this.initial.sort(this.compareElements);
94-
this.initial.detach().appendTo(this.initialNode);
93+
const initialOptions = Array.from(this.initialNode[0].options);
94+
const sortedOptions = tinysort(initialOptions, {selector: null, order: 'asc', natural: true});
95+
this.initialNode.empty();
96+
for (const option of sortedOptions) {
97+
this.initialNode[0].appendChild(option);
98+
}
9599
},
96100
sortChoices: function () {
97101
this.findChoiceOptions();
98-
this.choices.sort(this.compareElements);
99-
this.choices.detach().appendTo(this.choiceNode);
102+
const choiceOptions = Array.from(this.choiceNode[0].options);
103+
const sortedOptions = tinysort(choiceOptions, {selector: null, order: 'asc', natural: true});
104+
this.choiceNode.empty();
105+
for (const option of sortedOptions) {
106+
this.choiceNode[0].appendChild(option);
107+
}
100108
},
101109
addSubmitHandler: function () {
102110
/* Selects all elements in the initial node so that it is

0 commit comments

Comments
 (0)