Skip to content

Instantly share code, notes, and snippets.

@dbarrionuevo
Created July 10, 2014 18:27
Show Gist options
  • Select an option

  • Save dbarrionuevo/781b2a483e4d2f56be3c to your computer and use it in GitHub Desktop.

Select an option

Save dbarrionuevo/781b2a483e4d2f56be3c to your computer and use it in GitHub Desktop.
$(function() {
var len = 100;
var p = $("[data-id='truncate']");
if (p) {
var trunc = p.html();
if (trunc.length > len) {
trunc = trunc.substring(0, len);
trunc = trunc.replace(/\w+$/, '');
trunc += '<a href="#" ' +
'onclick="this.parentNode.innerHTML=' +
'unescape(\''+escape(p.html())+'\');return false;">' +
'...<\/a>';
p.html(trunc);
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment