UNPKG

ng-focus-selector

Version:

For device like `candy`, `qwerty`, `tv apps`, `stb` etc where element selection happens with keypad (or) remote, selection of element across the application will become complex.

2 lines 2.94 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/router")):"function"==typeof define&&define.amd?define("ng-focus-selector",["exports","@angular/core","@angular/router"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["ng-focus-selector"]={},t.ng.core,t.ng.router)}(this,(function(t,e,r){"use strict";var o=function(){function t(t,e,r){this.el=t,this.router=e,this.route=r}return t.prototype.onArrowLeftRight=function(t){var e=t.keyCode||t.which,r=parseInt(t.target.getAttribute("row")),o=parseInt(t.target.getAttribute("column")),n=document.querySelector('[row="'+r+'"][column="'+o+'"]');if(n&&n.getAttribute("istabitem")){var u=document.querySelector('[tabfocus="true"]');if(u){for(var s=this.route.snapshot;!s.firstChild.paramMap.get("column");)s=s.firstChild;var i=s.firstChild,c=i.paramMap,a=(i.params,i.data,parseInt(c.get("column")));37===e?a-=1:39===e&&(a+=1);var l=document.querySelectorAll('[istabheader="true"]');if(l.length&&l[a])u.getAttribute("tabfocus")&&u.setAttribute("tabfocus",!1),l[a].setAttribute("tabfocus",!0),this.focusElement(l[a]),(f=l[a].getAttribute("taburl"))&&this.router.navigateByUrl(f);return}}37===e?o-=1:39===e&&(o+=1);var f,p=document.querySelector('[row="'+r+'"][column="'+o+'"]');p&&(n.getAttribute("tabfocus")&&n.setAttribute("tabfocus",!1),p.setAttribute("tabfocus",!0),this.focusElement(p),(f=p.getAttribute("taburl"))&&this.router.navigateByUrl(f))},t.prototype.onArrowDownUp=function(t){var e=t.keyCode||t.which,r=t.target.getAttribute("isgrid"),o=parseInt(t.target.getAttribute("row")),n=parseInt(t.target.getAttribute("column"));n=r?n:0,40===e?o+=1:38===e&&(o-=1);var u=document.querySelector('[row="'+o+'"][tabfocus="true"]');if(!u||r){var s=document.querySelector('[row="'+o+'"][column="'+n+'"]');s&&this.focusElement(s)}else this.focusElement(u)},t.prototype.ngOnInit=function(){},t.prototype.focusElement=function(t){t.focus(),t.scrollIntoView({block:"end",inline:"end"})},t.prototype.setActiveIndex=function(t){var e=this.el.nativeElement.getElementsByClassName("focus-selector");e[t]&&this.focusElement(e[t])},t}();o.decorators=[{type:e.Component,args:[{selector:"ng-focus-selector",template:"<ng-content></ng-content>"}]}],o.ctorParameters=function(){return[{type:e.ElementRef},{type:r.Router},{type:r.ActivatedRoute}]},o.propDecorators={onArrowLeftRight:[{type:e.HostListener,args:["document:keydown.ArrowLeft",["$event"]]},{type:e.HostListener,args:["document:keydown.ArrowRight",["$event"]]}],onArrowDownUp:[{type:e.HostListener,args:["document:keydown.ArrowDown",["$event"]]},{type:e.HostListener,args:["document:keydown.ArrowUp",["$event"]]}]};var n=function(){};n.decorators=[{type:e.NgModule,args:[{declarations:[o],imports:[],exports:[o]}]}],t.FocusSelectorComponent=o,t.NgFocusSelectorModule=n,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=ng-focus-selector.umd.min.js.map