2018-04-13 16:59:33 +02:00
|
|
|
|
|
|
|
function truncateText (str) {
|
|
|
|
var cutoff = 20;
|
|
|
|
if (/\s/.test(str)) {
|
|
|
|
cutoff = 50;
|
|
|
|
}
|
|
|
|
return str.length < cutoff ? str : str.substr(0, cutoff-3) +'…';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getInitials(fullname) {
|
|
|
|
var f = "A";
|
|
|
|
var s = "Z";
|
|
|
|
if (fullname != null) {
|
|
|
|
var parts = fullname.split(' ');
|
|
|
|
if (parts.length > 0) {
|
|
|
|
f = parts[0].substring(0, 1).toUpperCase();
|
|
|
|
s = parts[parts.length-1].substring(0, 1).toUpperCase();
|
|
|
|
} else {
|
|
|
|
f = fullname.substring(0,1);
|
|
|
|
s = fullname.substring(1,2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var name = f+s;
|
|
|
|
return '<span title="'+fullname+'" style="background-color: '+nameToColor(fullname)+'; border-radius: 5px; padding: 5px; font-size: 10px; color: white;">'+name+'</span>';
|
|
|
|
}
|
|
|
|
|
|
|
|
function nameToColor(name) {
|
|
|
|
var colors = [
|
|
|
|
"#8e8e93",
|
|
|
|
"#ff2d55",
|
|
|
|
"#ff3b30",
|
|
|
|
"#ff9500",
|
|
|
|
"#ffcc00",
|
|
|
|
"#4cd964",
|
|
|
|
"#5ac8fa",
|
|
|
|
"#34aadc",
|
|
|
|
"#007aff",
|
|
|
|
"#5856d6"];
|
|
|
|
var hash = hashStr(name);
|
|
|
|
var index = hash % colors.length;
|
|
|
|
return colors[index];
|
|
|
|
}
|
|
|
|
|
2018-05-09 17:55:33 +02:00
|
|
|
//very simple hash for assigning always the same color to the owner of the file
|
2018-04-13 16:59:33 +02:00
|
|
|
function hashStr(str) {
|
|
|
|
var hash = 0;
|
|
|
|
for (var i = 0; i < str.length; i++) {
|
|
|
|
var charCode = str.charCodeAt(i);
|
|
|
|
hash += charCode;
|
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|