Commit 39a2991e authored by Robert Knight's avatar Robert Knight

Use createNodeIterator polyfill for IE 11 compatibility

The `seek` function from the `dom-seek` package expects its
`NodeIterator` argument to have a `referenceNode` property, which is
missing in IE 11.

Use the dom-node-iterator package recommended by the dom-seek README [1] to
polyfill optional-ness of arguments to `document.createNodeIterator` and
the missing properties on the returned `NodeIterator` object.

dom-node-iterator provides several ways to use the polyfill. This commit
uses the method that prefers the browser's native implementation if possible
and does not pollute the global scope, which could affect JS code
outside of the Hypothesis client.

There is one other place where we use `createNodeIterator` but in that
context the missing properties are not used so the polyfill is not
needed.

Fixes #762

[1] https://github.com/tilgovi/dom-seek/blob/master/README.md
parent 259a52db
seek = require('dom-seek')
# `dom-node-iterator` polyfills optional arguments of `createNodeIterator`
# and properties of the returned `NodeIterator` for IE 11 compatibility.
createNodeIterator = require('dom-node-iterator/polyfill')()
xpathRange = require('./range')
html = require('./html')
......@@ -285,9 +288,7 @@ exports.describe = (root, range, options = {}) ->
startPageIndex = getSiblingIndex(startTextLayer.parentNode)
endPageIndex = getSiblingIndex(endTextLayer.parentNode)
# The `whatToShow`, `filter` and `expandEntityReferences` arguments are
# mandatory in IE although optional according to the spec.
iter = document.createNodeIterator(startTextLayer, NodeFilter.SHOW_TEXT, null, false);
iter = createNodeIterator.call(document, startTextLayer, NodeFilter.SHOW_TEXT)
start = seek(iter, range.start)
end = seek(iter, range.end) + start + range.end.textContent.length
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment