Browse Source

luci-base: ui.js: order indicators by ID value

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Jo-Philipp Wich 4 years ago
parent
commit
01d8283ece
1 changed files with 14 additions and 3 deletions
  1. 14 3
      modules/luci-base/htdocs/luci-static/resources/ui.js

+ 14 - 3
modules/luci-base/htdocs/luci-static/resources/ui.js

@@ -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;