- if(node.nodeType === Node.TEXT_NODE) {
- var parent = node.parent(),
- toret;
-
- parent.children().forEach(function(child) {
- if(child.data('wlxmlNode').sameNode(node))
- toret = child;
- });
- if(toret)
- return toret;
+ while(!ptr.getData('canvasElement')) {
+ ptr = ptr.parent();
+ }
+ 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;