diff options
author | Julius Härtl <jus@bitgrid.net> | 2017-12-16 14:13:22 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2017-12-19 18:49:26 +0100 |
commit | d497f79625a35330f8a07d9d6913281fa2d0deac (patch) | |
tree | 992d70b41e9e65a6ac6ce8e11c9c63891b8704b0 /core/js | |
parent | 6b5e3a936584add25af32c73bf49d0a8e6288e9a (diff) | |
download | nextcloud-server-d497f79625a35330f8a07d9d6913281fa2d0deac.tar.gz nextcloud-server-d497f79625a35330f8a07d9d6913281fa2d0deac.zip |
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: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/jquery.avatar.js | 73 |
1 files changed, 27 insertions, 46 deletions
diff --git a/core/js/jquery.avatar.js b/core/js/jquery.avatar.js index ae678f17ff8..67dd10482fa 100644 --- a/core/js/jquery.avatar.js +++ b/core/js/jquery.avatar.js @@ -106,54 +106,35 @@ }); } - // If the displayname is not defined we use the old code path - 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(); + var img = new Image(); - // If the new image loads successfully set it. - img.onload = function() { - $div.text(''); - $div.append(img); - $div.clearimageplaceholder(); + // If the new image loads successfully set it. + img.onload = function() { + $div.text(''); + $div.append(img); + $div.clearimageplaceholder(); - if(typeof callback === 'function') { - callback(); - } - }; + if(typeof callback === 'function') { + 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.show(); - img.width = size; - img.height = size; - img.src = url; - } + $div.addClass('icon-loading'); + $div.show(); + img.width = size; + img.height = size; + img.src = url; }; }(jQuery)); |