Don't hardcode max words for read more
This commit is contained in:
parent
80189f09f8
commit
d36dba7d95
8
js/ds.js
8
js/ds.js
@ -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
|
||||
|
@ -21,5 +21,5 @@ document.addEventListener('readystatechange', async () => {
|
||||
// Create report HTML
|
||||
DataSpace.renderReport(report, images);
|
||||
|
||||
DataSpace.attachReadMore('read-more');
|
||||
DataSpace.attachReadMore('read-more', 80);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user