X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e104b4b87dc39066cbe397984c6f0e6bcc0459f8..75e12ca1b25cdcdb457ee2a159a0bf4287841c63:/src/editor/modules/documentCanvas/canvas/utils.js?ds=inline diff --git a/src/editor/modules/documentCanvas/canvas/utils.js b/src/editor/modules/documentCanvas/canvas/utils.js index 058ede8..620e652 100644 --- a/src/editor/modules/documentCanvas/canvas/utils.js +++ b/src/editor/modules/documentCanvas/canvas/utils.js @@ -42,6 +42,23 @@ var getElementForDetachedNode = function(node, originalParent) { return ptr.getData('canvasElement'); }; +var caretPositionFromPoint = function(x, y) { + /* globals document */ + var range, textNode, offset; + if(document.caretPositionFromPoint) { + range = document.caretPositionFromPoint(x, y); + textNode = range.offsetNode; + offset = range.offset; + } else if(document.caretRangeFromPoint) { + range = document.caretRangeFromPoint(x, y); + textNode = range.startContainer; + offset = range.startOffset; + } + return { + textNode: textNode, + offset: offset + }; +}; return { @@ -51,7 +68,8 @@ return { }, getElementForNode: getElementForNode, getElementForDetachedNode: getElementForDetachedNode, - getElementForElementRootNode: getElementForElementRootNode + getElementForElementRootNode: getElementForElementRootNode, + caretPositionFromPoint: caretPositionFromPoint }; });