MediaWiki:Common.js/truncate.js

/* */ $('span.flTruncate').each(function { function isAlphabetic(ch) {    return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');  }

function roughTruncate(str, len) { str = str.trim; if (str.length <= len) return str; var newLen = len; if (isAlphabetic(str[newLen])) { // Extend the string until we find the end of this word while (newLen < str.length && isAlphabetic(str[newLen])) newLen++; }   else { // Shorten the string until we find the end of the previous word while (newLen > 0 && !isAlphabetic(str[newLen-1])) newLen--; }   if (newLen == str.length) return str; if (str[newLen] != '.' ||	(str.length > newLen + 1 && str[newLen+1] == '.')) { return str.substring(0, newLen) + "..."; }   else { return str.substring(0, newLen+1); // including period } }  var truncateLen = $(this).attr('data-truncateLen'); if (truncateLen) truncateLen = parseInt(truncateLen); else truncateLen = 100; $(this).text(roughTruncate($(this).text, truncateLen)); }); /* */