index.js
function getDocument(node) {
  if (isDocument(node)) {
    return node;

  } else if (isDocument(node.ownerDocument)) {
    return node.ownerDocument;

  } else if (isDocument(node.document)) {
    return node.document;

  } else if (node.parentNode) {
    return getDocument(node.parentNode);

  // Range support
  } else if (node.commonAncestorContainer) {
    return getDocument(node.commonAncestorContainer);

  } else if (node.startContainer) {
    return getDocument(node.startContainer);

  // Selection support
  } else if (node.anchorNode) {
    return getDocument(node.anchorNode);
  }
}
function getDocument(node) {
  if (isDocument(node)) {
    return node;

  } else if (isDocument(node.ownerDocument)) {
    return node.ownerDocument;

  } else if (isDocument(node.document)) {
    return node.document;

  } else if (node.parentNode) {
    return getDocument(node.parentNode);

  // Range support
  } else if (node.commonAncestorContainer) {
    return getDocument(node.commonAncestorContainer);

  } else if (node.startContainer) {
    return getDocument(node.startContainer);

  // Selection support
  } else if (node.anchorNode) {
    return getDocument(node.anchorNode);
  }
}
function getDocument ( node ) { if ( isDocument ( node ) ) { return node ; } else if ( isDocument ( node . ownerDocument ) ) { return node . ownerDocument ; } else if ( isDocument ( node . document ) ) { return node . document ; } else if ( node . parentNode ) { return getDocument ( node . parentNode ) ; // Range support } else if ( node . commonAncestorContainer ) { return getDocument ( node . commonAncestorContainer ) ; } else if ( node . startContainer ) { return getDocument ( node . startContainer ) ; // Selection support } else if ( node . anchorNode ) { return getDocument ( node . anchorNode ) ; } }
Returns the `document` object associated with the given `node`, which may be
a DOM element, the Window object, a Selection, a Range. Basically any DOM
object that references the Document in some way, this function will find it.

@param {Mixed} node - DOM node, selection, or range in which to find the `document` object
@return {Document} the `document` object associated with `node`
@public
Returns the document object associated with the given node which may be a DOM element the Window object a Selection a Range . Basically any DOM object that references the Document in some way this function will find it .