mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-11 18:21:04 +08:00
39 lines
837 B
JavaScript
39 lines
837 B
JavaScript
/*
|
|
* Truncate long strings where is necessary.
|
|
*/
|
|
function truncateLongString( el, chars ) {
|
|
var input = $.trim(el.text());
|
|
|
|
var html = "";
|
|
if( el.children().hasClass("glyphicon") ){
|
|
html = el.children()[0];
|
|
}
|
|
|
|
if( input.length >= chars ){
|
|
var newText = el.text().slice(0, chars);
|
|
for( var i = newText.length; i > 0; i--){
|
|
if(newText[i] === ' ' && i > 10){
|
|
newText = newText.slice(0, i);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ( html ) {
|
|
el.html(html.outerHTML + newText + '...' );
|
|
} else {
|
|
el.html(newText + '...' );
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Usefull for converting locals messages to error format
|
|
* (i.e. no dot at the end).
|
|
*/
|
|
String.prototype.strToErrorFormat = function() {
|
|
var length = this.length;
|
|
if (this[length - 1] === ".") {
|
|
length -= 1;
|
|
}
|
|
return this.slice(0, length);
|
|
}
|