A jQuery plugin that truncates extended text and allows it to be shown dynamically.
This page provides a documentation reference for working with the plugin v1.0.0. See a demonstration of the more plugin and download the code from there. Or see a minimal page that you could use as a basis for your own investigations.
Customise each targetted paragraph with the settings below (all are optional):
$(selector).more({length: 60});
Note that the plugin expects the targetted paragraph to only contain text, and no other markup.
| Name | Type | Default | Comments |
|---|---|---|---|
| length | number | 100 | The number of characters shown after truncation. |
| leeway | number | 5 | The number of additonal characters allowed before truncation is actually applied. For example, with the default values, text up to 105 characters would not be truncated at all, while text over 105 characters would only show the first 100 followed by the ellipsis and link. |
| wordBreak | boolean | false | When false the text is truncated at the character specified by
length, regardless of its position within a word.
When true the text is truncated at the first word boundary before
length. |
| toggle | boolean | true | When true the link at the end of any truncated text toggles to allow
the user to collapse the text again. When false the text can be
expanded once but not collapsed again. |
| ellipsisText | string | '...' | The text used at the end of a truncation to indicate that more text is available. |
| moreText | string | 'Show more' | The text shown on the link to expand the text. |
| lessText | string | 'Show less' | The text shown on the link to collapse the text. |
| onChange | function | null | A callback function to notify of expansion/collapse.
The function receives one parameter being true if expanded
or false if collapsed. Within the function this
refers to the targetted paragraph. |
| Signature | Returns | Comments |
|---|---|---|
| $.more.setDefaults(settings) | More object | Update the default instance settings to use with all more text instances. |
| $(selector).more('change', settings) | jQuery object | Update the settings for the more instance attached to the given text. |
| $(selector).more('settings') | object | Retrieve the current settings for the first more instance attached to the given text. |
| $(selector).more('destroy') | jQuery object | Remove the more functionality from the given text. |
Contact Keith Wood at kbwood{at}iinet.com.au with comments or suggestions.