Headless CMS and Content Managment Hub
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.
 
 
 
 
 

58 lines
1.4 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { AfterViewInit, Directive, ElementRef, HostListener, OnInit, Renderer2 } from '@angular/core';
import { timer } from 'rxjs';
import { ResourceOwner } from '@app/framework/internal';
@Directive({
selector: '[sqxIgnoreScrollbar]'
})
export class IgnoreScrollbarDirective extends ResourceOwner implements OnInit, AfterViewInit {
private parent: any;
private scollbarWidth = 0;
constructor(
private readonly element: ElementRef,
private readonly renderer: Renderer2
) {
super();
}
@HostListener('resize)')
public onResize() {
this.reposition();
}
public ngOnInit() {
this.parent = this.renderer.parentNode(this.element.nativeElement);
this.own(timer(100, 100).subscribe(() => this.reposition));
}
public ngAfterViewInit() {
this.reposition();
}
private reposition() {
if (!this.parent) {
return;
}
const parentOuter = this.parent.offsetWidth;
const parentInner = this.parent.clientWidth;
const scrollbarWidth = parentOuter - parentInner;
if (scrollbarWidth !== this.scollbarWidth) {
this.scollbarWidth = scrollbarWidth;
this.renderer.setStyle(this.element.nativeElement, 'marginRight', `-${scrollbarWidth}px`);
}
}
}