1
0
mirror of https://github.com/flarum/core.git synced 2025-08-10 18:35:56 +02:00

Use blurred version of avatar as user card background

This commit is contained in:
Toby Zerner
2015-03-27 11:50:38 +10:30
parent 257a3fde1a
commit b96fd23842
4 changed files with 49 additions and 4 deletions

View File

@@ -13,6 +13,48 @@ export default Ember.Component.extend(HasItemLists, {
return 'background-color: '+this.get('user.color');
}),
avatarUrlDidChange: Ember.observer('user.avatarUrl', function() {
this.refreshOverlay(true);
}),
didInsertElement: function() {
this.refreshOverlay();
},
refreshOverlay: function(animate) {
var component = this;
var $overlay = component.$('.darken-overlay');
var $newOverlay = $overlay.clone().removeAttr('style').insertBefore($overlay);
var avatarUrl = component.get('user.avatarUrl');
var hideOverlay = function() {
if (animate) {
$overlay.fadeOut('slow');
}
$overlay.promise().done(function() {
$(this).remove();
});
};
if (avatarUrl) {
$('<img>').attr('src', avatarUrl).on('load', function() {
component.$().css('background-image', 'url('+avatarUrl+')');
$newOverlay.blurjs({
source: component.$(),
radius: 50,
overlay: 'rgba(0, 0, 0, .2)',
useCss: false
});
component.$().css('background-image', '');
if (animate) {
$newOverlay.hide().fadeIn('slow');
}
hideOverlay();
});
} else {
hideOverlay();
}
},
populateControls: function(items) {
this.addActionItem(items, 'edit', 'Edit', 'pencil');
this.addActionItem(items, 'delete', 'Delete', 'times');