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>
Fri, 17 Apr 2020 07:30:54 +0000 (09:30 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/ui.js

index 6d77f37824e064bd15b46c8d08e256da777cfcaa..625363811c448b888db2801f9ac99140c206ec72 100644 (file)
@@ -3291,12 +3291,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;