Skip to content
Snippets Groups Projects
Unverified Commit d497f796 authored by Julius Härtl's avatar Julius Härtl
Browse files

Fix fallback when image loading fails


With the new avatar endpoint there is no difference between unknown
users and errors when generating the placeholder avatar. Therefore the
avatar function will now show the old placeholder if both a user and
displayname was given as parameters.

In case there is no displayname provided we cannot build the proper
placeholder so the unknown user placeholder is shown.

The displayname is not required for the avatar anymore, so we can
get rid of the old code path for placeholders.

Signed-off-by: default avatarRoeland Jago Douma <roeland@famdouma.nl>
parent 6b5e3a93
No related branches found
No related tags found
No related merge requests found
...@@ -106,54 +106,35 @@ ...@@ -106,54 +106,35 @@
}); });
} }
// If the displayname is not defined we use the old code path var img = new Image();
if (typeof(displayname) === 'undefined') {
$.get(url).always(function(result, status) {
// if there is an error or an object returned (contains user information):
// -> show the fallback placeholder
if (typeof(result) === 'object' || status === 'error') {
if (!hidedefault) {
if (result.data && result.data.displayname) {
$div.imageplaceholder(user, result.data.displayname);
} else {
// User does not exist
setAvatarForUnknownUser($div);
}
} else {
$div.hide();
}
// else an image is transferred and should be shown
} else {
$div.show();
if (ie8fix === true) {
$div.html('<img width="' + size + '" height="' + size + '" src="'+url+'#'+Math.floor(Math.random()*1000)+'" alt="">');
} else {
$div.html('<img width="' + size + '" height="' + size + '" src="'+url+'" alt="">');
}
}
if(typeof callback === 'function') {
callback();
}
});
} else {
var img = new Image();
// If the new image loads successfully set it. // If the new image loads successfully set it.
img.onload = function() { img.onload = function() {
$div.text(''); $div.text('');
$div.append(img); $div.append(img);
$div.clearimageplaceholder(); $div.clearimageplaceholder();
if(typeof callback === 'function') { if(typeof callback === 'function') {
callback(); callback();
} }
}; };
// Fallback when avatar loading fails:
// Use old placeholder when a displayname attribute is defined,
// otherwise show the unknown user placeholder.
img.onerror = function () {
$div.clearimageplaceholder();
if (typeof(displayname) !== 'undefined') {
$div.imageplaceholder(user, displayname);
} else {
setAvatarForUnknownUser($div);
$div.removeClass('icon-loading');
}
};
$div.addClass('icon-loading'); $div.addClass('icon-loading');
$div.show(); $div.show();
img.width = size; img.width = size;
img.height = size; img.height = size;
img.src = url; img.src = url;
}
}; };
}(jQuery)); }(jQuery));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment