<script>
document.getElementById('btnFocus').addEventListener('click', function () {
// To find last direct childnode
var editEleLastNode = document.querySelector('.e-richtexteditor .e-content').lastChild;
// Find the all text node from editor element
var textNodes = getTextNodesUnder(document, editEleLastNode);
// Last textnode, where we going to set a cursor
var lastTextNode = textNodes[textNodes.length - 1];
var selectioncursor = new ej.richtexteditor.NodeSelection();
var range = document.createRange();
// to set the range
range.setStart(lastTextNode, 1);
// to set the cursor
selectioncursor.setRange(document, range);
});
// Find the all text node from given node
function getTextNodesUnder(document, node) {
var nodes = [];
for (node = node.firstChild; node; node = node.nextSibling) {
if (node.nodeType === 3) {
nodes.push(node);
}
else {
nodes = nodes.concat(getTextNodesUnder(document, node));
}
}
return nodes;
}
</script>
|