diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-12-20 12:38:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-20 12:38:05 +0100 |
commit | dc8809e754c22addaab20401a7505dcc4082541c (patch) | |
tree | 3d976ec5e32d105967c2d76bfbb9f8ca694cd61f /core/js/jquery.avatar.js | |
parent | b6fcf59881b27f0a0b7541ff6e01921d7a23142e (diff) | |
parent | 0ff3c81fc14793ddb39d6d46549ec56cfec26ddd (diff) | |
download | nextcloud-server-dc8809e754c22addaab20401a7505dcc4082541c.tar.gz nextcloud-server-dc8809e754c22addaab20401a7505dcc4082541c.zip |
Merge pull request #7498 from nextcloud/fix_7497
Better handle avatars
Diffstat (limited to 'core/js/jquery.avatar.js')
-rw-r--r-- | core/js/jquery.avatar.js | 77 |
1 files changed, 31 insertions, 46 deletions
diff --git a/core/js/jquery.avatar.js b/core/js/jquery.avatar.js index 54518c75cc7..958f0f9edd7 100644 --- a/core/js/jquery.avatar.js +++ b/core/js/jquery.avatar.js @@ -106,54 +106,39 @@ }); } - // 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 { - // We already have the displayname so set the placeholder (to show at least something) - if (!hidedefault) { - $div.imageplaceholder(displayname); - } + var img = new Image(); + + // If the new image loads successfully set it. + img.onload = function() { + $div.text(''); + $div.append(img); + $div.clearimageplaceholder(); - var img = new Image(); + 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'); + } - // If the new image loads successfully set it. - img.onload = function() { - $div.show(); - $div.text(''); - $div.append(img); - $div.clearimageplaceholder(); - }; + if(typeof callback === 'function') { + callback(); + } + }; - 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)); |