CenterForOpenScience/truncate

Name: truncate

Owner: Center for Open Science

Description: Dead simple HTML-safe truncation via the DOM.

Created: 2016-07-22 18:27:01.0

Updated: 2016-07-22 18:27:02.0

Pushed: 2016-04-14 14:14:10.0

Homepage:

Size: 209

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

Usage
jQuery.truncate(html, options)
uery.truncate('<p>Stuff and <i>Nonsense</i></p>', {
ngth: 13

Stuff and <i>No?</i></p>'
$el.truncate(options)
uery('<p>Stuff and <i>Nonsense</i></p>').truncate({
ngth: 13
tml();
Stuff and <i>No?</i></p>'
Options

Default options are stored on jQuery.truncate.defaults.

length

Default: Infinity

The maximum length (including the ellipsis) of the truncated html.

stripTags

Default: false

If stripTags is truthy all html tags will be stripped, leaving only the text.

uery.truncate('<p>Stuff and <i>Nonsense</i></p>', {
ngth: 13,
ripTags: true

ff and No?'
words

Default: false

If words is truthy the input will only be truncated at word boundaries.

uery.truncate('<p>Stuff and <i>Nonsense</i></p>', {
ngth: 13,
rds: true

Stuff and?</p>'
keepFirstWord

Default: false

When words and keepFirstWord are both truthy the input will contain at least one word beside the ellipsis even if it's longer than a target length.

uery.truncate('<p>Stuff and <i>Nonsense</i></p>', {
ngth: 4,
rds: true,
epFirstWord: true

Stuff?</p>'
noBreaks

Default: false

If noBreaks is truthy the input will contain no break elements.

uery.truncate('<p>Stuff and<br><i>Nonsense</i></p>', {
ngth: 13,
Breaks: true

Stuff and <i>No?</i></p>'
ellipsis

Default: '?'

The ellipsis setting is used to provide a different character for the ellipsis.

uery.truncate('<p>Stuff and <i>Nonsense</i></p>', {
ngth: 13,
lipsis: '~'

Stuff and <i>No~</i></p>'

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.