server/core/js/jquery.avatar.js

47 lines
1 KiB
JavaScript
Raw Normal View History

2013-08-29 12:26:11 +00:00
/**
* Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
(function ($) {
$.fn.avatar = function(user, size) {
if (typeof(size) === 'undefined') {
if (this.height() > 0) {
size = this.height();
} else if (this.data('size') > 0) {
size = this.data('size');
} else {
size = 64;
}
2013-08-29 12:26:11 +00:00
}
this.height(size);
this.width(size);
2013-08-29 12:26:11 +00:00
if (typeof(user) === 'undefined') {
if (typeof(this.data('user')) !== 'undefined') {
user = this.data('user');
} else {
this.placeholder('x');
return;
}
2013-08-29 12:26:11 +00:00
}
// sanitize
user = user.replace(/\//g,'');
2013-08-29 12:26:11 +00:00
var $div = this;
2013-08-31 17:05:53 +00:00
var url = OC.router_base_url+'/avatar/'+user+'/'+size // FIXME routes aren't loaded yet, so OC.Router.generate() doesn't work
$.get(url, function(result) {
2013-08-29 12:26:11 +00:00
if (typeof(result) === 'object') {
$div.placeholder(result.user);
} else {
2013-08-31 17:05:53 +00:00
$div.html('<img src="'+url+'">');
2013-08-29 12:26:11 +00:00
}
});
2013-08-31 17:05:53 +00:00
};
2013-08-29 12:26:11 +00:00
}(jQuery));