PP.Ui.cropText(text: String, width: Number, terminator: String, isRtl: boolean, node: HTMLElement);
text. Checked string.
width. Checked width.
terminator. Text inserted to the string end when checked text does not fit into the item with indicated width.
isRtl. Writing order. Argument is not used, it is required to not change method signature.
node. DOM node to insert in the text.
The cropText method is used to crop the string if it does not fit into the item.
The method returns a JSON object with the following fields:
Field name | Type | Brief description |
Text | String | Text of output string. |
Original | String | Checked string |
IsCroped | Boolean | Determines whether the string is cropped: Available values:
|
To execute the example, it is required to have link to PP.js script file. The following code is to be executed from the browser console. Check whether the Some long text string fits the item with the 100 width. If it does not fit then a part of string which fits will be shown. At the end of result string there will the ... text:
console.log(PP.Ui.cropText("Some long text", 100, "...").Text);
At the end, the console displays the result after the string is cropped:
Some ...
See also: