/********************************************************* * fixFirefoxFlexbox.js - a library fix Firefox's * keyboard tabbing of flexbox CSS `order` elements. * * by Zoltan Hawryluk (zoltan.dulac@gmail.com) * * Latest version available at: * - https://github.com/zoltan-dulac/a11y-examples * * More info at: * - http://useragentman.com/blog/Tf4TQ * * Licensed under the MIT License * - https://opensource.org/licenses/MIT ********************************************************/ (function (root, factory) { // AMD if(typeof define === "function" && define.amd) { define(["a11y-examples"], factory); // no AMD } else { root.fixFirefoxFlexbox = factory(root.allyExamples); } }(this, function(a11yExamples) { var fixFirefoxFlexbox = new function () { var me = this, userAgent = navigator.userAgent, isFirefoxDesktop = userAgent.indexOf('Firefox') > -1 && userAgent.indexOf('Mobile') == -1, bodyEl = document.body, // This selector should contain all the tabbable elements that can be in // a document. We need to ensure we are not including the ones with // tabindex="-1", of course. Note that :enabled is used to match all // form elements that are enabled (i.e. not disabled), but we still need // the :not([tabindex="-1"]) since fieldsets are included (I don't know // why, but it is what it is). tabbableElsSelector = 'a[href]:not([tabindex="-1"]), ' + 'area:not([tabindex="-1"]), [role="button"]:not([tabindex="-1"]), ' + '[role="link"]:not([tabindex="-1"]), iframe:not([tabindex="-1"]), ' + '[contentEditable=true]:not([tabindex="-1"]), '+ ':enabled:not([tabindex="-1"]):not([type="radio"]):not(fieldset), ' + 'input[type="radio"]:checked', tabFixClass = 'fixFirefoxFlexbox__tabFix', // This is the max amount a tabindex can have according to // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex tabIndexMax = 32767, observer = null, mutationConfig = { childList: true, subtree: true }; function fixFirefoxFlexbox() { bodyEl.addEventListener('focus', handleFirefoxFocusEvent, true); bodyEl.addEventListener('blur', handleFirefoxBlurEvent, true); bodyEl.addEventListener('keypress', handleFirefoxKeypressEvent, true); } function isTabbable(el) { return ( !el.hidden && el.offsetParent !== null ); } function mutationObserver(mutations) { var doApplyFix = false, affectedNodes = [], node, i, focusedNode, mutation; for (var i=0; i