(, CSS3 text-overflow: ) , , , , . Javascript #. , . :
String # replace , .
, 8 , , :
function replace_second_group_with_an_ellipsis(){
return arguments[1] + (arguments[2] ? '...' : '');
}
toolTipString.replace(/(^.{0,8})(.*)/, replace_second_group_with_an_ellipsis);
, replace(), arguments , .
, , . , . , javascript . :
function shorten_nicely_with_ellipsis(){
var str = arguments[1];
var truncating = !!arguments[2];
if( truncating && !arguments[2].match(/^\s/) ) {
for(var i=str.length; --i; i<=1) {
if( str[i].match(/\s/) && !str[i-1].match(/\s/) ) {
str = arguments[1].substr(0, i);
break;
}
}
}
if( truncating ) {
str = str + '...';
}
return str;
}
toolTipString.replace(/(^.{0,8})(.*)/, shorten_nicely_with_ellipsis);