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 /*jshint bitwise: false*/
14 return this.compareDocumentPosition(element) & (direction === 'above' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING);
18 return adj[direction === 'above' ? adj.length-1 : 0];
23 var getElementForElementRootNode = function(node) {
24 return node.getData('canvasElement');
27 var getElementForNode = function(node) {
28 while(!node.getData('canvasElement')) {
31 return node.getData('canvasElement');
34 var getElementForDetachedNode = function(node, originalParent) {
35 var ptr = originalParent;
37 return node.getData('canvasElement');
39 while(!ptr.getData('canvasElement')) {
42 return ptr.getData('canvasElement');
48 nearestInDocumentOrder: nearestInDocumentOrder,
52 getElementForNode: getElementForNode,
53 getElementForDetachedNode: getElementForDetachedNode,
54 getElementForElementRootNode: getElementForElementRootNode