aboutsummaryrefslogtreecommitdiff
path: root/page.js
diff options
context:
space:
mode:
authorRadu <radu@pml4t.net>2023-09-07 16:33:45 -0400
committerRadu <radu@pml4t.net>2023-09-07 16:34:35 -0400
commit696f234134da6b599dbf02dc4e96a0fe235762c1 (patch)
treef02bcd25c1867a86e80f0892596cd46e58653f74 /page.js
parentbc8316ccf7eb8e4d622386a1835eac8a400f047c (diff)
Fix: Attach event handler to all text areas in Adobe Connect
Diffstat (limited to 'page.js')
-rw-r--r--page.js41
1 files changed, 36 insertions, 5 deletions
diff --git a/page.js b/page.js
index 7546de7..a13cb30 100644
--- a/page.js
+++ b/page.js
@@ -4,7 +4,7 @@
(async () => {
if (await subEnabled()) {
- console.log("TeX Type started.");
+ console.log("TeX Type: Started.");
function cmdToUnicode(name, args) {
if (name === "^")
@@ -267,15 +267,18 @@
return input.value.length;
}
- window.addEventListener("input", (event) => {
+ function eventHandler(event) {
if (event.target.selectionStart != null) {
+ const { selectionStart, selectionEnd } = event.target;
const input = {
value: event.target.value,
- caret: event.target.selectionStart,
+ caret: selectionStart,
};
subCmds(input);
event.target.value = input.value;
- event.target.selectionStart = event.target.selectionEnd = input.caret;
+ event.target.selectionStart = input.caret;
+ // Sloppily ignore spurious `keyup`
+ event.target.selectionEnd = selectionEnd - selectionStart + input.caret;
} else if (event.target.contentEditable === "true") {
const textNode = window.getSelection().anchorNode;
const input = {
@@ -288,6 +291,34 @@
.getSelection()
.setBaseAndExtent(textNode, input.caret, textNode, input.caret);
}
- });
+ }
+
+ const adobeConnectIframe = document.getElementById("html-meeting-frame");
+ if (adobeConnectIframe) {
+ // Adobe Connect workaround
+
+ console.debug("Tex Type: Listening for `textarea` elements.");
+
+ const textAreas =
+ adobeConnectIframe.contentDocument.getElementsByTagName("textarea");
+ const oldTextAreas = new Set(textAreas);
+
+ function handleNewTextAreas() {
+ console.debug("Tex Type: Seeking new `textarea`s.");
+ for (const textArea of textAreas)
+ if (!oldTextAreas.has(textArea)) {
+ console.debug("Tex Type: Found new `textarea`.");
+ textArea.addEventListener("keyup", eventHandler, true);
+ oldTextAreas.add(textArea);
+ }
+ }
+
+ const cb = new MutationObserver(handleNewTextAreas);
+ cb.observe(adobeConnectIframe.contentDocument, {
+ childList: true,
+ subtree: true,
+ });
+ handleNewTextAreas();
+ } else window.addEventListener("input", eventHandler, true);
}
})();