I have a plugin that detects cursor position and text before it. However, it only works right now on multiline input. However, I also wish to have it work also in Rich Text Editor plugin. Can someone please give me advice please.
I hope someone could help as I am not much of a coder.
I can’t contact the previous developer and couldnt find a new one. This project has been stuck for months and I am desperate for help
Below is the code:
function(properties, context) {
let i = 0;
let txt = properties.animation_text;
let ntxt = properties.normal_text;
let elementId = properties.element_id;
let speed = properties.animation_speed;
let cursorPostion = properties.cursor_position;
function applyTypewriterEffect() {
let initalContent = document.getElementById(elementId).value;
let input = document.getElementById(elementId);
if (i < txt.length && txt.length > 0 ) {
input.value = initalContent.slice(0, cursorPostion) + txt.charAt(i) + initalContent.slice(cursorPostion);
i++;
cursorPostion++;
input.setSelectionRange(cursorPostion, cursorPostion)
input.blur();
input.focus();
if(ntxt !=null && ntxt !== ‘’ && i== txt.length && ntxt.length > 0)
input.value += ntxt;
setTimeout(applyTypewriterEffect, speed);
}else{
let selectionStart= properties.cursor_position;
let selectionEnd = properties.cursor_position + txt.length;
input.dispatchEvent(new Event(‘change’, { ‘bubbles’: true }));
setTimeout(function() {
if (input.setSelectionRange) {
input.setSelectionRange(selectionEnd, selectionEnd);
input.blur();
input.focus();
}
else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd(‘character’, selectionEnd);
range.moveStart(‘character’, selectionEnd);
range.select();
}
}, 1000);
}
}
applyTypewriterEffect();
}