getWindow.js 669 B

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