Expand Text

// For full API documentation, including code examples, visit http://wix.to/94BuAAs

 

let fullText; // variable to hold the full text

let shortText; // variable to hold the short version of the text

 

$w.onReady(function () {

// how many characters to include in the shortened version

const shortTextLength = 40;

// read the full text and store it in the fullText variable

fullText = $w("#textElement").text;

// grab the number of characters defined in shortTextLength and store them in the shortText variable

shortText = fullText.substr(0, shortTextLength) + "...";

// set the contents of the text element to be the short text

$w("#textElement").text = shortText;

});

 

export function btnToggle_click(event) {

// check the contents of the text element

if ($w("#textElement").text === shortText) {

// if currently displaying short text, display the full text

$w("#textElement").text = fullText;

$w("#btnToggle").label = "Show less";

} else {

// if currently displaying full text, display the short text

$w("#textElement").text = shortText;

$w("#btnToggle").label = "Show more";

}

}