Make a function to copy textarea content to cloneDiv element
This commit is contained in:
parent
fbfb8b419f
commit
51fdf52fa9
14
service.js
14
service.js
@ -716,6 +716,7 @@ class BesTAService {
|
|||||||
this.textAreaEl = textAreaEl
|
this.textAreaEl = textAreaEl
|
||||||
this.textAreaEl.spellcheck = false
|
this.textAreaEl.spellcheck = false
|
||||||
this.cloneDiv = this.createCloneDiv(textAreaEl)
|
this.cloneDiv = this.createCloneDiv(textAreaEl)
|
||||||
|
this.copyTAContent()
|
||||||
this.service = BesService.register(this.cloneDiv, this)
|
this.service = BesService.register(this.cloneDiv, this)
|
||||||
this.textAreaEl.addEventListener('input', () => this.handleInput())
|
this.textAreaEl.addEventListener('input', () => this.handleInput())
|
||||||
this.textAreaEl.addEventListener('click', e => this.handleTAClick(e))
|
this.textAreaEl.addEventListener('click', e => this.handleTAClick(e))
|
||||||
@ -756,10 +757,9 @@ class BesTAService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This function copies the text from the textarea to the clone div
|
* This function copies the text from the textarea to the clone div
|
||||||
|
* and creates div elements for each line of text in the textarea
|
||||||
*/
|
*/
|
||||||
handleInput() {
|
copyTAContent() {
|
||||||
const customEvent = new InputEvent('beforeinput')
|
|
||||||
|
|
||||||
const lines = this.textAreaEl.value.split('\n')
|
const lines = this.textAreaEl.value.split('\n')
|
||||||
this.cloneDiv.innerHTML = ''
|
this.cloneDiv.innerHTML = ''
|
||||||
lines.forEach(line => {
|
lines.forEach(line => {
|
||||||
@ -768,6 +768,14 @@ class BesTAService {
|
|||||||
if (line === '') divEl.innerHTML = ' '
|
if (line === '') divEl.innerHTML = ' '
|
||||||
this.cloneDiv.appendChild(divEl)
|
this.cloneDiv.appendChild(divEl)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function copies the text from the textarea to the clone div
|
||||||
|
*/
|
||||||
|
handleInput() {
|
||||||
|
const customEvent = new InputEvent('beforeinput')
|
||||||
|
this.copyTAContent()
|
||||||
this.cloneDiv.dispatchEvent(customEvent)
|
this.cloneDiv.dispatchEvent(customEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user