8 var nearestInDocumentOrder = function(selector, direction, element) {
9 var parents = $(element).parents(),
10 parent = parents.length ? $(parents[parents.length-1]) : element;
12 var adj = parent.find(selector).filter(function() {
13 return this.compareDocumentPosition(element) & (direction === 'above' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING);
17 return adj[direction === 'above' ? adj.length-1 : 0];
22 var findCanvasElement = function(node) {
23 if(node.nodeType === Node.ELEMENT_NODE) {
24 return node.getData('canvasElement');
26 if(node.nodeType === Node.TEXT_NODE) {
27 var parent = node.parent(),
30 parent.children().forEach(function(child) {
31 if(child.data('wlxmlNode').sameNode(node))
40 nearestInDocumentOrder: nearestInDocumentOrder,
41 findCanvasElement: findCanvasElement,