/* * angular-focusmanager * Version: 0.3.12 * Obogo (c) 2018 * https://github.com/obogo/angular-focusmanager * License: MIT. */ !function(a,b){var c={FOCUS_ELEMENT_ID:"fm-id",FOCUS_GROUP_ID:"fm-group",FOCUS_PARENT_ID:"fm-parent",FOCUS_PARENT_GROUP_ID:"fm-parent-group",TAB_INDEX:"tabindex",FOCUS_GROUP:"focus-group",FOCUS_GROUP_INDEX:"focus-group-index",FOCUS_GROUP_HEAD:"focus-group-head",FOCUS_GROUP_TAIL:"focus-group-tail",FOCUS_ELEMENT:"focus-element",FOCUS_ENABLED:"focus-enabled",FOCUS_INDEX:"focus-index",SELECTABLE:"A,SELECT,BUTTON,INPUT,TEXTAREA,*[focus-index]",GROUP_ELEMENTS_STRICT:'[{focusParentId}="{groupId}"][focus-index]:not([disabled]):not(.focus-ignore):not(.disabled)',GROUP_ELEMENTS:'[{focusParentId}="{groupId}"]:not([disabled]):not(.focus-ignore):not(.disabled)'};a.consts=c;var d;!function(){try{d=angular.module("fm")}catch(a){d=angular.module("fm",[])}}(),d.directive("focusAutofocus",["focusManager","focusQuery",function(a,b){function c(){e=null,h=0,clearInterval(f)}function d(b){a.focus(b),b.focus()}var e,f,g=[],h=0;return{scope:!0,link:function(a,i,j){var k=i[0],l=j.focusAutofocus?parseInt(j.focusAutofocus,10):0;g[l]=k,h+=1,e||(e=a.$watch(function(){e();var a=0,h=1e3;f=setInterval(function(){if(a'}}]),d.directive("focusRepeat",function(){return{scope:!0,link:function(a){a.$last&&a.$emit("focus::repeat")}}}),d.directive("ngRepeat",function(){return{scope:!0,link:function(a){a.$last&&a.$emit("focus::repeat")}}}),d.directive("focusShortcut",["focusManager",function(a){return{link:function(b,c,d){function e(){g||(g=!0,d.hasOwnProperty("focusShortcut")&&Mousetrap.bind(d.focusShortcut.split(","),function(b){return b.preventDefault(),b.stopPropagation(),a.focus(c[0]),!1}))}function f(){g&&(g=!1,d.hasOwnProperty("focusShortcut")&&Mousetrap.unbind(d.focusShortcut.split(",")))}var g=!1;d.focusShortcut&&(b.$on("bindKeys",e),b.$on("unbindKeys",f),b.$on("$destroy",f))}}}]),d.directive("focusStack",["focusManager","focusQuery",function(a,b){var c=[];return{link:function(d,e,f){c.push(b.getElementId(a.activeElement)),d.$on("$destroy",function(){if(c.length){var d=c.pop(),e=b.getElement(d);e&&setTimeout(function(){a.focus(e)})}})}}}]),d.factory("focusDispatcher",function(){function a(){this.events={}}function b(b){return b=b||"fm",c[b]||(c[b]=new a),c[b]}var c={};return a.prototype.events={},a.prototype.on=function(a,b){this.events.hasOwnProperty(a)||(this.events[a]=[]),this.events[a].push(b)},a.prototype.off=function(a,b){if(this.events.hasOwnProperty(a))for(var c in this.events[a])this.events[a][c]===b&&this.events[a].splice(c,1)},a.prototype.trigger=function(a,b){if(this.events.hasOwnProperty(a)){b=b||{},b.currentTarget=this;var c=this.events[a];for(var d in c)c.hasOwnProperty(d)&&c[d](b)}},b}),d.service("focusKeyboard",["focusManager",function(b){function c(){u||(u=!0)}function d(){u&&(u=!1)}function f(){v||(v=!0)}function g(){v&&(v=!1)}function h(){u?(d(),f()):(c(),g())}function i(a){var b=a.target;["email","number","password","search","text","textarea"].indexOf(b.type)>-1||"true"===b.getAttribute("contentEditable")||(a.preventDefault(),a.stopPropagation(),l(b,"mousedown"),l(b,"mouseup"),l(b,"click"))}function j(a){if(t.direction="next",b.enabled&&b.next(),b.enabled)return a.preventDefault(),a.stopPropagation(),!1}function k(a){if(t.direction="prev",b.enabled&&b.prev(),b.enabled)return a.preventDefault(),a.stopPropagation(),!1}function l(a,b){var c,d;if(a.ownerDocument?c=a.ownerDocument:9===a.nodeType&&(c=a),a.dispatchEvent){var e="";switch(b){case"click":case"mousedown":case"mouseup":e="MouseEvents"}d=c.createEvent(e);var f="change"!==b;d.initEvent(b,f,!0),d.synthetic=!0,a.dispatchEvent(d,!0)}else a.fireEvent&&(d=c.createEventObject(),d.synthetic=!0,a.fireEvent("on"+b,d))}function m(){e.addEvent(document,"keydown",o)}function n(){e.removeEvent(document,"keydown",o)}function o(a){u&&9===a.keyCode&&(a.shiftKey?k(a):j(a)),v&&(a.shiftKey||a.altKey||a.ctrlKey||(37===a.keyCode?k(a):38===a.keyCode?k(a):39===a.keyCode?j(a):40===a.keyCode&&j(a))),a.shiftKey||a.altKey||a.ctrlKey||13===a.keyCode&&i(a)}function p(a){r(),u&&(b.enabled||(b.enable(),a.shiftKey?b.findPrevChildGroup(s):b.findNextElement(s)))}function q(a){u&&(s=a,e.addEvent(document,"keyup",p))}function r(){e.removeEvent(document,"keyup",p)}var s,t=this,u=!1,v=!1;t.direction=null,t.enable=m,t.disable=n,t.enableTabKeys=c,t.disableTabKeys=d,t.enableArrowKeys=f,t.disableArrowKeys=g,t.toggleTabArrowKeys=h,t.triggerClick=i,t.watchNextTabKey=q,t.unwatchNextTabKey=r,a.keyboard=t}]).run(["focusKeyboard",function(a){a.enable(),a.enableTabKeys()}]),d.service("focusManager",["focusQuery","focusDispatcher",function(b,c){function d(a){if("undefined"==typeof a)return z.activeElement;if(z.activeElement!==a){var b={oldTarget:z.activeElement,newTarget:a};A.trigger("focusout",b),z.activeElement=a,a&&a.focus(),A.trigger("focusin",b)}}function e(){return b.getElement(b.getElementId(z.activeElement))}function f(a){return b.canReceiveFocus(a)}function g(){var a,c,d=e();d?(a=b.getParentId(d),c=b.getElementId(d),q(a,c)):q()}function h(){var a,c,d=e();d?(a=b.getParentId(d),c=b.getElementId(d),t(a,c)):t()}function i(a,b){for(var c=0,d=a.length;c0)return a[e-1]}}function k(a,c){var d,e;if(a&&a.length){if(!c)return a[0];if(d=b.getGroup(c),e=i(a,d),e>0)return a[e-1]}}function l(a,c){var d,e;if(a&&a.length){if(!c)return a[0];if(d=b.getElement(c),e=i(a,d),e!==-1&&e+1-1),b&&(b=!a.hasAttribute("disabled")),b&&(b=k(a)),b&&(b=!a.hasAttribute(c.FOCUS_GROUP)),b}function d(){var a=e.supplant("[{focusGroup}]:not([{focusParentGroupId}])",{focusGroup:c.FOCUS_GROUP,focusParentGroupId:c.FOCUS_PARENT_GROUP_ID}),b=document.querySelector(a);return w(b)}function f(){var a=e.supplant("[{focusGroup}]:not([{focusParentGroupId}])",{focusGroup:c.FOCUS_GROUP,focusParentGroupId:c.FOCUS_PARENT_GROUP_ID}),b=document.querySelectorAll(a);return w(b[b.length-1])}function g(a){for(var b=e.supplant('[{focusParentGroupId}="{groupId}"]',{focusParentGroupId:c.FOCUS_PARENT_GROUP_ID,groupId:a}),d=document.querySelectorAll(b),f=[],g=0,h=d.length;gb?1:a0&&(g=a[e+1],a[e+1]=a[e],a[e]=g);return a}function G(a,b){var d=parseInt(a.getAttribute(c.FOCUS_INDEX),10)||Number.POSITIVE_INFINITY,e=parseInt(b.getAttribute(c.FOCUS_INDEX),10)||Number.POSITIVE_INFINITY;return de?1:0}function H(a,b){var d=parseInt(a.getAttribute(c.FOCUS_GROUP_INDEX),10)||Number.POSITIVE_INFINITY,e=parseInt(b.getAttribute(c.FOCUS_GROUP_INDEX),10)||Number.POSITIVE_INFINITY;return de?1:0}function I(a){for(var b=u(a)||C(a);null===b||void 0===b;){if(a=a.parentNode,9===a.nodeType)return;b=u(a)||C(a)}return a}var J=this;J.getElement=r,J.getElementId=u,J.setElementId=v,J.getGroupId=w,J.setGroupId=x,J.getParentId=y,J.setParentId=z,J.getParentGroupId=A,J.setParentGroupId=B,J.getGroup=s,J.getFirstGroupId=d,J.getLastGroupId=f,J.getTabIndex=C,J.setTabIndex=D,J.getElementsWithoutParents=h,J.getGroupsWithoutParentGroup=i,J.isAutofocus=l,J.isVisible=k,J.hasGroupHead=n,J.hasGroupTail=p,J.getGroupHead=o,J.getGroupTail=q,J.isEnabled=m,J.getGroupElements=j,J.getChildGroups=g,J.contains=E,J.canReceiveFocus=b,J.findFocusEl=I,a.query=J});var e={};e.addEvent=function(a,b,c){angular.element(a).on(b,c)},e.removeEvent=function(a,b,c){angular.element(a).off(b,c)},e.debounce=function(a,b,c){var d;return function(){var e=this,f=arguments;clearTimeout(d),d=setTimeout(function(){d=null,c||a.apply(e,f)},b),c&&!d&&a.apply(e,f)}},e.throttle=function(a,b,c){b=b||250;var d,e;return function(){var f=c||this,g=+new Date,h=arguments;d&&gg||q.hasOwnProperty(g)&&(o[q[g]]=g)}e=o[c]?"keydown":"keypress"}return"keypress"==e&&f.length&&(e="keydown"),{key:d,modifiers:f,action:e}}function n(a,b,c,d,e){v[a+":"+c]=b,a=a.replace(/\s+/g," ");var f=a.split(" ");1":".","?":"/","|":"\\"},t={option:"alt",command:"meta","return":"enter",escape:"esc",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},u={},v={},w={},x=!1,y=!1,z=!1;for(c=1;20>c;++c)q[111+c]="f"+c;for(c=0;9>=c;++c)q[c+96]=c;d(b,"keypress",j),d(b,"keydown",j),d(b,"keyup",j);var A={bind:function(a,b,c){a=a instanceof Array?a:[a];for(var d=0;d