mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-13 12:47:11 +08:00
29 lines
693 B
JavaScript
29 lines
693 B
JavaScript
/*
|
|
* Truncate long strings where is necessary.
|
|
*/
|
|
function truncateLongString( el, chars ) {
|
|
var input = $.trim(el.text());
|
|
|
|
if( input.length >= chars){
|
|
var newText = el.text().slice(0, chars);
|
|
for( var i = newText.length; i > 0; i--){
|
|
if(newText[i] === ' '){
|
|
newText = newText.slice(0, i);
|
|
break;
|
|
}
|
|
}
|
|
el.text(newText + '...');
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Usefull for converting locals messages to error format
|
|
* (i.e. lower cased capital and no dot at the end).
|
|
*/
|
|
String.prototype.strToErrorFormat = function() {
|
|
var length = this.length;
|
|
if (this[length - 1] === ".") {
|
|
length -= 1;
|
|
}
|
|
return this.charAt(0).toLowerCase() + this.slice(1, length);
|
|
}
|