[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,13 +116,12 @@ export class TruncatablePartComponent implements AfterContentChecked, OnInit, On
* Function to get data to be observed * Function to get data to be observed
*/ */
toObserve() { 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) => { this.observer = new (this._window.nativeWindow as any).ResizeObserver((entries) => {
for (let entry of entries) { for (let entry of entries) {
if (!entry.target.classList.contains('notruncatable')) {
if (entry.target.scrollHeight > entry.contentRect.height) { if (entry.target.scrollHeight > entry.contentRect.height) {
if (entry.target.children.length > 0) { if (entry.target.children.length > 0) {
if (entry.target.children[0].offsetHeight > entry.contentRect.height) { if (entry.target.children[entry.target.children.length - 1].offsetHeight > entry.contentRect.height) {
entry.target.classList.add('truncated'); entry.target.classList.add('truncated');
} else { } else {
entry.target.classList.remove('truncated'); entry.target.classList.remove('truncated');
@@ -134,7 +133,6 @@ export class TruncatablePartComponent implements AfterContentChecked, OnInit, On
entry.target.classList.remove('truncated'); entry.target.classList.remove('truncated');
} }
} }
}
}); });
this.observedContent.forEach(p => { this.observedContent.forEach(p => {
this.observer.observe(p); this.observer.observe(p);

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'; import { TruncatableService } from './truncatable.service';
@Component({ @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 * 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 * 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'); const truncatedElements = this.el.nativeElement.querySelectorAll('.truncated');
if (truncatedElements?.length > 1) { if (truncatedElements?.length > 1) {
for (let i = 0; i < (truncatedElements.length - 1); i++) { for (let i = 0; i < (truncatedElements.length - 1); i++) {