Created
March 15, 2012 16:39
-
-
Save Demwunz/2045190 to your computer and use it in GitHub Desktop.
JavaScript: trim text
This file contains 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
trimText : function(obj, body, length){ | |
var splitLocation = body.indexOf(' ', length); | |
if(splitLocation != -1) { | |
// truncate tip | |
var splitLocation = body.indexOf(' ', length), | |
str1 = body.substring(0, splitLocation), | |
str2 = body.substring(splitLocation, length - 1); | |
obj.html(str1 + '<span class="truncate_ellipsis">…</span>' + '<span class="truncate_more">' + str2 + '</span>'); | |
obj.find('.truncate_more').css("display", "none"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment