Handle fields hidden with an opacity rule (#85)
This commit is contained in:
@@ -224,11 +224,11 @@
|
|||||||
* @return array List of search results
|
* @return array List of search results
|
||||||
*/
|
*/
|
||||||
function queryAllVisible(parent, field, form) {
|
function queryAllVisible(parent, field, form) {
|
||||||
var result = [];
|
const result = [];
|
||||||
for (var i = 0; i < field.selectors.length; i++) {
|
for (let i = 0; i < field.selectors.length; i++) {
|
||||||
var elems = parent.querySelectorAll(field.selectors[i]);
|
let elems = parent.querySelectorAll(field.selectors[i]);
|
||||||
for (var j = 0; j < elems.length; j++) {
|
for (let j = 0; j < elems.length; j++) {
|
||||||
var elem = elems[j];
|
let elem = elems[j];
|
||||||
// Select only elements from specified form
|
// Select only elements from specified form
|
||||||
if (form && form != elem.form) {
|
if (form && form != elem.form) {
|
||||||
continue;
|
continue;
|
||||||
@@ -247,12 +247,12 @@
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Elem takes space on the screen, but it or its parent is hidden with a visibility style.
|
// Elem takes space on the screen, but it or its parent is hidden with a visibility style.
|
||||||
var style = window.getComputedStyle(elem);
|
let style = window.getComputedStyle(elem);
|
||||||
if (style.visibility == "hidden") {
|
if (style.visibility == "hidden") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Elem is outside of the boundaries of the visible viewport.
|
// Elem is outside of the boundaries of the visible viewport.
|
||||||
var rect = elem.getBoundingClientRect();
|
let rect = elem.getBoundingClientRect();
|
||||||
if (
|
if (
|
||||||
rect.x + rect.width < 0 ||
|
rect.x + rect.width < 0 ||
|
||||||
rect.y + rect.height < 0 ||
|
rect.y + rect.height < 0 ||
|
||||||
@@ -260,6 +260,22 @@
|
|||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Elem is hidden by its or or its parent's opacity rules
|
||||||
|
const OPACITY_LIMIT = 0.1;
|
||||||
|
let opacity = 1;
|
||||||
|
for (
|
||||||
|
let testElem = elem;
|
||||||
|
opacity >= OPACITY_LIMIT && testElem && testElem.nodeType === Node.ELEMENT_NODE;
|
||||||
|
testElem = testElem.parentNode
|
||||||
|
) {
|
||||||
|
let style = window.getComputedStyle(testElem);
|
||||||
|
if (style.opacity) {
|
||||||
|
opacity *= parseFloat(style.opacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (opacity < OPACITY_LIMIT) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// This element is visible, will use it.
|
// This element is visible, will use it.
|
||||||
result.push(elem);
|
result.push(elem);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user