Skip to content

Instantly share code, notes, and snippets.

@dchen
Created February 14, 2009 02:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dchen/64223 to your computer and use it in GitHub Desktop.
Save dchen/64223 to your computer and use it in GitHub Desktop.
RUZEE.Ellipsis for jQuery
/**
* RUZEE.Ellipsis 0.1
* (c) 2007 Steffen Rusitschka
*
* RUZEE.Ellipsis is freely distributable under the terms of an MIT-style license.
* For details, see http://www.ruzee.com/
*
* Modified for use with jQuery instead of Prototype.
* GitHub - http://gist.github.com/64223
* Fooala - http://opensource.fooala.com/
*/
document.write('<style type="text/css">' +
'.ellipsis { margin-right:-10000px; }</style>');
$j(document).ready(function(){
$j('.ellipsis').each(function (i) {
var e = this;
var w = $j(e).width() - 10000;
var t = e.innerHTML;
$j(e).html("<span>" + t + "</span>");
e = $j(e).children(":first-child")
while (t.length > 0 && $j(e).width() >= w) {
t = t.substr(0, t.length - 1);
$j(e).html(t + "...");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment