Skip to content

Instantly share code, notes, and snippets.

@amaxwell01
Created December 1, 2012 23:40
Show Gist options
  • Select an option

  • Save amaxwell01/4185962 to your computer and use it in GitHub Desktop.

Select an option

Save amaxwell01/4185962 to your computer and use it in GitHub Desktop.
General Ellipsis Script
/* ==========================================================================
Ellipsis
* @params : item : Gets the ID of the element that you want to ellipsis
* the text in item can also be overloaded, it can be a string as well, in
* which case if it is long enough it will return the string with the
* ellipsed ammount.
* @params : amount : The number of characters that you want to include
========================================================================== */
var ellipsis = function( item, amount ) {
switch( typeof(item) )
{
case 'string':
var currentText = item;
var newText = '';
if( currentText.length > amount ) {
currentText = currentText.substring(0, amount - 3);
return currentText += '...';
} else {
return currentText;
}
break;
default:
var item = $(item);
item.each(function( element, value ) {
var currentText = value.text();
if( currentText.length > amount ) {
currentText = currentText.substring(0, amount - 3);
currentText += '...';
value.text(currentText);
}
});
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment