@uifabric/utilities
Version:
Fluent UI React utilities for building components.
1 lines • 1.71 kB
Source Map (JSON)
{"version":3,"file":"getWindow.js","sourceRoot":"../src/","sources":["dom/getWindow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,IAAI,OAAO,GAAuB,SAAS,CAAC;AAE5C,sFAAsF;AACtF,iFAAiF;AACjF,0EAA0E;AAC1E,IAAI;IACF,OAAO,GAAG,MAAM,CAAC;CAClB;AAAC,OAAO,CAAC,EAAE;IACV,WAAW;CACZ;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,WAA4B;IACpD,IAAI,MAAM,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;QAC5C,OAAO,SAAS,CAAC;KAClB;SAAM;QACL,IAAM,EAAE,GAAG,WAAsB,CAAC;QAElC,OAAO,EAAE,IAAI,EAAE,CAAC,aAAa,IAAI,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC;KACxG;AACH,CAAC","sourcesContent":["import { _isSSR } from './setSSR';\n\nlet _window: Window | undefined = undefined;\n\n// Note: Accessing \"window\" in IE11 is somewhat expensive, and calling \"typeof window\"\n// hits a memory leak, whereas aliasing it and calling \"typeof _window\" does not.\n// Caching the window value at the file scope lets us minimize the impact.\ntry {\n _window = window;\n} catch (e) {\n /* no-op */\n}\n\n/**\n * Helper to get the window object. The helper will make sure to use a cached variable\n * of \"window\", to avoid overhead and memory leaks in IE11. Note that in popup scenarios the\n * window object won't match the \"global\" window object, and for these scenarios, you should\n * pass in an element hosted within the popup.\n *\n * @public\n */\nexport function getWindow(rootElement?: Element | null): Window | undefined {\n if (_isSSR || typeof _window === 'undefined') {\n return undefined;\n } else {\n const el = rootElement as Element;\n\n return el && el.ownerDocument && el.ownerDocument.defaultView ? el.ownerDocument.defaultView : _window;\n }\n}\n"]}