/* WRAP username - Tout le monde a son wrap */
.wrap_username {
background-color: color-mix(in srgb, var(--color, black) 20%, black 10%);
}
div.wrap_username {
box-shadow: 0 0 3px 2px #00000017;
}
@media (prefers-color-scheme: dark) {
.wrap_username {
background-color: color-mix(in srgb, var(--color, black) 20%, white 10%)
}
}
div.wrap_username {
padding: 0.5em 1em 0 1.5em;
margin: 0 0 0.5em 0;
border-radius: 0.5em 0;
}
span.wrap_username {
display: inline-flex;
gap: 0.3em;
padding: 0 0.3em;
}
.wrap_username:before {
content: " ";
background-position: center;
background-repeat: no-repeat;
background-size: cover; /*105%*/
display: inline-block;
border-radius: 50%;
}
div.wrap_username:before {
border: 2px solid var(--color, #AAB);
width: 24px;
height: 24px;
position: absolute;
transform: translate(-2.2em, -0.9em);
}
div.wrap_username:after, span.wrap_username:after {
display: inline-block;
float: right;
margin-top: -1.4em;
color: color-mix(in srgb, var(--color, black) 20%, black 10%)
}
@media (prefers-color-scheme: dark) {
div.wrap_username:after, span.wrap_username:after {
color: color-mix(in srgb, var(--color, black) 20%, white 10%)
}
}
span.wrap_username:before {
width: 18px;
height: 18px;
}
/*
var string_to_color = function(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var colour = '#';
for (var i = 0; i < 3; i++) {
var value = (hash >> (i * 8)) & 0xFF;
colour += ('00' + value.toString(16)).substr(-2);
}
return colour;
}*/
var string_to_color = function(str, h, s, l) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
h = (h + hash) % 360;
return "hsl(" + h + ", " + s + "%, " + l + "%)";
};
function init_username_wrap(wrap_element, username)
{
var img_url = 'https://intranet.cyanide-studio.com/_media/user/' + username + '.jpg';
try
{
jQuery.get(img_url).done(function() {
console.log("Init username", username);
var color = string_to_color(username, -20, 50, 50);
jQuery('head').append('');
wrap_element.addClass("wrap_username");
wrap_element.addClass("wrap_"+username);
}).fail(function () { /*console.log("Invalid username", username);*/ });
}
catch (e)
{
}
}
setTimeout(function() {
jQuery(function () { if (typeof wrap_username === "undefined") { wrap_username = true; {
console.log("Init usernames...");
function is_valid_username(username) {
if (jQuery.isNumeric(username)) return false;
username = username.trim().toLowerCase();
if (jQuery.isNumeric(username)) return false;
if (username.length < 2) return false;
if (jQuery.inArray(username, [
"must", "must", "should", "could", "wont",
"collapsed", "block", "plugin_wrap", "column", "lexicon", "title", "nav", "nav_group", "filters", "toc",
"img-grid", "note", "node", "fetch", "1-2", "1-3", "1-4", "2-1", "2-2", "2-3", "2-4"
]) >= 0) return false;
return true;
}
jQuery('.plugin_wrap, [class*="wrap_"]:not([class*="plugin_include_"])').each(function() {
var wrap_element = jQuery(this);
var id = wrap_element.attr("id");
if (typeof id !== "undefined")
{
if (is_valid_username(id)) {
init_username_wrap(wrap_element, id);
}
}
else
{
var classList = wrap_element.attr("class").split(/\s+/);
classList.forEach(function (className) {
var username = className.replace("wrap_", "");
if (is_valid_username(username)) {
init_username_wrap(wrap_element, username);
}
} );
}
});
console.log("Init usernames... DONE");
} } });
}, 0);
/* Specific a avillepreux ... */
/* ... */