mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
47063: truncation option with shave library
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
|
||||
import {
|
||||
AfterViewChecked,
|
||||
AfterViewInit, Component, ElementRef, Inject, Input,
|
||||
ChangeDetectorRef, Component, ElementRef, Inject, Input,
|
||||
OnInit
|
||||
} from '@angular/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { NativeWindowRef, NativeWindowService } from '../window.service';
|
||||
|
||||
@Component({
|
||||
@@ -13,20 +10,19 @@ import { NativeWindowRef, NativeWindowService } from '../window.service';
|
||||
})
|
||||
export class TruncatableComponent implements OnInit {
|
||||
|
||||
@Input() lines: Observable<number>;
|
||||
@Input() lines: number;
|
||||
@Input() innerHTML;
|
||||
@Input() height: Observable<number>;
|
||||
height;
|
||||
styles: any;
|
||||
public constructor(private elementRef:ElementRef, @Inject(NativeWindowService) private _window: NativeWindowRef) { }
|
||||
|
||||
public constructor(private elementRef: ElementRef, @Inject(NativeWindowService) private _window: NativeWindowRef, private changeDetectorRef: ChangeDetectorRef) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
const lineHeight = this._window.nativeWindow.getComputedStyle(this.elementRef.nativeElement).lineHeight.replace('px', '');
|
||||
this.styles = this._window.nativeWindow.getComputedStyle(this.elementRef.nativeElement);
|
||||
this.height = this.lines.map((lines) => (lines * lineHeight)).startWith(0);
|
||||
this.print(this.styles);
|
||||
}
|
||||
|
||||
print(styles) {
|
||||
console.log(styles);
|
||||
this.styles = this._window.nativeWindow.getComputedStyle(this.elementRef.nativeElement);
|
||||
setTimeout(() => {
|
||||
this.height = this.styles.lineHeight.replace('px', '') * this.lines;
|
||||
this.changeDetectorRef.detectChanges();
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user