Comparing version 0.3.0 to 0.3.1
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.tolefocus=e.tolefocus||{})}(this,function(e){"use strict";function t(e){return void 0!==e}var o=function(){function e(){this.items=[],this.orderedItems=[]}return e.prototype.insert=function(e,t,o){var r=this.items.findIndex(function(e){return e.object===t});if(r>=0){if(r===e&&o>=0)return this.items[r].order=o,void this.reorder();this.items.splice(r,1)}e||0===e?this.items.splice(e,0,{object:t,order:o}):this.items.push({object:t,order:o}),this.reorder()},e.prototype.reorder=function(){var e=this,o=[],r=this.items.filter(function(e){return t(e.order)&&e.order<0}),n=this.items.filter(function(e){return t(e.order)&&e.order>=0}),i=this.items.filter(function(e){return!t(e.order)});n.forEach(function(e){o[e.order]=e});for(var s=0,u=0,l=this.items.length;u<l;u++)void 0===o[u]&&s<i.length&&(o[u]=i[s++]);o.splice.apply(o,[0,0].concat(r.sort(function(e,t){return t.order-e.order}))),this.orderedItems=[],o.forEach(function(t){void 0!==t&&e.orderedItems.push(t)})},e.prototype.remove=function(e){var t=this.items.findIndex(function(t){return t.object===e});t>=0&&this.items.splice(t,1),this.reorder()},e}(),r=function(){function e(e){var t=this;this.element=e,this.keyPressHandler=function(e){h.enabled&&9===e.keyCode&&(e.shiftKey?h.focusPrior(t.element):h.focusNext(t.element),e.preventDefault(),e.stopPropagation())},this.handle()}return e.prototype.unhandle=function(){this.element.removeEventListener("keydown",this.keyPressHandler)},e.prototype.handle=function(){this.element.addEventListener("keydown",this.keyPressHandler)},e}(),n=function(){function e(t,o){var r=this;this.element=t,this.callback=o,this.check=function(){var e=s.canElementGetFocus(r.element);e!==r.focusable&&(r.focusable=e,r.callback(r.focusable))},this.focusable=s.canElementGetFocus(t),this.intervalHandle=setInterval(this.check,100),e.inspectorsList.push(this)}return e.stopAll=function(){for(;this.inspectorsList.length>0;)this.inspectorsList[0].stop()},e.prototype.stop=function(){clearInterval(this.intervalHandle);var t=e.inspectorsList.indexOf(this);e.inspectorsList.splice(t,1)},e}();n.inspectorsList=[];var i=function(){function e(){this._customSelectors=[]}return e.prototype.setCanElementGetFocusHandler=function(e){this._canElementGetFocusHandler=e},e.prototype.addCustomSelector=function(e){this._customSelectors.push(e)},e.prototype.removeCustomSelector=function(e){var t=this._customSelectors.indexOf(e);t&&this._customSelectors.splice(t,1)},e.prototype.getFocusElementsSelector=function(){return f.concat(["["+c+"]","["+p+"]"],this._customSelectors).join(",")},e.prototype.removeGroup=function(e){var t=this.getElementInfo(e);t&&t.parentGroup.remove(t.group)},e.prototype.removeElement=function(e){var t=this.getElementInfo(e);t&&t.parentGroup.remove(e),e.TOLEFOCUS_INSPECTOR&&e.TOLEFOCUS_INSPECTOR.stop()},e.prototype.getElementInfo=function(e){return e[u]},e.prototype.isGroup=function(e){var t=e.getAttribute(c);return null!==t&&void 0!==t},e.prototype.isElement=function(e){var t=e.getAttribute(p);return e.matches(this.getFocusElementsSelector())||null!==t&&void 0!==t},e.prototype.processRemovedElement=function(e){e.getAttribute&&(this.isGroup(e)?this.removeGroup(e):this.isElement(e)&&this.removeElement(e))},e.prototype.locateParentGroupElement=function(e){for(var t=e;null!==(t=t.parentElement);)if(this.isGroup(t))return t;return t},e.prototype.getElementOrder=function(e){var t=e.getAttribute(p);if(null!==t&&void 0!==t&&""!==t)return parseInt(t,10)},e.prototype.isGroupChildren=function(e,t){for(;null!==t.parentElement;){if(this.isGroup(t.parentElement)||t.parentElement===document.body)return t.parentElement===e;t=t.parentElement}return!1},e.prototype.getDOMOrderInGroup=function(e,t){for(var o=e.querySelectorAll(this.getFocusElementsSelector()),r=[],n=0,i=o.length;n<i;n++){var s=o.item(n);this.isGroupChildren(e,s)&&r.push(s)}for(var n=0,i=r.length;n<i;n++)if(r[n]===t)return n},e.prototype.getGroupProperties=function(e){var t=e.getAttribute(c);if(""===t)return{head:void 0,tail:void 0};var o,r,n=t.split(" ").filter(function(e){return""!==e}).filter(function(e,t){return t<2});return 1===n.length?(o=n[0],r=n[0]):2===n.length&&(r=n[0],o=n[1]),{head:r,tail:o}},e.prototype.addGroup=function(e){var t=this.locateParentGroupElement(e),o=t?this.getElementInfo(t).group:h.root,r=this.getGroupProperties(e),n=r.head,i=r.tail,s=new l(o,e,n,i);o.add(s,this.getElementOrder(e))},e.prototype.canElementGetFocus=function(e){if(this._canElementGetFocusHandler){var t=this._canElementGetFocusHandler(e);if(void 0!==t)return t}var o=null!==e.offsetParent,r=!!e.disabled;return o&&!r},e.prototype.addElement=function(e){var t=this.locateParentGroupElement(e);(t?this.getElementInfo(t).group:h.root).add(e,this.getElementOrder(e));var o=e.getAttribute(a);null!==o&&void 0!==o&&(this.canElementGetFocus(e)&&e.focus(),o===d&&(e.TOLEFOCUS_INSPECTOR=new n(e,function(t){t&&e.focus()})))},e.prototype.processAddedElement=function(e){e.getAttribute&&(this.isGroup(e)?this.addGroup(e):this.isElement(e)&&this.addElement(e))},e.prototype.removeChildrenFromElement=function(e){if(e.getAttribute)for(var t=e.querySelectorAll(this.getFocusElementsSelector()),o=0,r=t.length;o<r;o++)this.processRemovedElement(t.item(o))},e.prototype.processFromElement=function(e){if(e.getAttribute)for(var t=e.querySelectorAll(this.getFocusElementsSelector()),o=0,r=t.length;o<r;o++)this.processAddedElement(t.item(o))},e}(),s=new i,u="TOLEFOCUS_INFO",l=function(){function e(e,t,r,n){void 0===r&&(r=""),void 0===n&&(n=""),this.parentGroup=e,this.groupElement=t,this.headBehavior=r,this.tailBehavior=n,this.items=new o}return Object.defineProperty(e.prototype,"count",{get:function(){return this.items.orderedItems.length},enumerable:!0,configurable:!0}),e.prototype.add=function(t,o){var n;t instanceof e?(n=s.getDOMOrderInGroup(this.groupElement,t.groupElement),t.groupElement[u]||(t.groupElement[u]={parentGroup:this,group:t})):(n=s.getDOMOrderInGroup(this.groupElement,t),t.setAttribute("tabindex","-1"),t[u]||(t[u]={parentGroup:this,eventsHandler:new r(t)})),this.items.insert(n,t,o)},e.prototype.remove=function(t){t instanceof e||!t[u]||t[u].eventsHandler.unhandle(),this.items.remove(t)},e.prototype.fistElementRecursively=function(){for(var t=0,o=this.items.orderedItems;t<o.length;t++){var r=o[t].object;if(!(r instanceof e))return r;var n=r.fistElementRecursively();if(n)return n}},e.prototype.lastElementRecursively=function(){for(var t=this.items.orderedItems.length-1;t>=0;t--){var o=this.items.orderedItems[t].object;if(!(o instanceof e))return o;var r=o.lastElementRecursively();if(r)return r}},e.prototype.locateElementRecursively=function(t){for(var o=0,r=0,n=this.items.orderedItems;r<n.length;r++){var i=n[r].object;if(i instanceof e){var s=i.locateElementRecursively(t);if(s.group)return s}else if(i===t)return{group:this,elementIndex:o};o++}return{group:void 0,elementIndex:void 0}},e.prototype.getItemIndexByElement=function(t){return this.items.orderedItems.findIndex(function(o){return o.object instanceof e&&o.object.groupElement===t||!(o.object instanceof e)&&o.object===t})},e.prototype.getNextElement=function(t){var o,r=this.getItemIndexByElement(t);if(r>=0)if(r<this.items.orderedItems.length-1)o=r+1;else if("loop"===this.tailBehavior)o=0;else if("stop"===this.tailBehavior)o=r;else if(this.parentGroup){var n=this.parentGroup.getNextElement(this.groupElement);if(n)return n}if(void 0!==o){var i=this.items.orderedItems[o];return i.object instanceof e?0===i.object.count?this.getNextElement(i.object.groupElement):i.object.fistElementRecursively():i.object}},e.prototype.getPriorElement=function(t){var o,r=this.getItemIndexByElement(t);if(r>=0)if(r>0)o=r-1;else if("loop"===this.headBehavior)o=this.items.orderedItems.length-1;else if("stop"===this.headBehavior)o=r;else if(this.parentGroup){var n=this.parentGroup.getPriorElement(this.groupElement);if(n)return n}if(void 0!==o){var i=this.items.orderedItems[o];return i.object instanceof e?i.object.lastElementRecursively():i.object}},e}(),c="focus-group",p="focus-order",a="autofocus",f=["a","select","button","input","textarea"],d="observe",m=function(){function e(){this._enabled=!1}return Object.defineProperty(e.prototype,"root",{get:function(){return this._root},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},enumerable:!0,configurable:!0}),e.prototype.addCustomSelector=function(e){s.addCustomSelector(e)},e.prototype.removeCustomSelector=function(e){s.removeCustomSelector(e)},e.prototype.setCanElementGetFocusHandler=function(e){s.setCanElementGetFocusHandler(e)},e.prototype.focusNext=function(e){e||(e=document.activeElement);var t=this.root.locateElementRecursively(e).group;if(t){for(var o=t.getNextElement(e);!s.canElementGetFocus(o);){o=s.getElementInfo(o).parentGroup.getNextElement(o)}o&&o.focus()}},e.prototype.focusPrior=function(e){e||(e=document.activeElement);var t=this.root.locateElementRecursively(e).group;if(t){for(var o=t.getPriorElement(e);!s.canElementGetFocus(o);){o=s.getElementInfo(o).parentGroup.getPriorElement(o)}o&&o.focus()}},e.prototype.disable=function(){this._enabled&&(this._enabled=!1,n.stopAll())},e.prototype.enable=function(e,t,o){void 0===t&&(t="loop"),void 0===o&&(o="loop"),this._enabled&&this.disable(),e||(e=document.body),this._root=new l(null,e,t,o),this._enabled=!0,s.processFromElement(e)},e}(),h=new m,v=function(){function e(){var e=this;this._enabled=!1,this.observer=new MutationObserver(function(t){return e.observerCallback(t)})}return Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rootElement",{get:function(){return this._rootElement},enumerable:!0,configurable:!0}),e.prototype.disable=function(){this._enabled&&(this.observer.disconnect(),this._enabled=!1)},e.prototype.enable=function(e){this._enabled&&this.disable(),e||(e=document.body);var t={childList:!0,subtree:!0};this.observer.observe(e,t)},e.prototype.observerCallback=function(e){var t=this;e.forEach(function(e){return t.processMutation(e)})},e.prototype.processMutation=function(e){if("childList"===e.type){for(var t=0,o=e.addedNodes.length;t<o;t++)s.processAddedElement(e.addedNodes.item(t)),s.processFromElement(e.addedNodes.item(t));for(var t=0,o=e.removedNodes.length;t<o;t++)s.processRemovedElement(e.removedNodes.item(t)),s.removeChildrenFromElement(e.removedNodes.item(t))}},e}(),E=new v;e.focusManager=h,e.focusObserver=E,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.tolefocus=e.tolefocus||{})}(this,function(e){"use strict";function t(e){return void 0!==e}function o(){var e=Element.prototype;Element.prototype.matches||(Element.prototype.matches=e.matchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector||e.webkitMatchesSelector||function(e){for(var t=(this.document||this.ownerDocument).querySelectorAll(e),o=t.length;--o>=0&&t.item(o)!==this;);return o>-1})}function r(){o()}var n=function(){function e(){this.items=[],this.orderedItems=[]}return e.prototype.insert=function(e,t,o){var r=this.items.findIndex(function(e){return e.object===t});if(r>=0){if(r===e&&o>=0)return this.items[r].order=o,void this.reorder();this.items.splice(r,1)}e||0===e?this.items.splice(e,0,{object:t,order:o}):this.items.push({object:t,order:o}),this.reorder()},e.prototype.reorder=function(){var e=this,o=[],r=this.items.filter(function(e){return t(e.order)&&e.order<0}),n=this.items.filter(function(e){return t(e.order)&&e.order>=0}),i=this.items.filter(function(e){return!t(e.order)});n.forEach(function(e){o[e.order]=e});for(var s=0,u=0,l=this.items.length;u<l;u++)void 0===o[u]&&s<i.length&&(o[u]=i[s++]);o.splice.apply(o,[0,0].concat(r.sort(function(e,t){return t.order-e.order}))),this.orderedItems=[],o.forEach(function(t){void 0!==t&&e.orderedItems.push(t)})},e.prototype.remove=function(e){var t=this.items.findIndex(function(t){return t.object===e});t>=0&&this.items.splice(t,1),this.reorder()},e}(),i=function(){function e(e){var t=this;this.element=e,this.keyPressHandler=function(e){E.enabled&&9===e.keyCode&&(e.shiftKey?E.focusPrior(t.element):E.focusNext(t.element),e.preventDefault(),e.stopPropagation())},this.handle()}return e.prototype.unhandle=function(){this.element.removeEventListener("keydown",this.keyPressHandler)},e.prototype.handle=function(){this.element.addEventListener("keydown",this.keyPressHandler)},e}(),s=function(){function e(t,o){var r=this;this.element=t,this.callback=o,this.check=function(){var e=l.canElementGetFocus(r.element);e!==r.focusable&&(r.focusable=e,r.callback(r.focusable))},this.focusable=l.canElementGetFocus(t),this.intervalHandle=setInterval(this.check,100),e.inspectorsList.push(this)}return e.stopAll=function(){for(;this.inspectorsList.length>0;)this.inspectorsList[0].stop()},e.prototype.stop=function(){clearInterval(this.intervalHandle);var t=e.inspectorsList.indexOf(this);e.inspectorsList.splice(t,1)},e}();s.inspectorsList=[];var u=function(){function e(){this._customSelectors=[]}return e.prototype.setCanElementGetFocusHandler=function(e){this._canElementGetFocusHandler=e},e.prototype.addCustomSelector=function(e){this._customSelectors.push(e)},e.prototype.removeCustomSelector=function(e){var t=this._customSelectors.indexOf(e);t&&this._customSelectors.splice(t,1)},e.prototype.getFocusElementsSelector=function(){return m.concat(["["+p+"]","["+f+"]"],this._customSelectors).join(",")},e.prototype.removeGroup=function(e){var t=this.getElementInfo(e);t&&t.parentGroup.remove(t.group)},e.prototype.removeElement=function(e){var t=this.getElementInfo(e);t&&t.parentGroup.remove(e),e.TOLEFOCUS_INSPECTOR&&e.TOLEFOCUS_INSPECTOR.stop()},e.prototype.getElementInfo=function(e){return e[c]},e.prototype.isGroup=function(e){var t=e.getAttribute(p);return null!==t&&void 0!==t},e.prototype.isElement=function(e){var t=e.getAttribute(f);return e.matches(this.getFocusElementsSelector())||null!==t&&void 0!==t},e.prototype.processRemovedElement=function(e){e.getAttribute&&(this.isGroup(e)?this.removeGroup(e):this.isElement(e)&&this.removeElement(e))},e.prototype.locateParentGroupElement=function(e){for(var t=e;null!==(t=t.parentElement);)if(this.isGroup(t))return t;return t},e.prototype.getElementOrder=function(e){var t=e.getAttribute(f);if(null!==t&&void 0!==t&&""!==t)return parseInt(t,10)},e.prototype.isGroupChildren=function(e,t){for(;null!==t.parentElement;){if(this.isGroup(t.parentElement)||t.parentElement===document.body)return t.parentElement===e;t=t.parentElement}return!1},e.prototype.getDOMOrderInGroup=function(e,t){for(var o=e.querySelectorAll(this.getFocusElementsSelector()),r=[],n=0,i=o.length;n<i;n++){var s=o.item(n);this.isGroupChildren(e,s)&&r.push(s)}for(var n=0,i=r.length;n<i;n++)if(r[n]===t)return n},e.prototype.getGroupProperties=function(e){var t=e.getAttribute(p);if(""===t)return{head:void 0,tail:void 0};var o,r,n=t.split(" ").filter(function(e){return""!==e}).filter(function(e,t){return t<2});return 1===n.length?(o=n[0],r=n[0]):2===n.length&&(r=n[0],o=n[1]),{head:r,tail:o}},e.prototype.addGroup=function(e){var t=this.locateParentGroupElement(e),o=t?this.getElementInfo(t).group:E.root,r=this.getGroupProperties(e),n=r.head,i=r.tail,s=new a(o,e,n,i);o.add(s,this.getElementOrder(e))},e.prototype.canElementGetFocus=function(e){if(this._canElementGetFocusHandler){var t=this._canElementGetFocusHandler(e);if(void 0!==t)return t}var o=null!==e.offsetParent,r=!!e.disabled;return o&&!r},e.prototype.addElement=function(e){var t=this.locateParentGroupElement(e);(t?this.getElementInfo(t).group:E.root).add(e,this.getElementOrder(e));var o=e.getAttribute(d);null!==o&&void 0!==o&&(this.canElementGetFocus(e)&&e.focus(),o===h&&(e.TOLEFOCUS_INSPECTOR=new s(e,function(t){t&&e.focus()})))},e.prototype.processAddedElement=function(e){e.getAttribute&&(this.isGroup(e)?this.addGroup(e):this.isElement(e)&&this.addElement(e))},e.prototype.removeChildrenFromElement=function(e){if(e.getAttribute)for(var t=e.querySelectorAll(this.getFocusElementsSelector()),o=0,r=t.length;o<r;o++)this.processRemovedElement(t.item(o))},e.prototype.processFromElement=function(e){if(e.getAttribute)for(var t=e.querySelectorAll(this.getFocusElementsSelector()),o=0,r=t.length;o<r;o++)this.processAddedElement(t.item(o))},e}(),l=new u,c="TOLEFOCUS_INFO",a=function(){function e(e,t,o,r){void 0===o&&(o=""),void 0===r&&(r=""),this.parentGroup=e,this.groupElement=t,this.headBehavior=o,this.tailBehavior=r,this.items=new n}return Object.defineProperty(e.prototype,"count",{get:function(){return this.items.orderedItems.length},enumerable:!0,configurable:!0}),e.prototype.add=function(t,o){var r;t instanceof e?(r=l.getDOMOrderInGroup(this.groupElement,t.groupElement),t.groupElement[c]||(t.groupElement[c]={parentGroup:this,group:t})):(r=l.getDOMOrderInGroup(this.groupElement,t),t.setAttribute("tabindex","-1"),t[c]||(t[c]={parentGroup:this,eventsHandler:new i(t)})),this.items.insert(r,t,o)},e.prototype.remove=function(t){t instanceof e||!t[c]||t[c].eventsHandler.unhandle(),this.items.remove(t)},e.prototype.fistElementRecursively=function(){for(var t=0,o=this.items.orderedItems;t<o.length;t++){var r=o[t].object;if(!(r instanceof e))return r;var n=r.fistElementRecursively();if(n)return n}},e.prototype.lastElementRecursively=function(){for(var t=this.items.orderedItems.length-1;t>=0;t--){var o=this.items.orderedItems[t].object;if(!(o instanceof e))return o;var r=o.lastElementRecursively();if(r)return r}},e.prototype.locateElementRecursively=function(t){for(var o=0,r=0,n=this.items.orderedItems;r<n.length;r++){var i=n[r].object;if(i instanceof e){var s=i.locateElementRecursively(t);if(s.group)return s}else if(i===t)return{group:this,elementIndex:o};o++}return{group:void 0,elementIndex:void 0}},e.prototype.getItemIndexByElement=function(t){return this.items.orderedItems.findIndex(function(o){return o.object instanceof e&&o.object.groupElement===t||!(o.object instanceof e)&&o.object===t})},e.prototype.getNextElement=function(t){var o,r=this.getItemIndexByElement(t);if(r>=0)if(r<this.items.orderedItems.length-1)o=r+1;else if("loop"===this.tailBehavior)o=0;else if("stop"===this.tailBehavior)o=r;else if(this.parentGroup){var n=this.parentGroup.getNextElement(this.groupElement);if(n)return n}if(void 0!==o){var i=this.items.orderedItems[o];return i.object instanceof e?0===i.object.count?this.getNextElement(i.object.groupElement):i.object.fistElementRecursively():i.object}},e.prototype.getPriorElement=function(t){var o,r=this.getItemIndexByElement(t);if(r>=0)if(r>0)o=r-1;else if("loop"===this.headBehavior)o=this.items.orderedItems.length-1;else if("stop"===this.headBehavior)o=r;else if(this.parentGroup){var n=this.parentGroup.getPriorElement(this.groupElement);if(n)return n}if(void 0!==o){var i=this.items.orderedItems[o];return i.object instanceof e?i.object.lastElementRecursively():i.object}},e}(),p="focus-group",f="focus-order",d="autofocus",m=["a","select","button","input","textarea"],h="observe",v=function(){function e(){this._enabled=!1}return Object.defineProperty(e.prototype,"root",{get:function(){return this._root},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},enumerable:!0,configurable:!0}),e.prototype.addCustomSelector=function(e){l.addCustomSelector(e)},e.prototype.removeCustomSelector=function(e){l.removeCustomSelector(e)},e.prototype.setCanElementGetFocusHandler=function(e){l.setCanElementGetFocusHandler(e)},e.prototype.focusNext=function(e){e||(e=document.activeElement);var t=this.root.locateElementRecursively(e).group;if(t){for(var o=t.getNextElement(e);!l.canElementGetFocus(o);){o=l.getElementInfo(o).parentGroup.getNextElement(o)}o&&o.focus()}},e.prototype.focusPrior=function(e){e||(e=document.activeElement);var t=this.root.locateElementRecursively(e).group;if(t){for(var o=t.getPriorElement(e);!l.canElementGetFocus(o);){o=l.getElementInfo(o).parentGroup.getPriorElement(o)}o&&o.focus()}},e.prototype.disable=function(){this._enabled&&(this._enabled=!1,s.stopAll())},e.prototype.enable=function(e,t,o){void 0===t&&(t="loop"),void 0===o&&(o="loop"),r(),this._enabled&&this.disable(),e||(e=document.body),this._root=new a(null,e,t,o),this._enabled=!0,l.processFromElement(e)},e}(),E=new v,y=function(){function e(){var e=this;this._enabled=!1,this.observer=new MutationObserver(function(t){return e.observerCallback(t)})}return Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rootElement",{get:function(){return this._rootElement},enumerable:!0,configurable:!0}),e.prototype.disable=function(){this._enabled&&(this.observer.disconnect(),this._enabled=!1)},e.prototype.enable=function(e){this._enabled&&this.disable(),e||(e=document.body);var t={childList:!0,subtree:!0};this.observer.observe(e,t)},e.prototype.observerCallback=function(e){var t=this;e.forEach(function(e){return t.processMutation(e)})},e.prototype.processMutation=function(e){if("childList"===e.type){for(var t=0,o=e.addedNodes.length;t<o;t++)l.processAddedElement(e.addedNodes.item(t)),l.processFromElement(e.addedNodes.item(t));for(var t=0,o=e.removedNodes.length;t<o;t++)l.processRemovedElement(e.removedNodes.item(t)),l.removeChildrenFromElement(e.removedNodes.item(t))}},e}(),b=new y;e.focusManager=E,e.focusObserver=b,Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -86,2 +86,3 @@ (function (global, factory) { | ||
var TAB_KEYCODE = 9; | ||
// const ENTER_KEYCODE = 13; | ||
var ElementEventsHandler = (function () { | ||
@@ -256,3 +257,3 @@ function ElementEventsHandler(element) { | ||
} | ||
var parts = value.split(" ").filter(function (part) { return part !== ""; }).filter(function (value, index) { return index < 2; }); | ||
var parts = value.split(" ").filter(function (part) { return part !== ""; }).filter(function (_value, index) { return index < 2; }); | ||
var tail, head; | ||
@@ -520,2 +521,22 @@ if (parts.length === 1) { | ||
function matches_polyfills() { | ||
var prototype = Element.prototype; | ||
if (!Element.prototype.matches) { | ||
Element.prototype.matches = | ||
prototype.matchesSelector || | ||
prototype.mozMatchesSelector || | ||
prototype.msMatchesSelector || | ||
prototype.oMatchesSelector || | ||
prototype.webkitMatchesSelector || | ||
function (s) { | ||
var matches = (this.document || this.ownerDocument).querySelectorAll(s), i = matches.length; | ||
while (--i >= 0 && matches.item(i) !== this) { } | ||
return i > -1; | ||
}; | ||
} | ||
} | ||
function setPolyfills() { | ||
matches_polyfills(); | ||
} | ||
var focusGroupAttributeName = "focus-group"; | ||
@@ -595,2 +616,3 @@ var focusOrderAttributeName = "focus-order"; | ||
if (tailBehavior === void 0) { tailBehavior = "loop"; } | ||
setPolyfills(); | ||
if (this._enabled) { | ||
@@ -597,0 +619,0 @@ this.disable(); |
@@ -1,46 +0,34 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "./FocusManager"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var FocusManager_1 = require("./FocusManager"); | ||
var TAB_KEYCODE = 9; | ||
// const ENTER_KEYCODE = 13; | ||
var ElementEventsHandler = (function () { | ||
function ElementEventsHandler(element) { | ||
var _this = this; | ||
this.element = element; | ||
this.keyPressHandler = function (event) { | ||
if (FocusManager_1.focusManager.enabled) { | ||
if (event.keyCode === TAB_KEYCODE) { | ||
if (event.shiftKey) { | ||
FocusManager_1.focusManager.focusPrior(_this.element); | ||
} | ||
else { | ||
FocusManager_1.focusManager.focusNext(_this.element); | ||
} | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
import { focusManager } from "./FocusManager"; | ||
var TAB_KEYCODE = 9; | ||
// const ENTER_KEYCODE = 13; | ||
var ElementEventsHandler = (function () { | ||
function ElementEventsHandler(element) { | ||
var _this = this; | ||
this.element = element; | ||
this.keyPressHandler = function (event) { | ||
if (focusManager.enabled) { | ||
if (event.keyCode === TAB_KEYCODE) { | ||
if (event.shiftKey) { | ||
focusManager.focusPrior(_this.element); | ||
} | ||
else { | ||
focusManager.focusNext(_this.element); | ||
} | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
}; | ||
this.handle(); | ||
} | ||
ElementEventsHandler.prototype.unhandle = function () { | ||
this.element.removeEventListener("keydown", this.keyPressHandler); | ||
} | ||
}; | ||
ElementEventsHandler.prototype.handle = function () { | ||
var elem = this.element; | ||
elem.addEventListener("keydown", this.keyPressHandler); | ||
}; | ||
return ElementEventsHandler; | ||
}()); | ||
exports.ElementEventsHandler = ElementEventsHandler; | ||
}); | ||
this.handle(); | ||
} | ||
ElementEventsHandler.prototype.unhandle = function () { | ||
this.element.removeEventListener("keydown", this.keyPressHandler); | ||
}; | ||
ElementEventsHandler.prototype.handle = function () { | ||
var elem = this.element; | ||
elem.addEventListener("keydown", this.keyPressHandler); | ||
}; | ||
return ElementEventsHandler; | ||
}()); | ||
export { ElementEventsHandler }; | ||
//# sourceMappingURL=ElementEventsHandler.js.map |
@@ -1,137 +0,125 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
import { OrderedList } from "../utils/OrderedList"; | ||
import { ElementEventsHandler } from "./ElementEventsHandler"; | ||
import { domProcessor } from "../dom/DomProcessor"; | ||
export var ELEMENT_INFO_TOKEN = "TOLEFOCUS_INFO"; | ||
var FocusGroup = (function () { | ||
function FocusGroup(parentGroup, groupElement, headBehavior, tailBehavior) { | ||
if (headBehavior === void 0) { headBehavior = ""; } | ||
if (tailBehavior === void 0) { tailBehavior = ""; } | ||
this.parentGroup = parentGroup; | ||
this.groupElement = groupElement; | ||
this.headBehavior = headBehavior; | ||
this.tailBehavior = tailBehavior; | ||
this.items = new OrderedList(); | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "../utils/OrderedList", "./ElementEventsHandler", "../dom/DomProcessor"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var OrderedList_1 = require("../utils/OrderedList"); | ||
var ElementEventsHandler_1 = require("./ElementEventsHandler"); | ||
var DomProcessor_1 = require("../dom/DomProcessor"); | ||
exports.ELEMENT_INFO_TOKEN = "TOLEFOCUS_INFO"; | ||
var FocusGroup = (function () { | ||
function FocusGroup(parentGroup, groupElement, headBehavior, tailBehavior) { | ||
if (headBehavior === void 0) { headBehavior = ""; } | ||
if (tailBehavior === void 0) { tailBehavior = ""; } | ||
this.parentGroup = parentGroup; | ||
this.groupElement = groupElement; | ||
this.headBehavior = headBehavior; | ||
this.tailBehavior = tailBehavior; | ||
this.items = new OrderedList_1.OrderedList(); | ||
Object.defineProperty(FocusGroup.prototype, "count", { | ||
get: function () { | ||
return this.items.orderedItems.length; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
FocusGroup.prototype.add = function (item, focusOrder) { | ||
var index; | ||
if (!(item instanceof FocusGroup)) { | ||
index = domProcessor.getDOMOrderInGroup(this.groupElement, item); | ||
item.setAttribute("tabindex", "-1"); | ||
if (!item[ELEMENT_INFO_TOKEN]) { | ||
item[ELEMENT_INFO_TOKEN] = { | ||
parentGroup: this, | ||
eventsHandler: new ElementEventsHandler(item) | ||
}; | ||
} | ||
} | ||
Object.defineProperty(FocusGroup.prototype, "count", { | ||
get: function () { | ||
return this.items.orderedItems.length; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
FocusGroup.prototype.add = function (item, focusOrder) { | ||
var index; | ||
if (!(item instanceof FocusGroup)) { | ||
index = DomProcessor_1.domProcessor.getDOMOrderInGroup(this.groupElement, item); | ||
item.setAttribute("tabindex", "-1"); | ||
if (!item[exports.ELEMENT_INFO_TOKEN]) { | ||
item[exports.ELEMENT_INFO_TOKEN] = { | ||
parentGroup: this, | ||
eventsHandler: new ElementEventsHandler_1.ElementEventsHandler(item) | ||
}; | ||
} | ||
else { | ||
index = domProcessor.getDOMOrderInGroup(this.groupElement, item.groupElement); | ||
if (!item.groupElement[ELEMENT_INFO_TOKEN]) { | ||
item.groupElement[ELEMENT_INFO_TOKEN] = { | ||
parentGroup: this, | ||
group: item | ||
}; | ||
} | ||
} | ||
this.items.insert(index, item, focusOrder); | ||
}; | ||
FocusGroup.prototype.remove = function (item) { | ||
if (!(item instanceof FocusGroup) && item[ELEMENT_INFO_TOKEN]) { | ||
item[ELEMENT_INFO_TOKEN].eventsHandler.unhandle(); | ||
} | ||
this.items.remove(item); | ||
}; | ||
FocusGroup.prototype.fistElementRecursively = function () { | ||
for (var _i = 0, _a = this.items.orderedItems; _i < _a.length; _i++) { | ||
var object = _a[_i].object; | ||
if (!(object instanceof FocusGroup)) { | ||
return object; | ||
} | ||
else { | ||
index = DomProcessor_1.domProcessor.getDOMOrderInGroup(this.groupElement, item.groupElement); | ||
if (!item.groupElement[exports.ELEMENT_INFO_TOKEN]) { | ||
item.groupElement[exports.ELEMENT_INFO_TOKEN] = { | ||
parentGroup: this, | ||
group: item | ||
}; | ||
var innerGroupFirst = object.fistElementRecursively(); | ||
if (innerGroupFirst) { | ||
return innerGroupFirst; | ||
} | ||
} | ||
this.items.insert(index, item, focusOrder); | ||
}; | ||
FocusGroup.prototype.remove = function (item) { | ||
if (!(item instanceof FocusGroup) && item[exports.ELEMENT_INFO_TOKEN]) { | ||
item[exports.ELEMENT_INFO_TOKEN].eventsHandler.unhandle(); | ||
} | ||
return undefined; | ||
}; | ||
FocusGroup.prototype.lastElementRecursively = function () { | ||
for (var i = this.items.orderedItems.length - 1; i >= 0; i--) { | ||
var object = this.items.orderedItems[i].object; | ||
if (!(object instanceof FocusGroup)) { | ||
return object; | ||
} | ||
this.items.remove(item); | ||
}; | ||
FocusGroup.prototype.fistElementRecursively = function () { | ||
for (var _i = 0, _a = this.items.orderedItems; _i < _a.length; _i++) { | ||
var object = _a[_i].object; | ||
if (!(object instanceof FocusGroup)) { | ||
return object; | ||
else { | ||
var innerGroupLast = object.lastElementRecursively(); | ||
if (innerGroupLast) { | ||
return innerGroupLast; | ||
} | ||
else { | ||
var innerGroupFirst = object.fistElementRecursively(); | ||
if (innerGroupFirst) { | ||
return innerGroupFirst; | ||
} | ||
} | ||
} | ||
return undefined; | ||
}; | ||
FocusGroup.prototype.locateElementRecursively = function (element) { | ||
var index = 0; | ||
for (var _i = 0, _a = this.items.orderedItems; _i < _a.length; _i++) { | ||
var object = _a[_i].object; | ||
if (!(object instanceof FocusGroup)) { | ||
if (object === element) { | ||
return { group: this, elementIndex: index }; | ||
} | ||
} | ||
return undefined; | ||
}; | ||
FocusGroup.prototype.lastElementRecursively = function () { | ||
for (var i = this.items.orderedItems.length - 1; i >= 0; i--) { | ||
var object = this.items.orderedItems[i].object; | ||
if (!(object instanceof FocusGroup)) { | ||
return object; | ||
else { | ||
var innerResult = object.locateElementRecursively(element); | ||
if (innerResult.group) { | ||
return innerResult; | ||
} | ||
else { | ||
var innerGroupLast = object.lastElementRecursively(); | ||
if (innerGroupLast) { | ||
return innerGroupLast; | ||
} | ||
} | ||
} | ||
return undefined; | ||
}; | ||
FocusGroup.prototype.locateElementRecursively = function (element) { | ||
var index = 0; | ||
for (var _i = 0, _a = this.items.orderedItems; _i < _a.length; _i++) { | ||
var object = _a[_i].object; | ||
if (!(object instanceof FocusGroup)) { | ||
if (object === element) { | ||
return { group: this, elementIndex: index }; | ||
} | ||
index++; | ||
} | ||
return { group: undefined, elementIndex: undefined }; | ||
}; | ||
FocusGroup.prototype.getItemIndexByElement = function (element) { | ||
return this.items.orderedItems.findIndex(function (item) { | ||
return (item.object instanceof FocusGroup && item.object.groupElement === element) | ||
|| (!(item.object instanceof FocusGroup) && item.object === element); | ||
}); | ||
}; | ||
FocusGroup.prototype.getNextElement = function (currentElement) { | ||
var nextItemIndex; | ||
var index = this.getItemIndexByElement(currentElement); | ||
if (index >= 0) { | ||
if (index < this.items.orderedItems.length - 1) { | ||
nextItemIndex = index + 1; | ||
} | ||
else { | ||
if (this.tailBehavior === "loop") { | ||
nextItemIndex = 0; | ||
} | ||
else { | ||
var innerResult = object.locateElementRecursively(element); | ||
if (innerResult.group) { | ||
return innerResult; | ||
} | ||
else if (this.tailBehavior === "stop") { | ||
nextItemIndex = index; | ||
} | ||
index++; | ||
} | ||
return { group: undefined, elementIndex: undefined }; | ||
}; | ||
FocusGroup.prototype.getItemIndexByElement = function (element) { | ||
return this.items.orderedItems.findIndex(function (item) { | ||
return (item.object instanceof FocusGroup && item.object.groupElement === element) | ||
|| (!(item.object instanceof FocusGroup) && item.object === element); | ||
}); | ||
}; | ||
FocusGroup.prototype.getNextElement = function (currentElement) { | ||
var nextItemIndex; | ||
var index = this.getItemIndexByElement(currentElement); | ||
if (index >= 0) { | ||
if (index < this.items.orderedItems.length - 1) { | ||
nextItemIndex = index + 1; | ||
} | ||
else { | ||
if (this.tailBehavior === "loop") { | ||
nextItemIndex = 0; | ||
} | ||
else if (this.tailBehavior === "stop") { | ||
nextItemIndex = index; | ||
} | ||
else { | ||
if (this.parentGroup) { | ||
var parentNext = this.parentGroup.getNextElement(this.groupElement); | ||
if (parentNext) { | ||
return parentNext; | ||
} | ||
if (this.parentGroup) { | ||
var parentNext = this.parentGroup.getNextElement(this.groupElement); | ||
if (parentNext) { | ||
return parentNext; | ||
} | ||
@@ -141,36 +129,36 @@ } | ||
} | ||
if (nextItemIndex === undefined) { | ||
return undefined; | ||
} | ||
if (nextItemIndex === undefined) { | ||
return undefined; | ||
} | ||
var nextItem = this.items.orderedItems[nextItemIndex]; | ||
if (nextItem.object instanceof FocusGroup) { | ||
if (nextItem.object.count === 0) { | ||
return this.getNextElement(nextItem.object.groupElement); | ||
} | ||
var nextItem = this.items.orderedItems[nextItemIndex]; | ||
if (nextItem.object instanceof FocusGroup) { | ||
if (nextItem.object.count === 0) { | ||
return this.getNextElement(nextItem.object.groupElement); | ||
} | ||
return nextItem.object.fistElementRecursively(); | ||
return nextItem.object.fistElementRecursively(); | ||
} | ||
else { | ||
return nextItem.object; | ||
} | ||
}; | ||
FocusGroup.prototype.getPriorElement = function (currentElement) { | ||
var priorItemIndex; | ||
var index = this.getItemIndexByElement(currentElement); | ||
if (index >= 0) { | ||
if (index > 0) { | ||
priorItemIndex = index - 1; | ||
} | ||
else { | ||
return nextItem.object; | ||
} | ||
}; | ||
FocusGroup.prototype.getPriorElement = function (currentElement) { | ||
var priorItemIndex; | ||
var index = this.getItemIndexByElement(currentElement); | ||
if (index >= 0) { | ||
if (index > 0) { | ||
priorItemIndex = index - 1; | ||
if (this.headBehavior === "loop") { | ||
priorItemIndex = this.items.orderedItems.length - 1; | ||
} | ||
else if (this.headBehavior === "stop") { | ||
priorItemIndex = index; | ||
} | ||
else { | ||
if (this.headBehavior === "loop") { | ||
priorItemIndex = this.items.orderedItems.length - 1; | ||
} | ||
else if (this.headBehavior === "stop") { | ||
priorItemIndex = index; | ||
} | ||
else { | ||
if (this.parentGroup) { | ||
var parentPrior = this.parentGroup.getPriorElement(this.groupElement); | ||
if (parentPrior) { | ||
return parentPrior; | ||
} | ||
if (this.parentGroup) { | ||
var parentPrior = this.parentGroup.getPriorElement(this.groupElement); | ||
if (parentPrior) { | ||
return parentPrior; | ||
} | ||
@@ -180,17 +168,17 @@ } | ||
} | ||
if (priorItemIndex === undefined) { | ||
return undefined; | ||
} | ||
var priorItem = this.items.orderedItems[priorItemIndex]; | ||
if (priorItem.object instanceof FocusGroup) { | ||
return priorItem.object.lastElementRecursively(); | ||
} | ||
else { | ||
return priorItem.object; | ||
} | ||
}; | ||
return FocusGroup; | ||
}()); | ||
exports.FocusGroup = FocusGroup; | ||
}); | ||
} | ||
if (priorItemIndex === undefined) { | ||
return undefined; | ||
} | ||
var priorItem = this.items.orderedItems[priorItemIndex]; | ||
if (priorItem.object instanceof FocusGroup) { | ||
return priorItem.object.lastElementRecursively(); | ||
} | ||
else { | ||
return priorItem.object; | ||
} | ||
}; | ||
return FocusGroup; | ||
}()); | ||
export { FocusGroup }; | ||
//# sourceMappingURL=FocusGroup.js.map |
@@ -1,106 +0,94 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
import { FocusGroup } from "./FocusGroup"; | ||
import { domProcessor } from "../dom/DomProcessor"; | ||
import { FocusabilityInspector } from "../dom/FocusabilityInspector"; | ||
import { setPolyfills } from "../utils/Polyfills"; | ||
export var focusGroupAttributeName = "focus-group"; | ||
export var focusOrderAttributeName = "focus-order"; | ||
export var autofocusAttributeName = "autofocus"; | ||
export var focusableTagNames = ["a", "select", "button", "input", "textarea"]; | ||
export var autofocusInspectAttributeValue = "observe"; | ||
var FocusManager = (function () { | ||
function FocusManager() { | ||
this._enabled = false; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "./FocusGroup", "../dom/DomProcessor", "../dom/FocusabilityInspector", "../utils/Polyfills"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var FocusGroup_1 = require("./FocusGroup"); | ||
var DomProcessor_1 = require("../dom/DomProcessor"); | ||
var FocusabilityInspector_1 = require("../dom/FocusabilityInspector"); | ||
var Polyfills_1 = require("../utils/Polyfills"); | ||
exports.focusGroupAttributeName = "focus-group"; | ||
exports.focusOrderAttributeName = "focus-order"; | ||
exports.autofocusAttributeName = "autofocus"; | ||
exports.focusableTagNames = ["a", "select", "button", "input", "textarea"]; | ||
exports.autofocusInspectAttributeValue = "observe"; | ||
var FocusManager = (function () { | ||
function FocusManager() { | ||
this._enabled = false; | ||
Object.defineProperty(FocusManager.prototype, "root", { | ||
get: function () { | ||
return this._root; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(FocusManager.prototype, "enabled", { | ||
get: function () { | ||
return this._enabled; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
FocusManager.prototype.addCustomSelector = function (selector) { | ||
domProcessor.addCustomSelector(selector); | ||
}; | ||
FocusManager.prototype.removeCustomSelector = function (selector) { | ||
domProcessor.removeCustomSelector(selector); | ||
}; | ||
FocusManager.prototype.setCanElementGetFocusHandler = function (handler) { | ||
domProcessor.setCanElementGetFocusHandler(handler); | ||
}; | ||
FocusManager.prototype.focusNext = function (currentElement) { | ||
if (!currentElement) { | ||
currentElement = document.activeElement; | ||
} | ||
Object.defineProperty(FocusManager.prototype, "root", { | ||
get: function () { | ||
return this._root; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(FocusManager.prototype, "enabled", { | ||
get: function () { | ||
return this._enabled; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
FocusManager.prototype.addCustomSelector = function (selector) { | ||
DomProcessor_1.domProcessor.addCustomSelector(selector); | ||
}; | ||
FocusManager.prototype.removeCustomSelector = function (selector) { | ||
DomProcessor_1.domProcessor.removeCustomSelector(selector); | ||
}; | ||
FocusManager.prototype.setCanElementGetFocusHandler = function (handler) { | ||
DomProcessor_1.domProcessor.setCanElementGetFocusHandler(handler); | ||
}; | ||
FocusManager.prototype.focusNext = function (currentElement) { | ||
if (!currentElement) { | ||
currentElement = document.activeElement; | ||
var group = this.root.locateElementRecursively(currentElement).group; | ||
if (group) { | ||
var element = group.getNextElement(currentElement); | ||
while (!domProcessor.canElementGetFocus(element)) { | ||
var info = domProcessor.getElementInfo(element); | ||
element = info.parentGroup.getNextElement(element); | ||
} | ||
var group = this.root.locateElementRecursively(currentElement).group; | ||
if (group) { | ||
var element = group.getNextElement(currentElement); | ||
while (!DomProcessor_1.domProcessor.canElementGetFocus(element)) { | ||
var info = DomProcessor_1.domProcessor.getElementInfo(element); | ||
element = info.parentGroup.getNextElement(element); | ||
} | ||
if (element) { | ||
element.focus(); | ||
} | ||
if (element) { | ||
element.focus(); | ||
} | ||
}; | ||
FocusManager.prototype.focusPrior = function (currentElement) { | ||
if (!currentElement) { | ||
currentElement = document.activeElement; | ||
} | ||
}; | ||
FocusManager.prototype.focusPrior = function (currentElement) { | ||
if (!currentElement) { | ||
currentElement = document.activeElement; | ||
} | ||
var group = this.root.locateElementRecursively(currentElement).group; | ||
if (group) { | ||
var element = group.getPriorElement(currentElement); | ||
while (!domProcessor.canElementGetFocus(element)) { | ||
var info = domProcessor.getElementInfo(element); | ||
element = info.parentGroup.getPriorElement(element); | ||
} | ||
var group = this.root.locateElementRecursively(currentElement).group; | ||
if (group) { | ||
var element = group.getPriorElement(currentElement); | ||
while (!DomProcessor_1.domProcessor.canElementGetFocus(element)) { | ||
var info = DomProcessor_1.domProcessor.getElementInfo(element); | ||
element = info.parentGroup.getPriorElement(element); | ||
} | ||
if (element) { | ||
element.focus(); | ||
} | ||
if (element) { | ||
element.focus(); | ||
} | ||
}; | ||
FocusManager.prototype.disable = function () { | ||
if (!this._enabled) { | ||
return; | ||
} | ||
this._enabled = false; | ||
FocusabilityInspector_1.FocusabilityInspector.stopAll(); | ||
}; | ||
FocusManager.prototype.enable = function (rootElement, headBehavior, tailBehavior) { | ||
if (headBehavior === void 0) { headBehavior = "loop"; } | ||
if (tailBehavior === void 0) { tailBehavior = "loop"; } | ||
Polyfills_1.setPolyfills(); | ||
if (this._enabled) { | ||
this.disable(); | ||
} | ||
if (!rootElement) { | ||
rootElement = document.body; | ||
} | ||
this._root = new FocusGroup_1.FocusGroup(null, rootElement, headBehavior, tailBehavior); | ||
this._enabled = true; | ||
DomProcessor_1.domProcessor.processFromElement(rootElement); | ||
}; | ||
return FocusManager; | ||
}()); | ||
exports.FocusManager = FocusManager; | ||
exports.focusManager = new FocusManager(); | ||
}); | ||
} | ||
}; | ||
FocusManager.prototype.disable = function () { | ||
if (!this._enabled) { | ||
return; | ||
} | ||
this._enabled = false; | ||
FocusabilityInspector.stopAll(); | ||
}; | ||
FocusManager.prototype.enable = function (rootElement, headBehavior, tailBehavior) { | ||
if (headBehavior === void 0) { headBehavior = "loop"; } | ||
if (tailBehavior === void 0) { tailBehavior = "loop"; } | ||
setPolyfills(); | ||
if (this._enabled) { | ||
this.disable(); | ||
} | ||
if (!rootElement) { | ||
rootElement = document.body; | ||
} | ||
this._root = new FocusGroup(null, rootElement, headBehavior, tailBehavior); | ||
this._enabled = true; | ||
domProcessor.processFromElement(rootElement); | ||
}; | ||
return FocusManager; | ||
}()); | ||
export { FocusManager }; | ||
export var focusManager = new FocusManager(); | ||
//# sourceMappingURL=FocusManager.js.map |
@@ -1,209 +0,197 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
import { ELEMENT_INFO_TOKEN, FocusGroup } from "../core/FocusGroup"; | ||
import { focusableTagNames, focusOrderAttributeName, autofocusAttributeName, focusGroupAttributeName, focusManager, autofocusInspectAttributeValue } from "../core/FocusManager"; | ||
import { FocusabilityInspector } from "./FocusabilityInspector"; | ||
export var INSPECT_TOKEN = "TOLEFOCUS_INSPECTOR"; | ||
var DomProcessor = (function () { | ||
function DomProcessor() { | ||
this._customSelectors = []; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "../core/FocusGroup", "../core/FocusManager", "./FocusabilityInspector"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var FocusGroup_1 = require("../core/FocusGroup"); | ||
var FocusManager_1 = require("../core/FocusManager"); | ||
var FocusabilityInspector_1 = require("./FocusabilityInspector"); | ||
exports.INSPECT_TOKEN = "TOLEFOCUS_INSPECTOR"; | ||
var DomProcessor = (function () { | ||
function DomProcessor() { | ||
this._customSelectors = []; | ||
DomProcessor.prototype.setCanElementGetFocusHandler = function (handler) { | ||
this._canElementGetFocusHandler = handler; | ||
}; | ||
DomProcessor.prototype.addCustomSelector = function (selector) { | ||
this._customSelectors.push(selector); | ||
}; | ||
DomProcessor.prototype.removeCustomSelector = function (selector) { | ||
var index = this._customSelectors.indexOf(selector); | ||
if (index) { | ||
this._customSelectors.splice(index, 1); | ||
} | ||
DomProcessor.prototype.setCanElementGetFocusHandler = function (handler) { | ||
this._canElementGetFocusHandler = handler; | ||
}; | ||
DomProcessor.prototype.addCustomSelector = function (selector) { | ||
this._customSelectors.push(selector); | ||
}; | ||
DomProcessor.prototype.removeCustomSelector = function (selector) { | ||
var index = this._customSelectors.indexOf(selector); | ||
if (index) { | ||
this._customSelectors.splice(index, 1); | ||
}; | ||
DomProcessor.prototype.getFocusElementsSelector = function () { | ||
return focusableTagNames.concat([ | ||
"[" + focusGroupAttributeName + "]", | ||
"[" + focusOrderAttributeName + "]" | ||
], this._customSelectors).join(","); | ||
}; | ||
DomProcessor.prototype.removeGroup = function (element) { | ||
var info = this.getElementInfo(element); | ||
if (info) { | ||
info.parentGroup.remove(info.group); | ||
} | ||
}; | ||
DomProcessor.prototype.removeElement = function (element) { | ||
var info = this.getElementInfo(element); | ||
if (info) { | ||
info.parentGroup.remove(element); | ||
} | ||
if (element[INSPECT_TOKEN]) { | ||
element[INSPECT_TOKEN].stop(); | ||
} | ||
}; | ||
DomProcessor.prototype.getElementInfo = function (element) { | ||
return element[ELEMENT_INFO_TOKEN]; | ||
}; | ||
DomProcessor.prototype.isGroup = function (element) { | ||
var focusGroupAttributeValue = element.getAttribute(focusGroupAttributeName); | ||
return focusGroupAttributeValue !== null && focusGroupAttributeValue !== undefined; | ||
}; | ||
DomProcessor.prototype.isElement = function (element) { | ||
var focusOrderAttributeValue = element.getAttribute(focusOrderAttributeName); | ||
return element.matches(this.getFocusElementsSelector()) || | ||
(focusOrderAttributeValue !== null && focusOrderAttributeValue !== undefined); | ||
}; | ||
DomProcessor.prototype.processRemovedElement = function (element) { | ||
if (!element.getAttribute) { | ||
return; | ||
} | ||
if (this.isGroup(element)) { | ||
this.removeGroup(element); | ||
} | ||
else if (this.isElement(element)) { | ||
this.removeElement(element); | ||
} | ||
}; | ||
DomProcessor.prototype.locateParentGroupElement = function (element) { | ||
var current = element; | ||
while ((current = current.parentElement) !== null) { | ||
if (this.isGroup(current)) { | ||
return current; | ||
} | ||
}; | ||
DomProcessor.prototype.getFocusElementsSelector = function () { | ||
return FocusManager_1.focusableTagNames.concat([ | ||
"[" + FocusManager_1.focusGroupAttributeName + "]", | ||
"[" + FocusManager_1.focusOrderAttributeName + "]" | ||
], this._customSelectors).join(","); | ||
}; | ||
DomProcessor.prototype.removeGroup = function (element) { | ||
var info = this.getElementInfo(element); | ||
if (info) { | ||
info.parentGroup.remove(info.group); | ||
} | ||
return current; | ||
}; | ||
DomProcessor.prototype.getElementOrder = function (element) { | ||
var focusOrderAttributeValue = element.getAttribute(focusOrderAttributeName); | ||
if (focusOrderAttributeValue !== null && | ||
focusOrderAttributeValue !== undefined && | ||
focusOrderAttributeValue !== "") { | ||
return parseInt(focusOrderAttributeValue, 10); | ||
} | ||
}; | ||
DomProcessor.prototype.isGroupChildren = function (group, element) { | ||
while (element.parentElement !== null) { | ||
if (this.isGroup(element.parentElement) || element.parentElement === document.body) { | ||
return element.parentElement === group; | ||
} | ||
}; | ||
DomProcessor.prototype.removeElement = function (element) { | ||
var info = this.getElementInfo(element); | ||
if (info) { | ||
info.parentGroup.remove(element); | ||
element = element.parentElement; | ||
} | ||
return false; | ||
}; | ||
DomProcessor.prototype.getDOMOrderInGroup = function (groupElement, element) { | ||
var elements = groupElement.querySelectorAll(this.getFocusElementsSelector()); | ||
var directChildren = []; | ||
for (var i = 0, j = elements.length; i < j; i++) { | ||
var current = elements.item(i); | ||
if (this.isGroupChildren(groupElement, current)) { | ||
directChildren.push(current); | ||
} | ||
if (element[exports.INSPECT_TOKEN]) { | ||
element[exports.INSPECT_TOKEN].stop(); | ||
} | ||
for (var i = 0, j = directChildren.length; i < j; i++) { | ||
if (directChildren[i] === element) { | ||
return i; | ||
} | ||
}; | ||
DomProcessor.prototype.getElementInfo = function (element) { | ||
return element[FocusGroup_1.ELEMENT_INFO_TOKEN]; | ||
}; | ||
DomProcessor.prototype.isGroup = function (element) { | ||
var focusGroupAttributeValue = element.getAttribute(FocusManager_1.focusGroupAttributeName); | ||
return focusGroupAttributeValue !== null && focusGroupAttributeValue !== undefined; | ||
}; | ||
DomProcessor.prototype.isElement = function (element) { | ||
var focusOrderAttributeValue = element.getAttribute(FocusManager_1.focusOrderAttributeName); | ||
return element.matches(this.getFocusElementsSelector()) || | ||
(focusOrderAttributeValue !== null && focusOrderAttributeValue !== undefined); | ||
}; | ||
DomProcessor.prototype.processRemovedElement = function (element) { | ||
if (!element.getAttribute) { | ||
return; | ||
} | ||
; | ||
}; | ||
DomProcessor.prototype.getGroupProperties = function (element) { | ||
var value = element.getAttribute(focusGroupAttributeName); | ||
if (value === "") { | ||
return { head: undefined, tail: undefined }; | ||
} | ||
var parts = value.split(" ").filter(function (part) { return part !== ""; }).filter(function (_value, index) { return index < 2; }); | ||
var tail, head; | ||
if (parts.length === 1) { | ||
tail = parts[0]; | ||
head = parts[0]; | ||
} | ||
else if (parts.length === 2) { | ||
head = parts[0]; | ||
tail = parts[1]; | ||
} | ||
return { head: head, tail: tail }; | ||
}; | ||
DomProcessor.prototype.addGroup = function (element) { | ||
var parentGroupElement = this.locateParentGroupElement(element); | ||
var parentGroup = parentGroupElement ? | ||
this.getElementInfo(parentGroupElement).group : | ||
focusManager.root; | ||
var _a = this.getGroupProperties(element), head = _a.head, tail = _a.tail; | ||
var group = new FocusGroup(parentGroup, element, head, tail); | ||
parentGroup.add(group, this.getElementOrder(element)); | ||
}; | ||
DomProcessor.prototype.canElementGetFocus = function (element) { | ||
if (this._canElementGetFocusHandler) { | ||
var result = this._canElementGetFocusHandler(element); | ||
if (result !== undefined) { | ||
return result; | ||
} | ||
if (this.isGroup(element)) { | ||
this.removeGroup(element); | ||
} | ||
var visible = element.offsetParent !== null; | ||
var disable = !!element["disabled"]; | ||
return visible && !disable; | ||
}; | ||
DomProcessor.prototype.addElement = function (element) { | ||
var parentGroupElement = this.locateParentGroupElement(element); | ||
var parentGroup = parentGroupElement ? | ||
this.getElementInfo(parentGroupElement).group : | ||
focusManager.root; | ||
parentGroup.add(element, this.getElementOrder(element)); | ||
var autofocusValue = element.getAttribute(autofocusAttributeName); | ||
if (autofocusValue !== null && autofocusValue !== undefined) { | ||
if (this.canElementGetFocus(element)) { | ||
element.focus(); | ||
} | ||
else if (this.isElement(element)) { | ||
this.removeElement(element); | ||
if (autofocusValue === autofocusInspectAttributeValue) { | ||
element[INSPECT_TOKEN] = new FocusabilityInspector(element, function (isFocusable) { | ||
if (isFocusable) { | ||
element.focus(); | ||
} | ||
}); | ||
} | ||
}; | ||
DomProcessor.prototype.locateParentGroupElement = function (element) { | ||
var current = element; | ||
while ((current = current.parentElement) !== null) { | ||
if (this.isGroup(current)) { | ||
return current; | ||
} | ||
} | ||
return current; | ||
}; | ||
DomProcessor.prototype.getElementOrder = function (element) { | ||
var focusOrderAttributeValue = element.getAttribute(FocusManager_1.focusOrderAttributeName); | ||
if (focusOrderAttributeValue !== null && | ||
focusOrderAttributeValue !== undefined && | ||
focusOrderAttributeValue !== "") { | ||
return parseInt(focusOrderAttributeValue, 10); | ||
} | ||
}; | ||
DomProcessor.prototype.isGroupChildren = function (group, element) { | ||
while (element.parentElement !== null) { | ||
if (this.isGroup(element.parentElement) || element.parentElement === document.body) { | ||
return element.parentElement === group; | ||
} | ||
element = element.parentElement; | ||
} | ||
return false; | ||
}; | ||
DomProcessor.prototype.getDOMOrderInGroup = function (groupElement, element) { | ||
var elements = groupElement.querySelectorAll(this.getFocusElementsSelector()); | ||
var directChildren = []; | ||
for (var i = 0, j = elements.length; i < j; i++) { | ||
var current = elements.item(i); | ||
if (this.isGroupChildren(groupElement, current)) { | ||
directChildren.push(current); | ||
} | ||
} | ||
for (var i = 0, j = directChildren.length; i < j; i++) { | ||
if (directChildren[i] === element) { | ||
return i; | ||
} | ||
} | ||
; | ||
}; | ||
DomProcessor.prototype.getGroupProperties = function (element) { | ||
var value = element.getAttribute(FocusManager_1.focusGroupAttributeName); | ||
if (value === "") { | ||
return { head: undefined, tail: undefined }; | ||
} | ||
var parts = value.split(" ").filter(function (part) { return part !== ""; }).filter(function (_value, index) { return index < 2; }); | ||
var tail, head; | ||
if (parts.length === 1) { | ||
tail = parts[0]; | ||
head = parts[0]; | ||
} | ||
else if (parts.length === 2) { | ||
head = parts[0]; | ||
tail = parts[1]; | ||
} | ||
return { head: head, tail: tail }; | ||
}; | ||
DomProcessor.prototype.addGroup = function (element) { | ||
var parentGroupElement = this.locateParentGroupElement(element); | ||
var parentGroup = parentGroupElement ? | ||
this.getElementInfo(parentGroupElement).group : | ||
FocusManager_1.focusManager.root; | ||
var _a = this.getGroupProperties(element), head = _a.head, tail = _a.tail; | ||
var group = new FocusGroup_1.FocusGroup(parentGroup, element, head, tail); | ||
parentGroup.add(group, this.getElementOrder(element)); | ||
}; | ||
DomProcessor.prototype.canElementGetFocus = function (element) { | ||
if (this._canElementGetFocusHandler) { | ||
var result = this._canElementGetFocusHandler(element); | ||
if (result !== undefined) { | ||
return result; | ||
} | ||
} | ||
var visible = element.offsetParent !== null; | ||
var disable = !!element["disabled"]; | ||
return visible && !disable; | ||
}; | ||
DomProcessor.prototype.addElement = function (element) { | ||
var parentGroupElement = this.locateParentGroupElement(element); | ||
var parentGroup = parentGroupElement ? | ||
this.getElementInfo(parentGroupElement).group : | ||
FocusManager_1.focusManager.root; | ||
parentGroup.add(element, this.getElementOrder(element)); | ||
var autofocusValue = element.getAttribute(FocusManager_1.autofocusAttributeName); | ||
if (autofocusValue !== null && autofocusValue !== undefined) { | ||
if (this.canElementGetFocus(element)) { | ||
element.focus(); | ||
} | ||
if (autofocusValue === FocusManager_1.autofocusInspectAttributeValue) { | ||
element[exports.INSPECT_TOKEN] = new FocusabilityInspector_1.FocusabilityInspector(element, function (isFocusable) { | ||
if (isFocusable) { | ||
element.focus(); | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
DomProcessor.prototype.processAddedElement = function (element) { | ||
if (!element.getAttribute) { | ||
return; | ||
} | ||
if (this.isGroup(element)) { | ||
this.addGroup(element); | ||
} | ||
else if (this.isElement(element)) { | ||
this.addElement(element); | ||
} | ||
}; | ||
DomProcessor.prototype.removeChildrenFromElement = function (rootElement) { | ||
if (!rootElement.getAttribute) { | ||
return; | ||
} | ||
var elements = rootElement.querySelectorAll(this.getFocusElementsSelector()); | ||
for (var i = 0, j = elements.length; i < j; i++) { | ||
this.processRemovedElement(elements.item(i)); | ||
} | ||
}; | ||
DomProcessor.prototype.processFromElement = function (rootElement) { | ||
if (!rootElement.getAttribute) { | ||
return; | ||
} | ||
var elements = rootElement.querySelectorAll(this.getFocusElementsSelector()); | ||
for (var i = 0, j = elements.length; i < j; i++) { | ||
this.processAddedElement(elements.item(i)); | ||
} | ||
}; | ||
return DomProcessor; | ||
}()); | ||
exports.DomProcessor = DomProcessor; | ||
exports.domProcessor = new DomProcessor(); | ||
}); | ||
} | ||
}; | ||
DomProcessor.prototype.processAddedElement = function (element) { | ||
if (!element.getAttribute) { | ||
return; | ||
} | ||
if (this.isGroup(element)) { | ||
this.addGroup(element); | ||
} | ||
else if (this.isElement(element)) { | ||
this.addElement(element); | ||
} | ||
}; | ||
DomProcessor.prototype.removeChildrenFromElement = function (rootElement) { | ||
if (!rootElement.getAttribute) { | ||
return; | ||
} | ||
var elements = rootElement.querySelectorAll(this.getFocusElementsSelector()); | ||
for (var i = 0, j = elements.length; i < j; i++) { | ||
this.processRemovedElement(elements.item(i)); | ||
} | ||
}; | ||
DomProcessor.prototype.processFromElement = function (rootElement) { | ||
if (!rootElement.getAttribute) { | ||
return; | ||
} | ||
var elements = rootElement.querySelectorAll(this.getFocusElementsSelector()); | ||
for (var i = 0, j = elements.length; i < j; i++) { | ||
this.processAddedElement(elements.item(i)); | ||
} | ||
}; | ||
return DomProcessor; | ||
}()); | ||
export { DomProcessor }; | ||
export var domProcessor = new DomProcessor(); | ||
//# sourceMappingURL=DomProcessor.js.map |
@@ -1,45 +0,33 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
import { domProcessor } from "./DomProcessor"; | ||
var frequency = 100; | ||
var FocusabilityInspector = (function () { | ||
function FocusabilityInspector(element, callback) { | ||
var _this = this; | ||
this.element = element; | ||
this.callback = callback; | ||
this.check = function () { | ||
var focusable = domProcessor.canElementGetFocus(_this.element); | ||
if (focusable !== _this.focusable) { | ||
_this.focusable = focusable; | ||
_this.callback(_this.focusable); | ||
} | ||
}; | ||
this.focusable = domProcessor.canElementGetFocus(element); | ||
this.intervalHandle = setInterval(this.check, frequency); | ||
FocusabilityInspector.inspectorsList.push(this); | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "./DomProcessor"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var DomProcessor_1 = require("./DomProcessor"); | ||
var frequency = 100; | ||
var FocusabilityInspector = (function () { | ||
function FocusabilityInspector(element, callback) { | ||
var _this = this; | ||
this.element = element; | ||
this.callback = callback; | ||
this.check = function () { | ||
var focusable = DomProcessor_1.domProcessor.canElementGetFocus(_this.element); | ||
if (focusable !== _this.focusable) { | ||
_this.focusable = focusable; | ||
_this.callback(_this.focusable); | ||
} | ||
}; | ||
this.focusable = DomProcessor_1.domProcessor.canElementGetFocus(element); | ||
this.intervalHandle = setInterval(this.check, frequency); | ||
FocusabilityInspector.inspectorsList.push(this); | ||
FocusabilityInspector.stopAll = function () { | ||
while (this.inspectorsList.length > 0) { | ||
this.inspectorsList[0].stop(); | ||
} | ||
FocusabilityInspector.stopAll = function () { | ||
while (this.inspectorsList.length > 0) { | ||
this.inspectorsList[0].stop(); | ||
} | ||
}; | ||
FocusabilityInspector.prototype.stop = function () { | ||
clearInterval(this.intervalHandle); | ||
var index = FocusabilityInspector.inspectorsList.indexOf(this); | ||
FocusabilityInspector.inspectorsList.splice(index, 1); | ||
}; | ||
return FocusabilityInspector; | ||
}()); | ||
FocusabilityInspector.inspectorsList = []; | ||
exports.FocusabilityInspector = FocusabilityInspector; | ||
}); | ||
}; | ||
FocusabilityInspector.prototype.stop = function () { | ||
clearInterval(this.intervalHandle); | ||
var index = FocusabilityInspector.inspectorsList.indexOf(this); | ||
FocusabilityInspector.inspectorsList.splice(index, 1); | ||
}; | ||
return FocusabilityInspector; | ||
}()); | ||
export { FocusabilityInspector }; | ||
FocusabilityInspector.inspectorsList = []; | ||
//# sourceMappingURL=FocusabilityInspector.js.map |
@@ -1,74 +0,62 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
import { domProcessor } from "./DomProcessor"; | ||
var FocusObserver = (function () { | ||
function FocusObserver() { | ||
var _this = this; | ||
this._enabled = false; | ||
this.observer = new MutationObserver(function (mutations) { return _this.observerCallback(mutations); }); | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "./DomProcessor"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var DomProcessor_1 = require("./DomProcessor"); | ||
var FocusObserver = (function () { | ||
function FocusObserver() { | ||
var _this = this; | ||
this._enabled = false; | ||
this.observer = new MutationObserver(function (mutations) { return _this.observerCallback(mutations); }); | ||
Object.defineProperty(FocusObserver.prototype, "enabled", { | ||
get: function () { | ||
return this._enabled; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(FocusObserver.prototype, "rootElement", { | ||
get: function () { | ||
return this._rootElement; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
FocusObserver.prototype.disable = function () { | ||
if (!this._enabled) { | ||
return; | ||
} | ||
Object.defineProperty(FocusObserver.prototype, "enabled", { | ||
get: function () { | ||
return this._enabled; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(FocusObserver.prototype, "rootElement", { | ||
get: function () { | ||
return this._rootElement; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
FocusObserver.prototype.disable = function () { | ||
if (!this._enabled) { | ||
return; | ||
} | ||
this.observer.disconnect(); | ||
this._enabled = false; | ||
this.observer.disconnect(); | ||
this._enabled = false; | ||
}; | ||
FocusObserver.prototype.enable = function (rootElement) { | ||
if (this._enabled) { | ||
this.disable(); | ||
} | ||
if (!rootElement) { | ||
rootElement = document.body; | ||
} | ||
var config = { | ||
childList: true, | ||
subtree: true | ||
}; | ||
FocusObserver.prototype.enable = function (rootElement) { | ||
if (this._enabled) { | ||
this.disable(); | ||
this.observer.observe(rootElement, config); | ||
}; | ||
FocusObserver.prototype.observerCallback = function (mutations) { | ||
var _this = this; | ||
mutations.forEach(function (mutation) { return _this.processMutation(mutation); }); | ||
}; | ||
FocusObserver.prototype.processMutation = function (mutation) { | ||
if (mutation.type === "childList") { | ||
for (var i = 0, j = mutation.addedNodes.length; i < j; i++) { | ||
domProcessor.processAddedElement(mutation.addedNodes.item(i)); | ||
domProcessor.processFromElement(mutation.addedNodes.item(i)); | ||
} | ||
if (!rootElement) { | ||
rootElement = document.body; | ||
for (var i = 0, j = mutation.removedNodes.length; i < j; i++) { | ||
domProcessor.processRemovedElement(mutation.removedNodes.item(i)); | ||
domProcessor.removeChildrenFromElement(mutation.removedNodes.item(i)); | ||
} | ||
var config = { | ||
childList: true, | ||
subtree: true | ||
}; | ||
this.observer.observe(rootElement, config); | ||
}; | ||
FocusObserver.prototype.observerCallback = function (mutations) { | ||
var _this = this; | ||
mutations.forEach(function (mutation) { return _this.processMutation(mutation); }); | ||
}; | ||
FocusObserver.prototype.processMutation = function (mutation) { | ||
if (mutation.type === "childList") { | ||
for (var i = 0, j = mutation.addedNodes.length; i < j; i++) { | ||
DomProcessor_1.domProcessor.processAddedElement(mutation.addedNodes.item(i)); | ||
DomProcessor_1.domProcessor.processFromElement(mutation.addedNodes.item(i)); | ||
} | ||
for (var i = 0, j = mutation.removedNodes.length; i < j; i++) { | ||
DomProcessor_1.domProcessor.processRemovedElement(mutation.removedNodes.item(i)); | ||
DomProcessor_1.domProcessor.removeChildrenFromElement(mutation.removedNodes.item(i)); | ||
} | ||
} | ||
}; | ||
return FocusObserver; | ||
}()); | ||
exports.FocusObserver = FocusObserver; | ||
exports.focusObserver = new FocusObserver(); | ||
}); | ||
} | ||
}; | ||
return FocusObserver; | ||
}()); | ||
export { FocusObserver }; | ||
export var focusObserver = new FocusObserver(); | ||
//# sourceMappingURL=FocusObserver.js.map |
@@ -1,17 +0,3 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "./core/FocusManager", "./dom/FocusObserver"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var FocusManager_1 = require("./core/FocusManager"); | ||
exports.focusManager = FocusManager_1.focusManager; | ||
var FocusObserver_1 = require("./dom/FocusObserver"); | ||
exports.focusObserver = FocusObserver_1.focusObserver; | ||
}); | ||
export { focusManager } from "./core/FocusManager"; | ||
export { focusObserver } from "./dom/FocusObserver"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,91 +0,79 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
function isDefined(variable) { | ||
return variable !== undefined; | ||
} | ||
var OrderedList = (function () { | ||
function OrderedList() { | ||
this.items = []; | ||
this.orderedItems = []; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function isDefined(variable) { | ||
return variable !== undefined; | ||
} | ||
var OrderedList = (function () { | ||
function OrderedList() { | ||
this.items = []; | ||
this.orderedItems = []; | ||
/*add(object: TItem, order?: number) { | ||
let existingIndex = this.items.findIndex((current) => current.object === object); | ||
if (existingIndex >= 0) { | ||
// If exists update order if it's passed. | ||
if (order >= 0) { | ||
this.items[existingIndex].order = order; | ||
this.reorder(); | ||
} | ||
} else { | ||
// If not exists add it | ||
this.items.push({ object, order }); | ||
this.reorder(); | ||
} | ||
/*add(object: TItem, order?: number) { | ||
let existingIndex = this.items.findIndex((current) => current.object === object); | ||
if (existingIndex >= 0) { | ||
// If exists update order if it's passed. | ||
if (order >= 0) { | ||
this.items[existingIndex].order = order; | ||
this.reorder(); | ||
} | ||
} else { | ||
// If not exists add it | ||
this.items.push({ object, order }); | ||
}*/ | ||
OrderedList.prototype.insert = function (index, object, order) { | ||
var existingIndex = this.items.findIndex(function (current) { return current.object === object; }); | ||
if (existingIndex >= 0) { | ||
// If exists in the same position update order if it's passed and return. | ||
if (existingIndex === index && order >= 0) { | ||
this.items[existingIndex].order = order; | ||
this.reorder(); | ||
return; | ||
} | ||
}*/ | ||
OrderedList.prototype.insert = function (index, object, order) { | ||
var existingIndex = this.items.findIndex(function (current) { return current.object === object; }); | ||
if (existingIndex >= 0) { | ||
// If exists in the same position update order if it's passed and return. | ||
if (existingIndex === index && order >= 0) { | ||
this.items[existingIndex].order = order; | ||
this.reorder(); | ||
return; | ||
} | ||
else { | ||
this.items.splice(existingIndex, 1); | ||
} | ||
} | ||
if (!index && index !== 0) { | ||
this.items.push({ object: object, order: order }); | ||
} | ||
else { | ||
this.items.splice(index, 0, { object: object, order: order }); | ||
this.items.splice(existingIndex, 1); | ||
} | ||
this.reorder(); | ||
}; | ||
OrderedList.prototype.reorder = function () { | ||
var _this = this; | ||
var result = []; | ||
var withNegativeOrder = this.items.filter(function (item) { return isDefined(item.order) && item.order < 0; }); | ||
var withOrderItems = this.items.filter(function (item) { return isDefined(item.order) && item.order >= 0; }); | ||
var withoutOrderItems = this.items.filter(function (item) { return !isDefined(item.order); }); | ||
withOrderItems.forEach(function (item) { | ||
result[item.order] = item; | ||
}); | ||
var i2 = 0; | ||
for (var i = 0, j = this.items.length; i < j; i++) { | ||
if (result[i] === undefined && i2 < withoutOrderItems.length) { | ||
result[i] = withoutOrderItems[i2++]; | ||
} | ||
} | ||
if (!index && index !== 0) { | ||
this.items.push({ object: object, order: order }); | ||
} | ||
else { | ||
this.items.splice(index, 0, { object: object, order: order }); | ||
} | ||
this.reorder(); | ||
}; | ||
OrderedList.prototype.reorder = function () { | ||
var _this = this; | ||
var result = []; | ||
var withNegativeOrder = this.items.filter(function (item) { return isDefined(item.order) && item.order < 0; }); | ||
var withOrderItems = this.items.filter(function (item) { return isDefined(item.order) && item.order >= 0; }); | ||
var withoutOrderItems = this.items.filter(function (item) { return !isDefined(item.order); }); | ||
withOrderItems.forEach(function (item) { | ||
result[item.order] = item; | ||
}); | ||
var i2 = 0; | ||
for (var i = 0, j = this.items.length; i < j; i++) { | ||
if (result[i] === undefined && i2 < withoutOrderItems.length) { | ||
result[i] = withoutOrderItems[i2++]; | ||
} | ||
result.splice.apply(result, [0, 0].concat(withNegativeOrder.sort(function (a, b) { | ||
return b.order - a.order; | ||
}))); | ||
this.orderedItems = []; | ||
result.forEach(function (item) { | ||
if (item !== undefined) { | ||
_this.orderedItems.push(item); | ||
} | ||
}); | ||
}; | ||
OrderedList.prototype.remove = function (object) { | ||
var index = this.items.findIndex(function (current) { return current.object === object; }); | ||
if (index >= 0) { | ||
this.items.splice(index, 1); | ||
} | ||
result.splice.apply(result, [0, 0].concat(withNegativeOrder.sort(function (a, b) { | ||
return b.order - a.order; | ||
}))); | ||
this.orderedItems = []; | ||
result.forEach(function (item) { | ||
if (item !== undefined) { | ||
_this.orderedItems.push(item); | ||
} | ||
this.reorder(); | ||
}; | ||
return OrderedList; | ||
}()); | ||
exports.OrderedList = OrderedList; | ||
}); | ||
}); | ||
}; | ||
OrderedList.prototype.remove = function (object) { | ||
var index = this.items.findIndex(function (current) { return current.object === object; }); | ||
if (index >= 0) { | ||
this.items.splice(index, 1); | ||
} | ||
this.reorder(); | ||
}; | ||
return OrderedList; | ||
}()); | ||
export { OrderedList }; | ||
//# sourceMappingURL=OrderedList.js.map |
@@ -1,33 +0,20 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
function matches_polyfills() { | ||
var prototype = Element.prototype; | ||
if (!Element.prototype.matches) { | ||
Element.prototype.matches = | ||
prototype.matchesSelector || | ||
prototype.mozMatchesSelector || | ||
prototype.msMatchesSelector || | ||
prototype.oMatchesSelector || | ||
prototype.webkitMatchesSelector || | ||
function (s) { | ||
var matches = (this.document || this.ownerDocument).querySelectorAll(s), i = matches.length; | ||
while (--i >= 0 && matches.item(i) !== this) { } | ||
return i > -1; | ||
}; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function matches_polyfills() { | ||
var prototype = Element.prototype; | ||
if (!Element.prototype.matches) { | ||
Element.prototype.matches = | ||
prototype.matchesSelector || | ||
prototype.mozMatchesSelector || | ||
prototype.msMatchesSelector || | ||
prototype.oMatchesSelector || | ||
prototype.webkitMatchesSelector || | ||
function (s) { | ||
var matches = (this.document || this.ownerDocument).querySelectorAll(s), i = matches.length; | ||
while (--i >= 0 && matches.item(i) !== this) { } | ||
return i > -1; | ||
}; | ||
} | ||
} | ||
function setPolyfills() { | ||
matches_polyfills(); | ||
} | ||
exports.setPolyfills = setPolyfills; | ||
}); | ||
} | ||
export function setPolyfills() { | ||
matches_polyfills(); | ||
} | ||
//# sourceMappingURL=Polyfills.js.map |
{ | ||
"name": "tolefocus", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Agnostic Framework Focus Manager", | ||
@@ -5,0 +5,0 @@ "scripts": { |
78726
1546