diff options
author | Thedro Neely <thedroneely@gmail.com> | 2022-03-24 16:16:32 -0400 |
---|---|---|
committer | Thedro Neely <thedroneely@gmail.com> | 2022-03-24 16:19:55 -0400 |
commit | 0980ce9359f42bda107277798fbaa2fca946140b (patch) | |
tree | 55bba3733d9eeec8e42408dbca6df9c2b6e6830d /public | |
parent | 7847414c57686bcee1c089a911f0401fcc72f40b (diff) | |
download | thedroneely.com-0980ce9359f42bda107277798fbaa2fca946140b.tar.gz thedroneely.com-0980ce9359f42bda107277798fbaa2fca946140b.tar.bz2 thedroneely.com-0980ce9359f42bda107277798fbaa2fca946140b.zip |
public/js/app: Ensure dictionary access does not capture code blocks
Traverse upwards and check if the text element has parent <pre>.
Diffstat (limited to 'public')
-rw-r--r-- | public/js/app.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/public/js/app.js b/public/js/app.js index 2e61595..3c6d91f 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -856,6 +856,16 @@ function preload(url) { } } + function notInside(element, name) { + if (typeof element.parentElement === "undefined" || + element.parentElement === null + ) { return true; } + var parentTag = element.parentElement; + var tagName = element.tagName; + if (tagName === name) { return false; } + return notInside(parentTag, name); + } + function dictionary(event) { if ( event.ctrlKey == true || @@ -865,8 +875,9 @@ function preload(url) { return; } var word = "" + window.getSelection(); - var container = window.getSelection().anchorNode.parentElement.tagName; - if (word > "" && word.length > 1 && container !== "CODE") { + var container = window.getSelection().anchorNode.parentElement; + + if (word > "" && word.length > 1 && notInside(container, 'PRE')) { dictionary_access(word); } } |