Untitled
unknown
plain_text
a year ago
1.4 kB
6
Indexable
<script>
$w.onReady(function () {
// Ensure the dataset is ready
$w("#dataset1").onReady(() => {
// Set up the repeater
$w("#repeater1").onItemReady(($item, itemData, index) => {
const fullText = itemData.bio; // Replace 'bio' with your dataset field key
if (fullText) {
// Truncate the text to 30 words
const truncatedText = fullText.split(' ').slice(0, 30).join(' ') + '...';
// Set the text element to show the truncated version initially
$item("#text35").text = truncatedText;
// Set button click event to toggle text
let isTruncated = true;
$item("#button4").label = "Read More"; // Initial button label
$item("#button4").onClick(() => {
if (isTruncated) {
$item("#text35").text = fullText; // Show full text
$item("#button4").label = "Read Less"; // Update button label
} else {
$item("#text35").text = truncatedText; // Show truncated text
$item("#button4").label = "Read More"; // Update button label
}
isTruncated = !isTruncated; // Toggle state
});
}
});
});
});
</script>
Editor is loading...
Leave a Comment