From f29d6732c35e45dfead370599e1d61ec4391f00a Mon Sep 17 00:00:00 2001 From: Aljaz Grilc Date: Tue, 26 Mar 2024 11:04:00 +0100 Subject: [PATCH] Add some documentation --- service.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/service.js b/service.js index 69706e0..adf7e56 100644 --- a/service.js +++ b/service.js @@ -701,6 +701,9 @@ class BesCKService extends BesService { } } +/// +/// Grammar checking service for textarea element +/// class BesTAService { constructor(textAreaEl) { this.textAreaEl = textAreaEl @@ -714,6 +717,12 @@ class BesTAService { }) } + /** + * Creates a clone div element for the textarea element + * + * @param {Node} textAreaEl + * @returns {Node} Clone div element + */ createCloneDiv(textAreaEl) { const cloneDiv = document.createElement('div') const textAreaRect = textAreaEl.getBoundingClientRect() @@ -738,6 +747,9 @@ class BesTAService { return cloneDiv } + /** + * This function copies the text from the textarea to the clone div + */ handleInput() { const customEvent = new InputEvent('beforeinput') @@ -751,6 +763,11 @@ class BesTAService { this.cloneDiv.dispatchEvent(customEvent) } + /** + * This function handles the click event on the textarea element and finds the deepest div at the click position + * + * @param {Event} e Click event + */ handleTAClick(e) { //TODO: Consider adding some kind of proofing? this.textAreaEl.style.visibility = 'hidden' @@ -767,8 +784,13 @@ class BesTAService { this.cloneDiv.dispatchEvent(clickEvent) } - // TODO: think of a way to reposition the cursor after the replacement + /** + * This function handles the replacement of the text in the textarea element + * + * @param {HTMLElement} el Element to replace the text in + */ handleReplacement(el) { + // TODO: think of a way to reposition the cursor after the replacement this.textAreaEl.value = el.outerText }