UNPKG

jobiqo-cl

Version:

[![CircleCI](https://circleci.com/gh/jobiqo/jobiqo-cl.svg?style=svg&circle-token=5a24efa5b8bbc4879276123e77d0d3f35ca7144c)](https://circleci.com/gh/jobiqo/jobiqo-cl)

42 lines (33 loc) 962 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var focusMerge = require('./focusMerge.js'); var focusOn = function focusOn(target) { target.focus(); if (target.contentWindow) { target.contentWindow.focus(); } }; var guardCount = 0; var lockDisabled = false; var setFocus = (function (topNode, lastNode) { var focusable = focusMerge.default(topNode, lastNode); if (lockDisabled) { return; } if (focusable) { if (guardCount > 2) { // eslint-disable-next-line no-console console.error('FocusLock: focus-fighting detected. Only one focus management system could be active. ' + 'See https://github.com/theKashey/focus-lock/#focus-fighting'); lockDisabled = true; setTimeout(function () { lockDisabled = false; }, 1); return; } guardCount++; focusOn(focusable.node); guardCount--; } }); exports.default = setFocus; exports.focusOn = focusOn;