-
Notifications
You must be signed in to change notification settings - Fork 3
/
focusManager.min.js.map
1 lines (1 loc) · 7.9 KB
/
focusManager.min.js.map
1
{"version":3,"sources":["focusManager.min.js"],"names":["root","factory","define","amd","exports","module","focusManager","this","isAncestor","ancestor","descendant","element","parentElement","isDisabled","disabled","isFocusable","Boolean","tabIndex","makeFocusable","findFirstFocusableElement","child","focusableDescendant","children","length","i","findLastFocusableElement","focus","state","lastFocus","resolveFocus","parent","defaultFocus","focusElement","focusFirstInElement","focusLastInElement","releaseModalFocus","eventListenerContext","eventListenerArguments","removeEventListener","apply","restrictFocus","modal","focusedElement","captureModalFocus","backgroundElement","focusCallback","evnt","target","document","addEventListener","capture","release"],"mappings":"CAAE,SAASA,EAAMC,GACO,kBAAXC,SAAyBA,OAAOC,IACzCD,UAAWD,GACiB,gBAAZG,SAChBC,OAAOD,QAAUH,IAEjBD,EAAKM,aAAeL,KAEtBM,KAAM,WACR,YAEA,SAASC,GAAWC,EAAUC,GAE7B,IADA,GAAIC,GAAUD,EACPC,GAAS,CACf,GAAIA,IAAYF,EACf,OAAO,CAERE,GAAUA,EAAQC,cAGnB,OAAO,EAGR,QAASC,GAAWF,GACnB,MAAOA,GAAQG,YAAa,EAG7B,QAASC,GAAYJ,GACpB,MAAOK,SAAQL,IAAYA,EAAQM,UAAY,IAAMJ,EAAWF,GAGjE,QAASO,GAAcP,GAGlBE,EAAWF,KACdA,EAAQG,UAAW,GAGfC,EAAYJ,KAChBA,EAAQM,aAOV,QAASE,GAA0BR,GAClC,GAAII,EAAYJ,GACf,MAAOA,EAQR,KAAK,GAHDS,GACAC,EAHAC,EAAWX,EAAQW,SACnBC,EAASD,EAASC,OAIbC,EAAI,EAAGA,EAAID,EAAQC,GAAK,EAKhC,GAJAJ,EAAQE,EAASE,GAEjBH,EAAsBF,EAA0BC,GAG/C,MAAOC,EAIT,OAAO,MAMR,QAASI,GAAyBd,GAMjC,IAAK,GAHDS,GACAC,EAHAC,EAAWX,EAAQW,SACnBC,EA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,QAAShB,EACTF,oBAAqBA,EACrBC,mBAAoBA,EAErB,OAAO5B","file":"focusManager.min.js","sourcesContent":[";(function(root, factory) {\n if (typeof define === 'function' && define.amd) {\n define([], factory);\n } else if (typeof exports === 'object') {\n module.exports = factory();\n } else {\n root.focusManager = factory();\n }\n}(this, function() {\n\"use strict\";\n\nfunction isAncestor(ancestor, descendant) {\n\tvar element = descendant;\n\twhile (element) {\n\t\tif (element === ancestor) {\n\t\t\treturn true;\n\t\t}\n\t\telement = element.parentElement;\n\t}\n\n\treturn false;\n}\n\nfunction isDisabled(element) {\n\treturn element.disabled === true;\n}\n\nfunction isFocusable(element) {\n\treturn Boolean(element) && element.tabIndex >= 0 && !isDisabled(element);\n}\n\nfunction makeFocusable(element) {\n\t// A tabIndex is needed to make the element focusable\n\t// A tabIndex of -1 means that the element is only programmatically focusable\n\tif (isDisabled(element)) {\n\t\telement.disabled = false;\n\t}\n\n\tif (!isFocusable(element)) {\n\t\telement.tabIndex = -1;\n\t}\n}\n\n// Find the first focusable element.\n// The candidates are the element and it's descendants.\n// The search is performed depth-first.\nfunction findFirstFocusableElement(element) {\n\tif (isFocusable(element)) {\n\t\treturn element;\n\t}\n\n\tvar children = element.children;\n\tvar length = children.length;\n\tvar child;\n\tvar focusableDescendant;\n\n\tfor (var i = 0; i < length; i += 1) {\n\t\tchild = children[i];\n\n\t\tfocusableDescendant = findFirstFocusableElement(child);\n\n\t\tif (focusableDescendant) {\n\t\t\treturn focusableDescendant;\n\t\t}\n\t}\n\n\treturn null;\n}\n\n// Find the first focusable element.\n// The candidates are the element and it's descendants.\n// The search is performed depth-first.\nfunction findLastFocusableElement(element) {\n\tvar children = element.children;\n\tvar length = children.length;\n\tvar child;\n\tvar focusableDescendant;\n\n\tfor (var i = length -1; i >= 0; i -= 1) {\n\t\tchild = children[i];\n\n\t\tfocusableDescendant = findLastFocusableElement(child);\n\n\t\tif (focusableDescendant) {\n\t\t\treturn focusableDescendant;\n\t\t}\n\t}\n\n\tif (isFocusable(element)) {\n\t\treturn element;\n\t}\n\n\treturn null;\n}\n\nfunction focus(element) {\n\tmakeFocusable(element);\n\telement.focus();\n\tstate.lastFocus = element;\n}\n\nfunction resolveFocus(parent, defaultFocus) {\n\tvar focusElement;\n\n\tif (defaultFocus) {\n\t\tfocusElement = defaultFocus;\n\t} else {\n\t\tfocusElement = findFirstFocusableElement(parent) || parent;\n\n\t\tif (focusElement === state.lastFocus) {\n\t\t\tfocusElement = findLastFocusableElement(parent) || parent;\n\t\t}\n\t}\n\n\tfocus(focusElement);\n}\n\nfunction focusFirstInElement(element) {\n\tvar focusElement = findFirstFocusableElement(element) || element;\n\tfocus(focusElement);\n}\n\nfunction focusLastInElement(element) {\n\tvar focusElement = findLastFocusableElement(element) || element;\n\tfocus(focusElement);\n}\n\n// State is kept is these variables.\n// Since only one modal dialog can capture focus at a time the state is a singleton.\nvar state = {\n\teventListenerArguments: null,\n\teventListenerContext: null,\n\tlastFocus: null\n};\n\nfunction releaseModalFocus(focusElement) {\n\tvar eventListenerContext = state.eventListenerContext;\n\tvar eventListenerArguments = state.eventListenerArguments;\n\n\tif (eventListenerContext && eventListenerArguments) {\n\t\teventListenerContext.removeEventListener.apply(eventListenerContext, eventListenerArguments);\n\t}\n\n\t// Reset the state object\n\tstate.eventListenerContext = null;\n\tstate.eventListenerArguments = null;\n\tstate.lastFocus = null;\n\n\tif (focusElement) {\n\t\tfocusElement.focus();\n\t}\n}\n\n// Keep focus inside the modal\nfunction restrictFocus(modal, focusedElement) {\n\tif (isAncestor(modal, focusedElement)) {\n\t\tstate.lastFocus = focusedElement;\n\t} else {\n\t\tresolveFocus(modal);\n\t}\n}\n\n// modal, the element in which to contain focus\n// focusElement (optional), the element inside the modal to focus when opening\n// backgroundElement (optional), All focus events within this element are redirected to the modal. Defaults to document\nfunction captureModalFocus(modal, focusElement, backgroundElement) {\n\n\t// without a modal there is nothing to capture\n\tif (!modal) {\n\t\treturn null;\n\t}\n\n\t// If any focus is already being captured, release it now\n\treleaseModalFocus();\n\n\t// focus the modal so the user knows it was opened\n\tresolveFocus(modal, focusElement);\n\n\t// Whenever an element outside of the modal is focused, the modal is focused instead\n\tfunction focusCallback(evnt) {\n\t\trestrictFocus(modal, evnt.target);\n\t}\n\n\t// The focus event does not bubble\n\t// however it can be captured on an ancestor element\n\t// by setting useCapture to true\n\tvar eventListenerContext = backgroundElement || document;\n\tvar eventListenerArguments = [\"focus\", focusCallback, true];\n\n\t// Save the eventListener data in the state object so it can be removed later\n\t// by the releaseModalFocus function\n\tstate.eventListenerContext = eventListenerContext;\n\tstate.eventListenerArguments = eventListenerArguments;\n\n\teventListenerContext.addEventListener.apply(eventListenerContext, eventListenerArguments);\n}\n\nvar focusManager = {\n\tcapture: captureModalFocus,\n\trelease: releaseModalFocus,\n\tfocusFirstInElement: focusFirstInElement,\n\tfocusLastInElement: focusLastInElement\n};\nreturn focusManager;\n}));\n"],"sourceRoot":"/source/"}