Refine read more feature
This commit is contained in:
parent
d36dba7d95
commit
ec1b0dee80
33
js/ds.js
33
js/ds.js
@ -379,17 +379,36 @@ DataSpace.attachReadMore = function (cssClass, maxWords = 100)
|
||||
const more = document.createElement('span');
|
||||
more.textContent = 'Read more';
|
||||
more.className = 'text-primary c-hand';
|
||||
more.onclick = function () {
|
||||
this.parentElement.textContent = text;
|
||||
}
|
||||
|
||||
contentElement.textContent = text.split(' ').splice(0, maxWords).reduce(
|
||||
(p, v) => `${p} ${v}`
|
||||
);
|
||||
contentElement.textContent = text.split(' ')
|
||||
.splice(0, maxWords)
|
||||
.reduce((p, v) => `${p} ${v}`);
|
||||
|
||||
contentElement.textContent += '... ';
|
||||
|
||||
contentElement.appendChild(more);
|
||||
// Store innerHTML for less...
|
||||
const nodes = [];
|
||||
for (const node of contentElement.childNodes) {
|
||||
nodes.push(node);
|
||||
}
|
||||
|
||||
// TODO change this element, don't create a new one
|
||||
more.onclick = function () {
|
||||
const less = document.createElement('span');
|
||||
less.textContent = 'Less';
|
||||
less.className = 'text-primary c-hand';
|
||||
|
||||
// Hacky...
|
||||
less.onclick = function () {
|
||||
contentElement.innerHTML = '';
|
||||
for (const node of nodes) {
|
||||
contentElement.appendChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
contentElement.textContent = text + ' ';
|
||||
contentElement.appendChild(less);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user