javascript - TinyMCE 4 - get caret position -
i want caret position in tiny mce 4, don't want row/column number - want position in pixels (x & y dimmension). can relative anything. last thing - want without creating additional tags in content, bookmarks. tinymce have method that? or there option bookmark position in pixels, , after removing it?
thanks replies
ok, found it.
first have instance of tinymce.editor class var editor = new tinymce.editor(); //or way, tinymce.activeeditor
next jquery position of tinymce widgets:
var tinymceposition = $(editor.getcontainer()).position(); var toolbarposition = $(editor.getcontainer()).find(".mce-toolbar").first();
now position of html node, you're edit:
var nodeposition = $(editor.selection.getnode()).position(); var textareatop = 0; var textarealeft = 0;
we have y-axis position (via nodeposition.top
), it's time x:
if (editor.selection.getrng().getclientrects().length > 0) { textareatop = editor.selection.getrng().getclientrects()[0].top + editor.selection.getrng().getclientrects()[0].height; textarealeft = editor.selection.getrng().getclientrects()[0].left; } else { textareatop = parseint($($this.selection.getnode()).css("font-size")) * 1.3 + nodeposition.top; textarealeft = nodeposition.left; }
we have in textareatop && textarealeft
positions of caret relative tinymce editor window (textarea). it's time position relative whole page (browser window):
var position = $(editor.getcontainer()).offset(); var caretposition = { top: tinymceposition.top + toolbarposition.innerheight() + textareatop, left: tinymceposition.left + textarealeft + position.left }
solution based on autocomplete plugin tinymce 3, , adapted needs in tinymce 4.
Comments
Post a Comment