Implement find_id inside frames

Fixes :click-element
This commit is contained in:
Jay Kamat 2017-12-07 14:53:15 -05:00
parent 825939633a
commit 5c5f992821
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5

View File

@ -220,9 +220,39 @@ window._qutebrowser.webelem = (function() {
return out;
};
// Runs a function in a frame until the result is not null, then return
function run_frames(func) {
for (let i = 0; i < window.frames.length; ++i) {
if (iframe_same_domain(window.frames[i])) {
const frame = window.frames[i];
const result = func(frame);
if (result) {
return result;
}
}
}
return null;
}
funcs.find_id = (id) => {
const elem = document.getElementById(id);
return serialize_elem(elem);
if (elem) {
return serialize_elem(elem);
}
const serialized_elem = run_frames((frame) => {
const element = frame.window.document.getElementById(id);
if (element) {
return serialize_elem(element, frame);
}
return null;
});
if (serialized_elem) {
return serialized_elem;
}
return null;
};
// Check if elem is an iframe, and if so, run func on it.
@ -239,20 +269,6 @@ window._qutebrowser.webelem = (function() {
return null;
}
// Runs a function in a frame until the result is not null, then return
function run_frames(func) {
for (let i = 0; i < window.frames.length; ++i) {
if (iframe_same_domain(window.frames[i])) {
const frame = window.frames[i];
const result = func(frame);
if (result) {
return result;
}
}
}
return null;
}
funcs.find_focused = () => {
const elem = document.activeElement;