summaryrefslogtreecommitdiff
path: root/modules/luci-base/htdocs/luci-static/resources/form.js
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-07-27 17:19:08 +0200
committerJo-Philipp Wich <jo@mein.io>2022-07-27 17:32:58 +0200
commit37422e891a47f15659356ce75b6f6cce831e0041 (patch)
treed1e16dfb79a16f13d0fb368fac75fad7a0d27f16 /modules/luci-base/htdocs/luci-static/resources/form.js
parent8199b2ce9a7d36359aedea1ad9dab157134a46c2 (diff)
luci-base: revise array sorting
Refactor various sort operations throughout luci-base to use the new L.naturalCompare() comparator function. This primarily ensures that embedded numbers are sorted numerically and not in a lexicographical way. It also simplifies some code as a side effect. Ref: #5899 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/htdocs/luci-static/resources/form.js')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/form.js12
1 files changed, 4 insertions, 8 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js
index aae8b3684a..2d540420bc 100644
--- a/modules/luci-base/htdocs/luci-static/resources/form.js
+++ b/modules/luci-base/htdocs/luci-static/resources/form.js
@@ -74,7 +74,7 @@ var CBIJSONConfig = baseclass.extend({
if (indexA != indexB)
return (indexA - indexB);
- return (a > b);
+ return L.naturalCompare(a, b);
}, this));
for (var i = 0; i < section_ids.length; i++)
@@ -3080,13 +3080,9 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p
}, this));
list.sort(function(a, b) {
- if (a[0] < b[0])
- return descending ? 1 : -1;
-
- if (a[0] > b[0])
- return descending ? -1 : 1;
-
- return 0;
+ return descending
+ ? -L.naturalCompare(a[0], b[0])
+ : L.naturalCompare(a[0], b[0]);
});
window.requestAnimationFrame(L.bind(function() {