PP.Ui.cropText

Syntax

PP.Ui.cropText(text: String, width: Number, terminator: String, isRtl: boolean, node: HTMLElement);

Parameters

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.

Description

The cropText method is used to crop the string if it does not fit into the item.

Comments

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 It determines whether the string is cropped. Available values:
  • true. The string is cropped.

  • false. The string is not cropped.

Example

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:

PP.Ui