JS Truncate

Overview

The JS Truncation module is used for truncating text blocks to a certain number of lines. This is particularly useful for limiting the height of editable content areas.

This module is basically a wrapper module for dotdotdot, a jQuery plugin that handles text truncation. The documentation for dotdotdot can be found here. You'll need to have dotdotdot installed and loaded in before JS Truncation will work.

Any element given the class js-truncate will be truncated using dotdotdot. The default number of lines is 3, but can be overridden with the data-truncation-lines attribute.

Methods

TruncationHandler.refresh($element)

Refresh the truncation of a given element. This must be used for truncateable elements that are hidden on page load, such as children of modals or hidden navigations, as dotdotdot does not work on hidden elements.

Examples

Basic

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Custom Truncation Type

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.