aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main/angular/auto-colspan.directive.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-05-26 10:27:02 +0200
committerChocobozzz <me@florianbigard.com>2023-05-26 10:27:02 +0200
commit4b70c278a960a8d43407f0039aa03d0b08b44f9c (patch)
treed82990de9c1075dc5357f5f2f03162381f1e2c87 /client/src/app/shared/shared-main/angular/auto-colspan.directive.ts
parenta4c49a17ea8b90c1522a9d0868de7186c7432592 (diff)
downloadPeerTube-4b70c278a960a8d43407f0039aa03d0b08b44f9c.tar.gz
PeerTube-4b70c278a960a8d43407f0039aa03d0b08b44f9c.tar.zst
PeerTube-4b70c278a960a8d43407f0039aa03d0b08b44f9c.zip
Automatic colspan for tables
Diffstat (limited to 'client/src/app/shared/shared-main/angular/auto-colspan.directive.ts')
-rw-r--r--client/src/app/shared/shared-main/angular/auto-colspan.directive.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-main/angular/auto-colspan.directive.ts b/client/src/app/shared/shared-main/angular/auto-colspan.directive.ts
new file mode 100644
index 000000000..8da89b668
--- /dev/null
+++ b/client/src/app/shared/shared-main/angular/auto-colspan.directive.ts
@@ -0,0 +1,22 @@
1import { AfterViewInit, Directive, ElementRef, Renderer2 } from '@angular/core'
2
3@Directive({
4 selector: '[myAutoColspan]'
5})
6export class AutoColspanDirective implements AfterViewInit {
7
8 constructor (
9 private host: ElementRef,
10 private renderer: Renderer2
11 ) { }
12
13 ngAfterViewInit () {
14 const el = this.host.nativeElement as HTMLElement
15 const table = el.closest('table')
16 if (!table) throw new Error('table element not found')
17
18 const th = table.querySelectorAll('th')
19
20 this.renderer.setAttribute(el, 'colspan', th.length + '')
21 }
22}