Skip to content

Instantly share code, notes, and snippets.

@ptone
Created May 11, 2012 21:39
Show Gist options
  • Save ptone/2662550 to your computer and use it in GitHub Desktop.
Save ptone/2662550 to your computer and use it in GitHub Desktop.
softwrap long strings
function softwrap(desc){
var words = desc.split(" ");
var newText = "";
for (var i = 0; i < words.length; i++) {
var aWord = words[i];
console.log(aWord);
if (aWord.length > 20) {
aWord = aWord.replace(/(\S{2})/g,"$1&#8203;");
}
newText += aWord + " ";
}
return newText;
}
$('.record_description').each(function(index, value){value.innerHTML=softwrap(value.innerHTML);})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment