Constructor
new TruncatableTextField($container, $element, [options])
#
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
$container |
jQuery | The container for the element. |
|||||||||
$element |
jQuery | The element where we should put the text. |
|||||||||
options |
Object |
optional |
Properties:
|
Properties
$element
#
Properties:
| Name | Type | Description |
|---|---|---|
$element |
jQuery | The DOM element that holds text for this element. |
$ellipsis
#
Properties:
| Name | Type | Description |
|---|---|---|
ellipsis |
jQuery | the element which marks that the text was truncated |
expanded
#
Properties:
| Name | Type | Description |
|---|---|---|
expanded |
boolean | true if the text is long enough to be truncated but the full text is shown |
normalTitle
#
Properties:
| Name | Type | Description |
|---|---|---|
normalTitle |
string | title attribute to show when the text is not truncated |
truncatedTitle
#
Properties:
| Name | Type | Description |
|---|---|---|
truncatedTitle |
string | title attribute to show when the text is not truncated |
Methods
changeStyle()
#
Changes the element style if a certain length is reached.
grow()
#
Makes the container flexible-width, thereby restoring the full text.
isTruncatable() → {boolean}
#
Returns true if the text is long enough that it needs to be truncated.
Returns:
- Type
- boolean
isTruncated() → {boolean}
#
Returns true if the text is truncated at the moment.
Returns:
- Type
- boolean
repaint()
#
Recalculate truncation after layout changes (such as resize)
set(value)
#
Sets the string for the element.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
string | Warning - unsafe HTML is allowed here. |
setTitle(normal, truncated)
#
Allows setting different titles for fully visible and for truncated text.
Parameters:
| Name | Type | Description |
|---|---|---|
normal |
string | |
truncated |
string |
shrink()
#
Makes the container fixed-width, clipping the text. This will only add a .mw-mmv-ttf-truncated class; it's the caller's responsibility to define the fixed height for that class.
updateTitle()
#
Selects the right title to use (for full or for truncated version). The title can be set with setTitle().