Created
December 1, 2012 23:40
-
-
Save amaxwell01/4185962 to your computer and use it in GitHub Desktop.
General Ellipsis Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* ========================================================================== | |
| 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