remove useless select support legacy (#863)
This commit is contained in:
@@ -745,151 +745,6 @@ function getSelectOptions(element) {
|
||||
return [selectOptions, removeMultipleSpaces(selectedOption.textContent)];
|
||||
}
|
||||
|
||||
function getListboxOptions(element) {
|
||||
// get all the elements with role="option" under the element
|
||||
var optionElements = element.querySelectorAll('[role="option"]');
|
||||
let selectOptions = [];
|
||||
for (var i = 0; i < optionElements.length; i++) {
|
||||
let ele = optionElements[i];
|
||||
|
||||
selectOptions.push({
|
||||
optionIndex: i,
|
||||
text: removeMultipleSpaces(getVisibleText(ele)),
|
||||
});
|
||||
}
|
||||
return selectOptions;
|
||||
}
|
||||
|
||||
async function getSelect2OptionElements(element) {
|
||||
let optionList = [];
|
||||
const document = element.getRootNode();
|
||||
|
||||
while (true) {
|
||||
oldOptionCount = optionList.length;
|
||||
let newOptionList = document.querySelectorAll("[id='select2-drop'] ul li");
|
||||
if (newOptionList.length === oldOptionCount) {
|
||||
console.log("no more options loaded, wait 5s to query again");
|
||||
// sometimes need more time to load the options, so sleep 10s and try again
|
||||
await globalSleep(5000); // wait 5s
|
||||
newOptionList = document.querySelectorAll("[id='select2-drop'] ul li");
|
||||
console.log(newOptionList.length, " options found, after 5s");
|
||||
}
|
||||
|
||||
optionList = newOptionList;
|
||||
if (optionList.length === 0 || optionList.length === oldOptionCount) {
|
||||
break;
|
||||
}
|
||||
|
||||
lastOption = optionList[optionList.length - 1];
|
||||
if (!lastOption.className.toString().includes("select2-more-results")) {
|
||||
break;
|
||||
}
|
||||
lastOption.scrollIntoView();
|
||||
}
|
||||
|
||||
return optionList;
|
||||
}
|
||||
|
||||
async function getSelect2Options(element) {
|
||||
const optionList = await getSelect2OptionElements(element);
|
||||
|
||||
let selectOptions = [];
|
||||
for (let i = 0; i < optionList.length; i++) {
|
||||
let ele = optionList[i];
|
||||
if (ele.className.toString().includes("select2-more-results")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
selectOptions.push({
|
||||
optionIndex: i,
|
||||
text: removeMultipleSpaces(ele.textContent),
|
||||
});
|
||||
}
|
||||
|
||||
return selectOptions;
|
||||
}
|
||||
|
||||
async function getReactSelectOptionElements(element) {
|
||||
var scrollLeft = window.scrollX;
|
||||
var scrollTop = window.scrollY;
|
||||
|
||||
let optionList = [];
|
||||
// wait for 2s until the element is updated with `aria-controls`
|
||||
console.log("wait 2s for the dropdown being updated.");
|
||||
await globalSleep(2000);
|
||||
|
||||
dropdownId = element.getAttribute("aria-controls");
|
||||
if (!dropdownId) {
|
||||
return optionList;
|
||||
}
|
||||
|
||||
const document = element.getRootNode();
|
||||
dropdownDiv = document.querySelector(`div[id="${dropdownId}"]`);
|
||||
let previousOptionCount = null;
|
||||
|
||||
while (true) {
|
||||
// sometimes need more time to load the options
|
||||
console.log("wait 5s to load all options");
|
||||
await globalSleep(5000); // wait 5s
|
||||
optionList = dropdownDiv.querySelectorAll("div[class*='select__option']");
|
||||
if (optionList.length === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
previousOptionCount !== null &&
|
||||
previousOptionCount == optionList.length
|
||||
) {
|
||||
break;
|
||||
}
|
||||
previousOptionCount = optionList.length;
|
||||
|
||||
lastOption = optionList[optionList.length - 1];
|
||||
lastOption.scrollIntoView({ behavior: "instant" });
|
||||
|
||||
lastOption.dispatchEvent(
|
||||
new WheelEvent("wheel", {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
deltaX: 0,
|
||||
deltaY: -20,
|
||||
deltaZ: 0,
|
||||
}),
|
||||
);
|
||||
lastOption.dispatchEvent(
|
||||
new WheelEvent("wheel", {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
deltaX: 0,
|
||||
deltaY: 20,
|
||||
deltaZ: 0,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// scroll back to the original place
|
||||
window.scroll({
|
||||
top: scrollTop,
|
||||
left: scrollLeft,
|
||||
behavior: "instant",
|
||||
});
|
||||
return optionList;
|
||||
}
|
||||
|
||||
async function getReactSelectOptions(element) {
|
||||
const optionList = await getReactSelectOptionElements(element);
|
||||
|
||||
let selectOptions = [];
|
||||
for (let i = 0; i < optionList.length; i++) {
|
||||
let ele = optionList[i];
|
||||
selectOptions.push({
|
||||
optionIndex: i,
|
||||
text: removeMultipleSpaces(ele.textContent),
|
||||
});
|
||||
}
|
||||
return selectOptions;
|
||||
}
|
||||
|
||||
function getDOMElementBySkyvenElement(elementObj) {
|
||||
// if element has shadowHost set, we need to find the shadowHost element first then find the element
|
||||
if (elementObj.shadowHost) {
|
||||
@@ -1674,10 +1529,6 @@ function scrollToElementTop(element) {
|
||||
});
|
||||
}
|
||||
|
||||
async function globalSleep(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
// Helper method for debugging
|
||||
function findNodeById(arr, targetId, path = []) {
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user