@@ -36,13 +36,13 @@ var Annotate = {
3636 return Annotate . findXPath ( elt [ 0 ] . nextSibling ) ;
3737 }
3838 //look next for preceding sibling line breaks in the same container with an @id or @n.
39- var lb = document . evaluate ( "preceding::lb[1]" , elt [ 0 ] , null , XPathResult . FIRST_ORDERED_NODE_TYPE , null ) ;
39+ var lb = elt [ 0 ] . ownerDocument . evaluate ( "preceding::lb[1]" , elt [ 0 ] , null , XPathResult . FIRST_ORDERED_NODE_TYPE , null ) ;
4040 lb = lb . singleNodeValue ;
4141 if ( lb != null ) {
4242 var lbp , eltp ;
43- lbp = document . evaluate ( "ancestor::*[not(starts-with(@id, 'teibp-')) or @n][1]" , lb , null , XPathResult . FIRST_ORDERED_NODE_TYPE , null ) ;
43+ lbp = lb . ownerDocument . evaluate ( "ancestor::*[not(starts-with(@id, 'teibp-')) or @n][1]" , lb , null , XPathResult . FIRST_ORDERED_NODE_TYPE , null ) ;
4444 lbp = lbp . singleNodeValue ;
45- eltp = document . evaluate ( "ancestor::*[not(starts-with(@id, 'teibp-')) or @n][1]" , elt [ 0 ] , null , XPathResult . FIRST_ORDERED_NODE_TYPE , null ) ;
45+ eltp = elt [ 0 ] . ownerDocument . evaluate ( "ancestor::*[not(starts-with(@id, 'teibp-')) or @n][1]" , elt [ 0 ] , null , XPathResult . FIRST_ORDERED_NODE_TYPE , null ) ;
4646 eltp = eltp . singleNodeValue ;
4747 if ( lbp == eltp ) {
4848 return Annotate . findXPath ( lb ) ;
@@ -102,11 +102,11 @@ var Annotate = {
102102 // we got nothin'. Build a nasty, big, literal XPath
103103 path = [ ] ;
104104 xpath = "count(preceding-sibling::" + elt [ 0 ] . localName + ")" ;
105- var count = document . evaluate ( xpath , elt [ 0 ] , null , XPathResult . NUMBER , null ) . numberValue ;
105+ var count = elt [ 0 ] . ownerDocument . evaluate ( xpath , elt [ 0 ] , null , XPathResult . NUMBER , null ) . numberValue ;
106106 path . push ( elt [ 0 ] . localName + "[" + ( count + 1 ) + "]" ) ;
107107 for ( var i = 0 ; i < parents . length - 1 ; i ++ ) {
108108 xpath = "count(preceding-sibling::" + parents [ i ] . localName + ")" ;
109- count = document . evaluate ( xpath , parents [ i ] , null , XPathResult . NUMBER , null ) . numberValue ;
109+ count = parents [ i ] . ownerDocument . evaluate ( xpath , parents [ i ] , null , XPathResult . NUMBER , null ) . numberValue ;
110110 path . push ( parents [ i ] . localName + "[" + ( count + 1 ) + "]" ) ;
111111 }
112112 return [ "//" + path . reverse ( ) . join ( "/" ) , elt [ 0 ] ] ;
@@ -125,7 +125,7 @@ var Annotate = {
125125 var curr = context ;
126126 while ( curr != anchor ) {
127127 curr = curr . nextSibling ;
128- var desc = document . evaluate ( "descendant-or-self::node()" , curr , null , XPathResult . ORDERED_NODE_ITERATOR_TYPE , null ) ;
128+ var desc = curr . ownerDocument . evaluate ( "descendant-or-self::node()" , curr , null , XPathResult . ORDERED_NODE_ITERATOR_TYPE , null ) ;
129129 var item ;
130130 while ( item = desc . iterateNext ( ) ) {
131131 if ( item . nodeType == Node . TEXT_NODE && item != anchor ) {
@@ -190,7 +190,7 @@ var Annotate = {
190190 var curr = context ;
191191 while ( curr != anchor ) {
192192 curr = curr . nextSibling ;
193- var desc = document . evaluate ( "descendant-or-self::node()" , curr , null , XPathResult . ORDERED_NODE_ITERATOR_TYPE , null ) ;
193+ var desc = curr . ownerDocument . evaluate ( "descendant-or-self::node()" , curr , null , XPathResult . ORDERED_NODE_ITERATOR_TYPE , null ) ;
194194 var item ;
195195 while ( item = desc . iterateNext ( ) ) {
196196 if ( item . nodeType == Node . TEXT_NODE && item != anchor ) {
@@ -225,7 +225,7 @@ var Annotate = {
225225 if ( selection . getRangeAt ( 0 ) . startContainer == selection . getRangeAt ( 0 ) . endContainer ) {
226226 path = Annotate . findXPath ( selection . getRangeAt ( 0 ) . startContainer ) ;
227227 } else {
228- var lb = document . evaluate ( "preceding-sibling::lb[1]" , selection . getRangeAt ( 0 ) . startContainer , null , XPathResult . FIRST_ORDERED_NODE_TYPE , null ) ;
228+ var lb = selection . getRangeAt ( 0 ) . startContainer . ownerDocument . evaluate ( "preceding-sibling::lb[1]" , selection . getRangeAt ( 0 ) . startContainer , null , XPathResult . FIRST_ORDERED_NODE_TYPE , null ) ;
229229 if ( lb = lb . singleNodeValue ) {
230230 path = Annotate . findXPath ( lb ) ;
231231 } else {
0 commit comments