mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
44 lines
1.0 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { AfterViewInit, Directive, ElementRef, Input, OnInit, Renderer2 } from '@angular/core';
|
|
import { timer } from 'rxjs';
|
|
|
|
import { ResourceOwner } from '@app/framework/internal';
|
|
|
|
@Directive({
|
|
selector: '[sqxSyncWidth]'
|
|
})
|
|
export class SyncWidthDirective extends ResourceOwner implements OnInit, AfterViewInit {
|
|
@Input('sqxSyncWidth')
|
|
public target: HTMLElement;
|
|
|
|
constructor(
|
|
private readonly element: ElementRef<HTMLElement>,
|
|
private readonly renderer: Renderer2
|
|
) {
|
|
super();
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.own(timer(100, 100).subscribe(() => this.reposition()));
|
|
}
|
|
|
|
public ngAfterViewInit() {
|
|
this.reposition();
|
|
}
|
|
|
|
private reposition() {
|
|
if (!this.target) {
|
|
return;
|
|
}
|
|
|
|
const size = this.element.nativeElement.clientWidth;
|
|
|
|
this.renderer.setStyle(this.target, 'width', `${size}px`);
|
|
}
|
|
}
|