Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View More in languages and also profession acheivements #240

Merged
merged 1 commit into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions blocks/agent-about/agent-about.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { a, div } from '../../scripts/dom-helpers.js';
import {
a, div, ul, li,
} from '../../scripts/dom-helpers.js';

const viewMoreOnClick = (anchor, block) => {
const viewMoreOnClick = (name, anchor, block) => {
anchor.addEventListener('click', () => {
if (anchor.classList.contains('view-more')) {
anchor.classList.remove('view-more');
anchor.classList.add('view-less');
block.querySelector('.about-text').classList.remove('hide');
block.querySelector('.about-text-truncate').classList.add('hide');
block.querySelector(`.${name}`).classList.remove('hide');
block.querySelector(`.${name}-truncate`).classList.add('hide');
} else {
anchor.classList.remove('view-less');
anchor.classList.add('view-more');
block.querySelector('.about-text').classList.add('hide');
block.querySelector('.about-text-truncate').classList.remove('hide');
block.querySelector(`.${name}`).classList.add('hide');
block.querySelector(`.${name}-truncate`).classList.remove('hide');
}
});
};
Expand All @@ -22,12 +24,37 @@ export default function decorate(block) {
children.forEach((child, index) => {
child.classList.add(`cols-${index + 1}`);
if (index === 0) {
child.children[1].classList.add('about-text', 'hide');
child.append(div({ class: 'about-text-truncate' },
`${child.children[1].textContent.substring(0, 245)}...`));
const anchor = a({ class: 'view-more' });
child.append(anchor);
viewMoreOnClick(anchor, block);
const name = 'about-text';
const threshold = 245;
child.children[1].classList.add(name);
if (child.children[1].textContent > threshold) {
child.children[1].classList.add('hide');
child.append(div({ class: `${name}-truncate` },
`${child.children[1].textContent.substring(0, threshold)}...`));
const anchor = a({ class: 'view-more' });
child.append(anchor);
viewMoreOnClick(name, anchor, block);
}
} else {
const threshold = 3;
const name = child.children[0].textContent.toLowerCase().replace(/\s/g, '-');
const liItems = child.children[1].querySelectorAll('li');
child.children[1].classList.add(name);

if (liItems.length > threshold) {
child.children[1].classList.add('hide');
const tempUl = ul({ });
Array.from(child.children[1].querySelectorAll('li'))
.slice(0, threshold).forEach((liItem) => {
const tempLi = li({}, liItem.textContent);
tempUl.append(tempLi);
});

child.append(div({ class: `${name}-truncate` }, tempUl));
const anchor = a({ class: 'view-more' });
child.append(anchor);
viewMoreOnClick(name, anchor, block);
}
}
});
}
Expand Down
Loading