Merge pull request #20943 from owncloud/load_avatar_once
[Avatars] JS should not load same avatar twice
This commit is contained in:
commit
af8bcb3a4d
|
@ -47,7 +47,7 @@
|
|||
*/
|
||||
|
||||
(function ($) {
|
||||
$.fn.avatar = function(user, size, ie8fix, hidedefault, callback) {
|
||||
$.fn.avatar = function(user, size, ie8fix, hidedefault, callback, displayname) {
|
||||
if (typeof(size) === 'undefined') {
|
||||
if (this.height() > 0) {
|
||||
size = this.height();
|
||||
|
@ -79,6 +79,8 @@
|
|||
'/avatar/{user}/{size}',
|
||||
{user: user, size: Math.ceil(size * window.devicePixelRatio)});
|
||||
|
||||
// If the displayname is not defined we use the old code path
|
||||
if (typeof(displayname) === 'undefined') {
|
||||
$.get(url, function(result) {
|
||||
if (typeof(result) === 'object') {
|
||||
if (!hidedefault) {
|
||||
|
@ -104,5 +106,24 @@
|
|||
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 successfull set it.
|
||||
img.onload = function() {
|
||||
$div.show();
|
||||
$div.text('');
|
||||
$div.append(img);
|
||||
}
|
||||
|
||||
img.width = size;
|
||||
img.height = size;
|
||||
img.src = url;
|
||||
}
|
||||
};
|
||||
}(jQuery));
|
||||
|
|
|
@ -65,8 +65,7 @@ var UserList = {
|
|||
* Avatar or placeholder
|
||||
*/
|
||||
if ($tr.find('div.avatardiv').length){
|
||||
$tr.find('.avatardiv').imageplaceholder(user.name, user.displayname);
|
||||
$('div.avatardiv', $tr).avatar(user.name, 32);
|
||||
$('div.avatardiv', $tr).avatar(user.name, 32, undefined, undefined, undefined, user.displayname);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue