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 ($) {
|
2013-08-30 07:00:37 +00:00
|
|
|
$.fn.avatar = function(user, size) {
|
|
|
|
if (typeof(size) === 'undefined') {
|
|
|
|
if (this.height() > 0) {
|
|
|
|
size = this.height();
|
2013-08-31 16:27:28 +00:00
|
|
|
} else if (this.data('size') > 0) {
|
|
|
|
size = this.data('size');
|
2013-08-30 07:00:37 +00:00
|
|
|
} else {
|
|
|
|
size = 64;
|
|
|
|
}
|
2013-08-29 12:26:11 +00:00
|
|
|
}
|
|
|
|
|
2013-08-30 07:00:37 +00:00
|
|
|
this.height(size);
|
|
|
|
this.width(size);
|
2013-08-29 12:26:11 +00:00
|
|
|
|
|
|
|
if (typeof(user) === 'undefined') {
|
2013-08-31 16:27:28 +00:00
|
|
|
if (typeof(this.data('user')) !== 'undefined') {
|
|
|
|
user = this.data('user');
|
|
|
|
} else {
|
|
|
|
this.placeholder('x');
|
|
|
|
return;
|
|
|
|
}
|
2013-08-29 12:26:11 +00:00
|
|
|
}
|
|
|
|
|
2013-08-31 16:27:28 +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));
|