UNPKG

ngx-dynamic-tabindex

Version:
93 lines (85 loc) 3.77 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) : typeof define === 'function' && define.amd ? define('ngx-dynamic-tabindex', ['exports', '@angular/core'], factory) : (global = global || self, factory(global['ngx-dynamic-tabindex'] = {}, global.ng.core)); }(this, (function (exports, core) { 'use strict'; var NgxDynamicTabindexDirective = /** @class */ (function () { function NgxDynamicTabindexDirective(hostEl) { this.hostEl = hostEl; this.attributeName = 'tabindex'; } NgxDynamicTabindexDirective.prototype.ngAfterViewInit = function () { var _this = this; this.applyIndexes(); this.mutationObserver = new MutationObserver(function () { return _this.applyIndexes(); }); this.mutationObserver.observe(this.hostEl.nativeElement, { childList: true, subtree: true, }); }; NgxDynamicTabindexDirective.prototype.ngOnDestroy = function () { this.mutationObserver.disconnect(); }; NgxDynamicTabindexDirective.prototype.applyIndexes = function () { var _this = this; var isTabAheadOffset = !!this.hostEl.nativeElement.querySelector('[tabIndexAheadOffset]'); var elements = this.hostEl.nativeElement.querySelectorAll("[" + this.attributeName + "]"); var globalOffset; var tabIndex; elements.forEach(function (el, index) { if (isTabAheadOffset) { var offsetValue = parseInt(el.getAttribute('tabIndexAheadOffset'), 10); if (offsetValue) { globalOffset = offsetValue; tabIndex = _this.getTabIndex(index + offsetValue + 1); } else if (globalOffset >= 1) { tabIndex = _this.getTabIndex(index); globalOffset--; } else { tabIndex = _this.getTabIndex(index + 1); } } else { tabIndex = _this.getTabIndex(index + 1); } el.setAttribute(_this.attributeName, tabIndex); }); }; NgxDynamicTabindexDirective.prototype.getTabIndex = function (index) { return index.toString(); }; return NgxDynamicTabindexDirective; }()); NgxDynamicTabindexDirective.decorators = [ { type: core.Directive, args: [{ selector: '[applyTabIndexes]' },] } ]; NgxDynamicTabindexDirective.ctorParameters = function () { return [ { type: core.ElementRef } ]; }; var NgxDynamicTabindexModule = /** @class */ (function () { function NgxDynamicTabindexModule() { } return NgxDynamicTabindexModule; }()); NgxDynamicTabindexModule.decorators = [ { type: core.NgModule, args: [{ declarations: [NgxDynamicTabindexDirective], imports: [], exports: [NgxDynamicTabindexDirective] },] } ]; /* * Public API Surface of ngx-dynamic-tabindex */ /** * Generated bundle index. Do not edit. */ exports.NgxDynamicTabindexDirective = NgxDynamicTabindexDirective; exports.NgxDynamicTabindexModule = NgxDynamicTabindexModule; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=ngx-dynamic-tabindex.umd.js.map