{"size": 1533, "ext": "js", "max_stars_repo_path": "src/helpers/ariaAppHider.js", "max_stars_repo_name": "expertIOT/react-modal", "max_stars_repo_stars_event_min_datetime": "2015-11-05T21:03:47.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-05T21:03:47.000Z", "max_issues_repo_path": "src/helpers/ariaAppHider.js", "max_issues_repo_name": "expertIOT/react-modal", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/helpers/ariaAppHider.js", "max_forks_repo_name": "expertIOT/react-modal", "max_forks_repo_forks_event_min_datetime": "2015-12-12T20:43:54.000Z", "max_forks_repo_forks_event_max_datetime": "2015-12-12T20:43:54.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 26.4310344828, "max_line_length": 95, "alphanum_fraction": 0.7005870841}
let globalElement = null;

export function assertNodeList(nodeList, selector) {
  if (!nodeList || !nodeList.length) {
    throw new Error(
      `react-modal: No elements were found for selector ${selector}.`
    );
  }
}

export function setElement(element) {
  let useElement = element;
  if (typeof useElement === 'string') {
    const el = document.querySelectorAll(useElement);
    assertNodeList(el, useElement);
    useElement = 'length' in el ? el[0] : el;
  }
  globalElement = useElement || globalElement;
  return globalElement;
}

export function tryForceFallback() {
  if (document && document.body) {
    // force fallback to document.body
    setElement(document.body);
    return true;
  }
  return false;
}

export function validateElement(appElement) {
  if (!appElement && !globalElement && !tryForceFallback()) {
    throw new Error([
      'react-modal: Cannot fallback to `document.body`, because it\'s not ready or available.',
      'If you are doing server-side rendering, use this function to defined an element.',
      '`Modal.setAppElement(el)` to make this accessible'
    ]);
  }
}

export function hide(appElement) {
  validateElement(appElement);
  (appElement || globalElement).setAttribute('aria-hidden', 'true');
}

export function show(appElement) {
  validateElement(appElement);
  (appElement || globalElement).removeAttribute('aria-hidden');
}

export function documentNotReadyOrSSRTesting() {
  globalElement = null;
}

export function resetForTesting() {
  globalElement = document.body;
}
