diff options
author | siikamiika <siikamiika@users.noreply.github.com> | 2019-09-05 09:25:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-05 09:25:42 +0300 |
commit | 9cd0101b62fe99d736b4e6b9072c2aa4827311af (patch) | |
tree | 822811aae7528487bc4ebb17d363cdb4b7b0b00c /ext/fg/js/source.js | |
parent | 4ac55da7dd5354e6c3495f04583352d0d863b7b6 (diff) | |
parent | 9028b55774f788f0b61acadb8d3ba85b2bfab34a (diff) |
Merge pull request #185 from toasted-nutbread/recursive-popups
Recursive popups
Diffstat (limited to 'ext/fg/js/source.js')
-rw-r--r-- | ext/fg/js/source.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js index e724488d..385b5001 100644 --- a/ext/fg/js/source.js +++ b/ext/fg/js/source.js @@ -232,6 +232,50 @@ class TextSourceRange { const writingMode = style.writingMode; return typeof writingMode === 'string' ? writingMode : 'horizontal-tb'; } + + static getNodesInRange(range) { + const end = range.endContainer; + const nodes = []; + for (let node = range.startContainer; node !== null; node = TextSourceRange.getNextNode(node)) { + nodes.push(node); + if (node === end) { break; } + } + return nodes; + } + + static getNextNode(node) { + let next = node.firstChild; + if (next === null) { + while (true) { + next = node.nextSibling; + if (next !== null) { break; } + + next = node.parentNode; + if (node === null) { break; } + + node = next; + } + } + return next; + } + + static anyNodeMatchesSelector(nodeList, selector) { + for (const node of nodeList) { + if (TextSourceRange.nodeMatchesSelector(node, selector)) { + return true; + } + } + return false; + } + + static nodeMatchesSelector(node, selector) { + for (; node !== null; node = node.parentNode) { + if (node.nodeType === Node.ELEMENT_NODE) { + return node.matches(selector); + } + } + return false; + } } |