user-avatar.html 1.3 KB

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