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 ) {
|
2016-12-13 21:54:37 +08:00
|
|
|
if($.type(el) !== 'string'){
|
|
|
|
var input = $.trim(el.text());
|
|
|
|
} else {
|
|
|
|
var input = $.trim(el);
|
|
|
|
}
|
2016-07-22 19:29:01 +08:00
|
|
|
|
2016-09-01 21:45:39 +08:00
|
|
|
var html = "";
|
2016-12-13 21:54:37 +08:00
|
|
|
if( $.type(el) !== 'string' &&
|
|
|
|
el.children().hasClass("glyphicon")) {
|
2016-09-01 21:45:39 +08:00
|
|
|
html = el.children()[0];
|
|
|
|
}
|
|
|
|
|
2016-09-29 20:12:52 +08:00
|
|
|
if( input.length >= chars ){
|
2016-12-13 21:54:37 +08:00
|
|
|
if($.type(el) != 'string') {
|
|
|
|
var newText = el.text().slice(0, chars);
|
|
|
|
}else {
|
|
|
|
var newText = el.slice(0, chars);
|
|
|
|
}
|
2016-07-22 19:29:01 +08:00
|
|
|
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 {
|
2016-12-13 21:54:37 +08:00
|
|
|
if($.type(el) === 'string'){
|
|
|
|
return newText + '...';
|
|
|
|
} else {
|
2016-09-14 17:11:35 +08:00
|
|
|
el.html(newText + '...' );
|
2016-12-13 21:54:37 +08:00
|
|
|
}
|
2016-09-14 17:11:35 +08:00
|
|
|
}
|
2016-12-13 21:54:37 +08:00
|
|
|
} else {
|
|
|
|
return el;
|
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
|
|
|
}
|