diff --git a/core/js/jquery.avatar.js b/core/js/jquery.avatar.js index 29d019baea..fae100fda2 100644 --- a/core/js/jquery.avatar.js +++ b/core/js/jquery.avatar.js @@ -48,6 +48,11 @@ (function ($) { $.fn.avatar = function(user, size, ie8fix, hidedefault, callback, displayname) { + var setAvatarForUnknownUser = function(target) { + target.imageplaceholder('?'); + target.css('background-color', '#b9b9b9'); + }; + if (typeof(user) !== 'undefined') { user = String(user); } @@ -72,7 +77,7 @@ if (typeof(this.data('user')) !== 'undefined') { user = this.data('user'); } else { - this.imageplaceholder('?'); + setAvatarForUnknownUser(this); return; } } @@ -112,8 +117,7 @@ $div.imageplaceholder(user, result.data.displayname); } else { // User does not exist - $div.imageplaceholder(user, '?'); - $div.css('background-color', '#b9b9b9'); + setAvatarForUnknownUser($div); } } else { $div.hide(); diff --git a/core/js/tests/specs/jquery.avatarSpec.js b/core/js/tests/specs/jquery.avatarSpec.js index dab78500d0..d730573669 100644 --- a/core/js/tests/specs/jquery.avatarSpec.js +++ b/core/js/tests/specs/jquery.avatarSpec.js @@ -62,10 +62,12 @@ describe('jquery.avatar tests', function() { it('undefined user', function() { spyOn($div, 'imageplaceholder'); + spyOn($div, 'css'); $div.avatar(); expect($div.imageplaceholder).toHaveBeenCalledWith('?'); + expect($div.css).toHaveBeenCalledWith('background-color', '#b9b9b9'); }); describe('no avatar', function() { @@ -86,6 +88,7 @@ describe('jquery.avatar tests', function() { it('show placeholder for non existing user', function() { spyOn($div, 'imageplaceholder'); + spyOn($div, 'css'); $div.avatar('foo'); 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() {