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.
59 lines
1.3 KiB
59 lines
1.3 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Sebastian Stehle. All rights reserved
|
|
*/
|
|
|
|
import { Directive, ElementRef, HostListener, OnDestroy, OnInit } from '@angular/core';
|
|
import { Subscription } from 'rxjs';
|
|
|
|
import { PanelService } from './../services/panel.service';
|
|
|
|
@Directive({
|
|
selector: '.panel-container'
|
|
})
|
|
export class PanelContainerDirective implements OnInit, OnDestroy {
|
|
private subscription: Subscription;
|
|
private panelsSize: number | null = null;
|
|
|
|
constructor(
|
|
private readonly element: ElementRef,
|
|
private readonly panels: PanelService
|
|
) {
|
|
}
|
|
|
|
@HostListener('window:resize')
|
|
public onResize() {
|
|
this.resize();
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.subscription =
|
|
this.panels.changed.subscribe(width => {
|
|
this.panelsSize = width;
|
|
|
|
this.resize();
|
|
});
|
|
}
|
|
|
|
public ngOnDestroy() {
|
|
this.subscription.unsubscribe();
|
|
}
|
|
|
|
private resize() {
|
|
if (!this.panelsSize) {
|
|
return;
|
|
}
|
|
|
|
const currentWidth = this.element.nativeElement.getBoundingClientRect().width;
|
|
|
|
const diff = this.panelsSize - currentWidth;
|
|
|
|
if (diff > 0) {
|
|
this.element.nativeElement.scrollLeft = diff;
|
|
} else {
|
|
this.element.nativeElement.scrollLeft = 0;
|
|
}
|
|
}
|
|
}
|