Skip to content

Commit

Permalink
Dynamicaly change avatar and header bg from account setting (#4289)
Browse files Browse the repository at this point in the history
  • Loading branch information
ykzts authored and Gargron committed Jul 21, 2017
1 parent dbaa6a0 commit f2390e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/javascript/packs/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ function main() {
noteCounter.textContent = 160 - length(target.value);
}
});

delegate(document, '#account_avatar', 'change', ({ target }) => {
const avatar = document.querySelector('.card.compact .avatar img');
const [file] = target.files || [];
const url = URL.createObjectURL(file);
avatar.src = url;
});

delegate(document, '#account_header', 'change', ({ target }) => {
const header = document.querySelector('.card.compact');
const [file] = target.files || [];
const url = URL.createObjectURL(file);
header.style.backgroundImage = `url(${url})`;
});
}

loadPolyfills().then(main).catch(error => {
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/styles/accounts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

.avatar {
margin-bottom: 0;

img {
object-fit: cover;
}
}
}

Expand Down

0 comments on commit f2390e2

Please sign in to comment.