Don't hardcode max words for read more

This commit is contained in:
Nicolò P 2023-03-22 16:30:36 +01:00
parent 80189f09f8
commit d36dba7d95
2 changed files with 5 additions and 5 deletions

View File

@ -362,17 +362,18 @@ DataSpace.getImagesSrc = function (resource)
}
/**
* @param {string} cssClass
* @param {int} maxWords
*
* @returns {void}
*/
DataSpace.attachReadMore = function (cssClass)
DataSpace.attachReadMore = function (cssClass, maxWords = 100)
{
const elements = document.querySelectorAll(`.${cssClass}`);
for (const element of elements) {
let contentElement = element.nextElementSibling;
let text = contentElement.textContent;
const isLongText = text.split(' ').length > 100;
const isLongText = text.split(' ').length > maxWords;
if (isLongText) {
const more = document.createElement('span');
@ -382,7 +383,7 @@ DataSpace.attachReadMore = function (cssClass)
this.parentElement.textContent = text;
}
contentElement.textContent = text.split(' ').splice(0, 100).reduce(
contentElement.textContent = text.split(' ').splice(0, maxWords).reduce(
(p, v) => `${p} ${v}`
);
@ -392,7 +393,6 @@ DataSpace.attachReadMore = function (cssClass)
}
}
}
/**
* @todo The order of elements in the tiles array
* in arches-json is the same as that of

View File

@ -21,5 +21,5 @@ document.addEventListener('readystatechange', async () => {
// Create report HTML
DataSpace.renderReport(report, images);
DataSpace.attachReadMore('read-more');
DataSpace.attachReadMore('read-more', 80);
});