getWindow.js 645 B

1234567891011121314151617
  1. function getWindow(node) {
  2. var _node_ownerDocument;
  3. if (isDocument(node) && node.defaultView) {
  4. return node.defaultView;
  5. } else if ((_node_ownerDocument = node.ownerDocument) === null || _node_ownerDocument === undefined ? undefined : _node_ownerDocument.defaultView) {
  6. return node.ownerDocument.defaultView;
  7. }
  8. throw new Error(`Could not determine window of node. Node was ${describe(node)}`);
  9. }
  10. function isDocument(node) {
  11. return node.nodeType === 9;
  12. }
  13. function describe(val) {
  14. return typeof val === 'function' ? `function ${val.name}` : val === null ? 'null' : String(val);
  15. }
  16. export { getWindow };