jquery.autoellipsis is a jQuery plugin for automatically applying ellipsis on selected elements. This plugin optimally uses the available space, unlike methods like character counting.
Download
The latest version of the jquery.autoellipsis library can be downloaded from here:
- jquery.autoellipsis-1.0.10.js SHA-1 sum: a614f35ca9f1d92b8da777c0ba275351a1fcc672
- jquery.autoellipsis-1.0.10.min.js SHA-1 sum: eb9b749f6e8a667d72f0cec839a6dab48a381ee5
License
jquery.autoellipsis is available on GitHub under MIT license.
How to use
- ellipsis The ellipsis character or string to use. Defaults to "..." (three dots).
- setTitle Sets the
title
attribute of the affected elements with the original content. May be set to eithernever
,onEllipsis
oralways
. When usingonEllipsis
, thetitle
attribute will only be set when the content of the element was indeed ellipsed. Defaults tonever
. - live When set to
true
, perform ellipsis on current and future elements matching the jQuery selection. Also reapplies the ellipsis when the target elements' dimensions change. Use with care, as this mode polls the selection elements. Defaults tofalse
.
jQuery
object for chaining purposes.Example
The example code below shows how to use the ellipsis plugin. It uses jGFeed to retrieve the Global News RSS feed from the New York Times.
The feed items are rendered in fixed-height blocks, after which the ellipsis is applied. Using the default .ellipsis()
call with no arguments, the ellipsis method works on all sub-elements.
(function($) { $(document).ready(function() { $.jGFeed('http://www.nytimes.com/services/xml/rss/nyt/GlobalHome.xml', function(feeds) { if (feeds) { for (var i = 0, ii = feeds.entries.length; i < ii; i++) { var entry = feeds.entries[i]; $('#nyt-feed').append('<li><span class="title">' + entry.title + '</span><span class="description">' + entry.content + '</span></li>'); } $('#nyt-feed li').ellipsis(); }; }, 5); }); })(jQuery);