I need to implement ellipsis (\"...\") in the middle of a text within a resizable element. Here is what it might look like. So,
\"Lorem ipsum do
I just created a function that can trim at the middle, nearEnd and End but havent been tested yet because I finally was needing it at the server side
//position acceptable values : middle, end, closeEnd
function AddElipsis(input, maxChars, position) {
if (typeof input === 'undefined') {
return "";
}
else if (input.length <= maxChars) {
return input;
}
else {
if (position == 'middle') {
var midPos = Math.floor(maxChars / 2) - 2;
return input.substr(0, midPos) + '...' + input.substr(input.length - midPos, input.length);
}
else if (position == 'closeEnd') {
var firstPart = Math.floor(maxChars * 0.80) - 2;
var endPart = Math.floor(maxChars * 0.20) - 2;
return input.substr(0, firstPart) + '...' + input.substr(input.length - endPart, input.length);
}
else {
return input.substr(0, maxChars - 3) + '...';
}
}
}