Merge pull request #6591 from nextcloud/unify-appearance-of-avatars-for-undefined-and-unknown-users

Unify appearance of avatars for undefined and unknown users
This commit is contained in:
Roeland Jago Douma 2017-09-24 13:12:58 +02:00 committed by GitHub
commit 4ee731c1ab
2 changed files with 12 additions and 4 deletions

View File

@ -48,6 +48,11 @@
(function ($) { (function ($) {
$.fn.avatar = function(user, size, ie8fix, hidedefault, callback, displayname) { $.fn.avatar = function(user, size, ie8fix, hidedefault, callback, displayname) {
var setAvatarForUnknownUser = function(target) {
target.imageplaceholder('?');
target.css('background-color', '#b9b9b9');
};
if (typeof(user) !== 'undefined') { if (typeof(user) !== 'undefined') {
user = String(user); user = String(user);
} }
@ -72,7 +77,7 @@
if (typeof(this.data('user')) !== 'undefined') { if (typeof(this.data('user')) !== 'undefined') {
user = this.data('user'); user = this.data('user');
} else { } else {
this.imageplaceholder('?'); setAvatarForUnknownUser(this);
return; return;
} }
} }
@ -112,8 +117,7 @@
$div.imageplaceholder(user, result.data.displayname); $div.imageplaceholder(user, result.data.displayname);
} else { } else {
// User does not exist // User does not exist
$div.imageplaceholder(user, '?'); setAvatarForUnknownUser($div);
$div.css('background-color', '#b9b9b9');
} }
} else { } else {
$div.hide(); $div.hide();

View File

@ -62,10 +62,12 @@ describe('jquery.avatar tests', function() {
it('undefined user', function() { it('undefined user', function() {
spyOn($div, 'imageplaceholder'); spyOn($div, 'imageplaceholder');
spyOn($div, 'css');
$div.avatar(); $div.avatar();
expect($div.imageplaceholder).toHaveBeenCalledWith('?'); expect($div.imageplaceholder).toHaveBeenCalledWith('?');
expect($div.css).toHaveBeenCalledWith('background-color', '#b9b9b9');
}); });
describe('no avatar', function() { describe('no avatar', function() {
@ -86,6 +88,7 @@ describe('jquery.avatar tests', function() {
it('show placeholder for non existing user', function() { it('show placeholder for non existing user', function() {
spyOn($div, 'imageplaceholder'); spyOn($div, 'imageplaceholder');
spyOn($div, 'css');
$div.avatar('foo'); $div.avatar('foo');
fakeServer.requests[0].respond( fakeServer.requests[0].respond(
@ -96,7 +99,8 @@ describe('jquery.avatar tests', function() {
}) })
); );
expect($div.imageplaceholder).toHaveBeenCalledWith('foo', '?'); expect($div.imageplaceholder).toHaveBeenCalledWith('?');
expect($div.css).toHaveBeenCalledWith('background-color', '#b9b9b9');
}); });
it('show no placeholder', function() { it('show no placeholder', function() {