2016-08-11 22:05:23 +08:00
|
|
|
/*
|
|
|
|
* Truncate long strings where is necessary.
|
|
|
|
*/
|
2016-07-22 19:29:01 +08:00
|
|
|
function truncateLongString( el, chars ) {
|
|
|
|
var input = $.trim(el.text());
|
|
|
|
|
2016-09-01 21:45:39 +08:00
|
|
|
var html = "";
|
|
|
|
if( el.children().hasClass("glyphicon") ){
|
|
|
|
html = el.children()[0];
|
|
|
|
}
|
|
|
|
|
2016-09-29 20:12:52 +08:00
|
|
|
if( input.length >= chars ){
|
2016-07-22 19:29:01 +08:00
|
|
|
var newText = el.text().slice(0, chars);
|
|
|
|
for( var i = newText.length; i > 0; i--){
|
2016-09-01 21:45:39 +08:00
|
|
|
if(newText[i] === ' ' && i > 10){
|
2016-07-22 19:29:01 +08:00
|
|
|
newText = newText.slice(0, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-14 17:11:35 +08:00
|
|
|
|
|
|
|
if ( html ) {
|
|
|
|
el.html(html.outerHTML + newText + '...' );
|
|
|
|
} else {
|
|
|
|
el.html(newText + '...' );
|
|
|
|
}
|
2016-07-22 19:29:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 22:05:23 +08:00
|
|
|
/*
|
|
|
|
* Usefull for converting locals messages to error format
|
2016-09-28 18:54:47 +08:00
|
|
|
* (i.e. no dot at the end).
|
2016-08-11 22:05:23 +08:00
|
|
|
*/
|
2016-08-05 23:00:29 +08:00
|
|
|
String.prototype.strToErrorFormat = function() {
|
2016-07-22 19:29:01 +08:00
|
|
|
var length = this.length;
|
|
|
|
if (this[length - 1] === ".") {
|
|
|
|
length -= 1;
|
|
|
|
}
|
2016-09-28 18:54:47 +08:00
|
|
|
return this.slice(0, length);
|
2016-08-05 23:00:29 +08:00
|
|
|
}
|