Add some documentation
This commit is contained in:
24
service.js
24
service.js
@@ -701,6 +701,9 @@ class BesCKService extends BesService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Grammar checking service for textarea element
|
||||||
|
///
|
||||||
class BesTAService {
|
class BesTAService {
|
||||||
constructor(textAreaEl) {
|
constructor(textAreaEl) {
|
||||||
this.textAreaEl = 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) {
|
createCloneDiv(textAreaEl) {
|
||||||
const cloneDiv = document.createElement('div')
|
const cloneDiv = document.createElement('div')
|
||||||
const textAreaRect = textAreaEl.getBoundingClientRect()
|
const textAreaRect = textAreaEl.getBoundingClientRect()
|
||||||
@@ -738,6 +747,9 @@ class BesTAService {
|
|||||||
return cloneDiv
|
return cloneDiv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function copies the text from the textarea to the clone div
|
||||||
|
*/
|
||||||
handleInput() {
|
handleInput() {
|
||||||
const customEvent = new InputEvent('beforeinput')
|
const customEvent = new InputEvent('beforeinput')
|
||||||
|
|
||||||
@@ -751,6 +763,11 @@ class BesTAService {
|
|||||||
this.cloneDiv.dispatchEvent(customEvent)
|
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) {
|
handleTAClick(e) {
|
||||||
//TODO: Consider adding some kind of proofing?
|
//TODO: Consider adding some kind of proofing?
|
||||||
this.textAreaEl.style.visibility = 'hidden'
|
this.textAreaEl.style.visibility = 'hidden'
|
||||||
@@ -767,8 +784,13 @@ class BesTAService {
|
|||||||
this.cloneDiv.dispatchEvent(clickEvent)
|
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) {
|
handleReplacement(el) {
|
||||||
|
// TODO: think of a way to reposition the cursor after the replacement
|
||||||
this.textAreaEl.value = el.outerText
|
this.textAreaEl.value = el.outerText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user