mirror of
https://github.com/bitwarden/desktop.git
synced 2024-11-16 10:35:31 +01:00
dont lose order of els when reducing limit
This commit is contained in:
parent
72d09b0331
commit
fda669c701
@ -566,21 +566,30 @@
|
||||
return els;
|
||||
}
|
||||
|
||||
// non-checkboxes have higher priority
|
||||
els = els.sort(function (a, b) {
|
||||
var aType = a.type ? a.type.toLowerCase() : a.type;
|
||||
var bType = b.type ? b.type.toLowerCase() : b.type;
|
||||
|
||||
if (aType !== 'checkbox' && bType === 'checkbox') {
|
||||
return -1;
|
||||
// non-checkboxes/radios have higher priority
|
||||
var returnEls = [];
|
||||
var unimportantEls = [];
|
||||
for (var i = 0; i < els.length; i++) {
|
||||
if (returnEls.length >= limit) {
|
||||
break;
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user