user-avatar.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <link rel="import" href="../contact-item/anonymous-contact-behavior.html">
  2. <dom-module id="user-avatar">
  3. <template>
  4. <style>
  5. :host {
  6. display: block;
  7. @apply(--layout-vertical);
  8. @apply(--layout-center);
  9. width: 120px;
  10. }
  11. .avatar {
  12. display: inline-block;
  13. width: 52px;
  14. height: 52px;
  15. border-radius: 50%;
  16. overflow: hidden;
  17. background: #ccc;
  18. @apply(--shadow-elevation-2dp);
  19. }
  20. .paper-font-subhead{
  21. text-align: center;
  22. }
  23. </style>
  24. <div class="avatar" id="avatar" item-icon></div>
  25. <div class="paper-font-subhead">{{_displayName}}</div>
  26. </template>
  27. <script>
  28. 'use strict';
  29. Polymer({
  30. is: 'user-avatar',
  31. behaviors:[Chat.AnonymousContactBehavior],
  32. observers:['_computeBackgroundImg(contact.*)'],
  33. _computeBackgroundImg:function(){
  34. console.log('avatar changed');
  35. var avatar = this.anonymousAccount(this.contact).avatar;
  36. var style = this.$.avatar.style;
  37. style.backgroundImage='url('+avatar.url+')';
  38. style.backgroundPosition=avatar.left+'px '+avatar.top+'px';
  39. }
  40. });
  41. </script>
  42. </dom-module>