[DSC-516] Author show more button fixed

This commit is contained in:
Sufiyan Shaikh
2022-05-25 17:02:11 +05:30
parent fc83facf1e
commit d54f959613
2 changed files with 12 additions and 14 deletions

View File

@@ -116,23 +116,21 @@ export class TruncatablePartComponent implements AfterContentChecked, OnInit, On
* Function to get data to be observed
*/
toObserve() {
this.observedContent = this.document.querySelectorAll('.content');
this.observedContent = this.document.querySelectorAll('.content:not(.notruncatable)');
this.observer = new (this._window.nativeWindow as any).ResizeObserver((entries) => {
for (let entry of entries) {
if (!entry.target.classList.contains('notruncatable')) {
if (entry.target.scrollHeight > entry.contentRect.height) {
if (entry.target.children.length > 0) {
if (entry.target.children[0].offsetHeight > entry.contentRect.height) {
entry.target.classList.add('truncated');
} else {
entry.target.classList.remove('truncated');
}
} else {
if (entry.target.scrollHeight > entry.contentRect.height) {
if (entry.target.children.length > 0) {
if (entry.target.children[entry.target.children.length - 1].offsetHeight > entry.contentRect.height) {
entry.target.classList.add('truncated');
} else {
entry.target.classList.remove('truncated');
}
} else {
entry.target.classList.remove('truncated');
entry.target.classList.add('truncated');
}
} else {
entry.target.classList.remove('truncated');
}
}
});

View File

@@ -1,4 +1,4 @@
import { AfterViewChecked, Component, ElementRef, Input, OnInit } from '@angular/core';
import { AfterContentChecked, Component, ElementRef, Input, OnInit } from '@angular/core';
import { TruncatableService } from './truncatable.service';
@Component({
@@ -11,7 +11,7 @@ import { TruncatableService } from './truncatable.service';
/**
* Component that represents a section with one or more truncatable parts that all listen to this state
*/
export class TruncatableComponent implements OnInit, AfterViewChecked {
export class TruncatableComponent implements OnInit, AfterContentChecked {
/**
* Is true when all truncatable parts in this truncatable should be expanded on loading
*/
@@ -59,7 +59,7 @@ export class TruncatableComponent implements OnInit, AfterViewChecked {
}
}
ngAfterViewChecked() {
ngAfterContentChecked() {
const truncatedElements = this.el.nativeElement.querySelectorAll('.truncated');
if (truncatedElements?.length > 1) {
for (let i = 0; i < (truncatedElements.length - 1); i++) {