luci-base: ui.js: order indicators by ID value
authorJo-Philipp Wich <jo@mein.io>
Fri, 17 Apr 2020 07:30:20 +0000 (09:30 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 7 May 2020 17:40:49 +0000 (19:40 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 01d8283ecea730191ce41302acb7ecd1aaf0631f)

modules/luci-base/htdocs/luci-static/resources/ui.js

index d0045007b9d1cb5806e39084b6d903e1444ec3a7..47f3e9892c89ae956e76a21deb66564578b751a3 100644 (file)
@@ -3205,12 +3205,23 @@ var UI = baseclass.extend(/** @lends LuCI.ui.prototype */ {
                }
 
                var handlerFn = (typeof(handler) == 'function') ? handler : null,
-                   indicatorElem = indicatorDiv.querySelector('span[data-indicator="%s"]'.format(id)) ||
-                       indicatorDiv.appendChild(E('span', {
+                   indicatorElem = indicatorDiv.querySelector('span[data-indicator="%s"]'.format(id));
+
+               if (indicatorElem == null) {
+                       var beforeElem = null;
+
+                       for (beforeElem = indicatorDiv.firstElementChild;
+                            beforeElem != null;
+                            beforeElem = beforeElem.nextElementSibling)
+                               if (beforeElem.getAttribute('data-indicator') > id)
+                                       break;
+
+                       indicatorElem = indicatorDiv.insertBefore(E('span', {
                                'data-indicator': id,
                                'data-clickable': handlerFn ? true : null,
                                'click': handlerFn
-                       }, ['']));
+                       }, ['']), beforeElem);
+               }
 
                if (label == indicatorElem.firstChild.data && style == indicatorElem.getAttribute('data-style'))
                        return false;