X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e104b4b87dc39066cbe397984c6f0e6bcc0459f8..2f9850da2c6ad0258f87c3d8972689da6aa8011d:/src/editor/modules/documentCanvas/canvas/utils.js 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 }; });