mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 23:33:31 +00:00
dont lose order of els when reducing limit
This commit is contained in:
@@ -566,21 +566,30 @@
|
|||||||
return els;
|
return els;
|
||||||
}
|
}
|
||||||
|
|
||||||
// non-checkboxes have higher priority
|
// non-checkboxes/radios have higher priority
|
||||||
els = els.sort(function (a, b) {
|
var returnEls = [];
|
||||||
var aType = a.type ? a.type.toLowerCase() : a.type;
|
var unimportantEls = [];
|
||||||
var bType = b.type ? b.type.toLowerCase() : b.type;
|
for (var i = 0; i < els.length; i++) {
|
||||||
|
if (returnEls.length >= limit) {
|
||||||
if (aType !== 'checkbox' && bType === 'checkbox') {
|
break;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
if (aType === 'checkbox' && bType !== 'checkbox') {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
return els.slice(0, limit);
|
var el = els[i];
|
||||||
|
var type = el.type ? el.type.toLowerCase() : el.type;
|
||||||
|
if (type === 'checkbox' || type === 'radio') {
|
||||||
|
unimportantEls.push(el);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
returnEls.push(el);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var unimportantElsToAdd = limit - returnEls.length;
|
||||||
|
if (unimportantElsToAdd > 0) {
|
||||||
|
returnEls = returnEls.concat(unimportantEls.slice(0, unimportantElsToAdd));
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnEls;
|
||||||
// END MODIFICATION
|
// END MODIFICATION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user