|
224 | 224 | * @return array List of search results
|
225 | 225 | */
|
226 | 226 | function queryAllVisible(parent, field, form) {
|
227 |
| - var result = []; |
228 |
| - for (var i = 0; i < field.selectors.length; i++) { |
229 |
| - var elems = parent.querySelectorAll(field.selectors[i]); |
230 |
| - for (var j = 0; j < elems.length; j++) { |
231 |
| - var elem = elems[j]; |
| 227 | + const result = []; |
| 228 | + for (let i = 0; i < field.selectors.length; i++) { |
| 229 | + let elems = parent.querySelectorAll(field.selectors[i]); |
| 230 | + for (let j = 0; j < elems.length; j++) { |
| 231 | + let elem = elems[j]; |
232 | 232 | // Select only elements from specified form
|
233 | 233 | if (form && form != elem.form) {
|
234 | 234 | continue;
|
|
247 | 247 | continue;
|
248 | 248 | }
|
249 | 249 | // Elem takes space on the screen, but it or its parent is hidden with a visibility style.
|
250 |
| - var style = window.getComputedStyle(elem); |
| 250 | + let style = window.getComputedStyle(elem); |
251 | 251 | if (style.visibility == "hidden") {
|
252 | 252 | continue;
|
253 | 253 | }
|
254 | 254 | // Elem is outside of the boundaries of the visible viewport.
|
255 |
| - var rect = elem.getBoundingClientRect(); |
| 255 | + let rect = elem.getBoundingClientRect(); |
256 | 256 | if (
|
257 | 257 | rect.x + rect.width < 0 ||
|
258 | 258 | rect.y + rect.height < 0 ||
|
259 | 259 | (rect.x > window.innerWidth || rect.y > window.innerHeight)
|
260 | 260 | ) {
|
261 | 261 | continue;
|
262 | 262 | }
|
| 263 | + // Elem is hidden by its or or its parent's opacity rules |
| 264 | + const OPACITY_LIMIT = 0.1; |
| 265 | + let opacity = 1; |
| 266 | + for ( |
| 267 | + let testElem = elem; |
| 268 | + opacity >= OPACITY_LIMIT && testElem && testElem.nodeType === Node.ELEMENT_NODE; |
| 269 | + testElem = testElem.parentNode |
| 270 | + ) { |
| 271 | + let style = window.getComputedStyle(testElem); |
| 272 | + if (style.opacity) { |
| 273 | + opacity *= parseFloat(style.opacity); |
| 274 | + } |
| 275 | + } |
| 276 | + if (opacity < OPACITY_LIMIT) { |
| 277 | + continue; |
| 278 | + } |
263 | 279 | // This element is visible, will use it.
|
264 | 280 | result.push(elem);
|
265 | 281 | }
|
|
0 commit comments