Fixes #198 Squished avatars

Refactor all avatar views to use a shared partial, then change it to a
background image. Requires allowing unsafe-inline styles in the CSP.
This commit is contained in:
lilia 2015-03-23 14:01:18 -07:00
parent 6509561795
commit 20baa795ad
10 changed files with 48 additions and 42 deletions

View file

@ -53,7 +53,7 @@
</script> </script>
<script type='text/x-tmpl-mustache' id='message'> <script type='text/x-tmpl-mustache' id='message'>
<div class='sender'>{{ sender }}</div> <div class='sender'>{{ sender }}</div>
<span class='avatar'><img src='{{ avatar_url }}' /></span> {{> avatar }}
<div class="bubble"> <div class="bubble">
<p class="content">{{ message }}</p> <p class="content">{{ message }}</p>
<div class='attachments'></div> <div class='attachments'></div>
@ -74,7 +74,7 @@
<div class='clearfix'> <div class='clearfix'>
<div class='group-avatar'> <div class='group-avatar'>
<div class='thumbnail'> <div class='thumbnail'>
<span class='default avatar'><img src='{{ avatar_url }}' /></span> {{> avatar }}
</div> </div>
<input type='file' name='avatar' class='file-input'> <input type='file' name='avatar' class='file-input'>
</div> </div>
@ -85,11 +85,14 @@
</div> </div>
</div> </div>
</script> </script>
<script type='text/x-tmpl-mustache' id='avatar'>
<span class='avatar' style='background-image: url("{{ avatar_url }}");' ></span>
</script>
<script type='text/x-tmpl-mustache' id='contact_pill'> <script type='text/x-tmpl-mustache' id='contact_pill'>
<span>{{ name }}</span><span class='remove'>x</span> <span>{{ name }}</span><span class='remove'>x</span>
</script> </script>
<script type='text/x-tmpl-mustache' id='contact'> <script type='text/x-tmpl-mustache' id='contact'>
<span class='avatar'><img src='{{ avatar_url }}' /></span> {{> avatar }}
<div class='contact-details'> <div class='contact-details'>
<h3 class='contact-name'> <h3 class='contact-name'>
{{ contact_name }} {{ contact_name }}
@ -206,7 +209,7 @@
</script> </script>
<script type='text/x-tmpl-mustache' id='contact-detail'> <script type='text/x-tmpl-mustache' id='contact-detail'>
<div> <div>
<span class='avatar'><img src='{{ avatar_url }}' /></span> {{> avatar }}
<span class='name'>{{ name }}</span> <span class='name'>{{ name }}</span>
{{ #conflict }} {{ #conflict }}
<button class='conflict'><span>Verify</span></button> <button class='conflict'><span>Verify</span></button>

View file

@ -46,7 +46,7 @@
last_message_timestamp: moment(this.model.get('timestamp')).format('MMM D'), last_message_timestamp: moment(this.model.get('timestamp')).format('MMM D'),
number: this.model.getNumber(), number: this.model.getNumber(),
avatar_url: this.model.getAvatarUrl() avatar_url: this.model.getAvatarUrl()
}) }, this.render_partials())
); );
twemoji.parse(this.el, { base: '/images/twemoji/', size: 16 }); twemoji.parse(this.el, { base: '/images/twemoji/', size: 16 });

View file

@ -17,11 +17,10 @@
'use strict'; 'use strict';
window.Whisper = window.Whisper || {}; window.Whisper = window.Whisper || {};
var ContactView = Backbone.View.extend({ var ContactView = Whisper.View.extend({
className: 'contact-detail', className: 'contact-detail',
template: $('#contact-detail').html(),
initialize: function(options) { initialize: function(options) {
this.template = $('#contact-detail').html();
Mustache.parse(this.template);
this.conflict = options.conflict; this.conflict = options.conflict;
}, },
events: { events: {
@ -30,13 +29,12 @@
triggerConflict: function() { triggerConflict: function() {
this.$el.trigger('conflict', {conflict: this.conflict}); this.$el.trigger('conflict', {conflict: this.conflict});
}, },
render: function() { render_attributes: function() {
this.$el.html(Mustache.render(this.template, { return {
name : this.model.getTitle(), name : this.model.getTitle(),
avatar_url : this.model.getAvatarUrl(), avatar_url : this.model.getAvatarUrl(),
conflict : this.conflict conflict : this.conflict
})); };
return this;
} }
}); });

View file

@ -41,7 +41,7 @@
timestamp: moment(this.model.get('received_at')).fromNow(), timestamp: moment(this.model.get('received_at')).fromNow(),
sender: (contact && contact.getTitle()) || '', sender: (contact && contact.getTitle()) || '',
avatar_url: (contact && contact.getAvatarUrl()) avatar_url: (contact && contact.getAvatarUrl())
}) }, this.render_partials())
); );
twemoji.parse(this.el, { base: '/images/twemoji/', size: 16 }); twemoji.parse(this.el, { base: '/images/twemoji/', size: 16 });

View file

@ -29,6 +29,7 @@
this.recipients_view = new Whisper.RecipientsInputView(); this.recipients_view = new Whisper.RecipientsInputView();
this.$el.find('.scrollable').append(this.recipients_view.el); this.$el.find('.scrollable').append(this.recipients_view.el);
this.$el.find('.avatar').addClass('default');
}, },
events: { events: {
'click .back': 'goBack', 'click .back': 'goBack',

View file

@ -25,11 +25,18 @@
render_attributes: function() { render_attributes: function() {
return _.result(this.model, 'attributes', {}); return _.result(this.model, 'attributes', {});
}, },
render_partials: function() {
return {
avatar: this.avatar_template
};
},
render: function() { render: function() {
var attrs = _.result(this, 'render_attributes', {}); var attrs = _.result(this, 'render_attributes', {});
var template = _.result(this, 'template', ''); var template = _.result(this, 'template', '');
this.$el.html(Mustache.render(template, attrs)); var partials = _.result(this, 'render_partials', '');
this.$el.html(Mustache.render(template, attrs, partials));
return this; return this;
} },
avatar_template: $('#avatar').html()
}); });
})(); })();

View file

@ -26,6 +26,6 @@
"options_page": "options.html", "options_page": "options.html",
"content_security_policy": "content_security_policy":
"default-src 'self'; img-src 'self' data:; connect-src https://textsecure-service-staging.whispersystems.org wss://textsecure-service-staging.whispersystems.org https://whispersystems-textsecure-attachments-staging.s3.amazonaws.com" "default-src 'self'; img-src 'self' data:; connect-src https://textsecure-service-staging.whispersystems.org wss://textsecure-service-staging.whispersystems.org https://whispersystems-textsecure-attachments-staging.s3.amazonaws.com; style-src 'self' 'unsafe-inline'"
} }

View file

@ -53,10 +53,6 @@
} }
} }
.avatar img {
vertical-align: middle;
}
.conflict { .conflict {
border: none; border: none;
border-radius: 5px; border-radius: 5px;
@ -240,11 +236,9 @@
display: none; display: none;
} }
.avatar img { .avatar {
height: 36px; height: 36px;
width: 36px; width: 36px;
background: $grey_l;
border-radius: (36px / 2);
} }
.meta { .meta {

View file

@ -161,6 +161,16 @@ img.emoji {
vertical-align: -0.1em; vertical-align: -0.1em;
} }
.avatar {
display: inline-block;
height: 44px;
width: 44px;
background: $grey_l url('/images/default.png') no-repeat center;
border-radius: 50%;
background-size: cover;
vertical-align: middle;
}
.new-group-update-form { .new-group-update-form {
background: white; background: white;
@ -241,13 +251,6 @@ img.emoji {
} }
} }
.avatar img {
height: 44px;
width: 44px;
background: $grey_l;
border-radius: (44px / 2);
}
.contact-details { .contact-details {
vertical-align: top; vertical-align: top;
display: inline-block; display: inline-block;

View file

@ -144,6 +144,15 @@ img.emoji {
margin: 0 .05em 0 .1em; margin: 0 .05em 0 .1em;
vertical-align: -0.1em; } vertical-align: -0.1em; }
.avatar {
display: inline-block;
height: 44px;
width: 44px;
background: #f3f3f3 url("/images/default.png") no-repeat center;
border-radius: 22px;
background-size: cover;
vertical-align: middle; }
.new-group-update-form { .new-group-update-form {
background: white; } background: white; }
.new-group-update-form .group-avatar { .new-group-update-form .group-avatar {
@ -201,11 +210,6 @@ img.emoji {
box-shadow: 0 1px 3px rgba(170, 170, 170, 0.8); } box-shadow: 0 1px 3px rgba(170, 170, 170, 0.8); }
.contact:last-child::after { .contact:last-child::after {
display: none; } display: none; }
.contact .avatar img {
height: 44px;
width: 44px;
background: #f3f3f3;
border-radius: 22px; }
.contact .contact-details { .contact .contact-details {
vertical-align: top; vertical-align: top;
display: inline-block; display: inline-block;
@ -383,8 +387,6 @@ input.search {
text-align: right; text-align: right;
font-weight: bold; font-weight: bold;
padding-right: 1em; } padding-right: 1em; }
.message-detail .avatar img {
vertical-align: middle; }
.message-detail .conflict { .message-detail .conflict {
border: none; border: none;
border-radius: 5px; border-radius: 5px;
@ -526,12 +528,10 @@ input.search {
.message-detail .outgoing .avatar, .message-detail .outgoing .avatar,
.message-list .outgoing .avatar { .message-list .outgoing .avatar {
display: none; } display: none; }
.message-detail .avatar img, .message-detail .avatar,
.message-list .avatar img { .message-list .avatar {
height: 36px; height: 36px;
width: 36px; width: 36px; }
background: #f3f3f3;
border-radius: 18px; }
.message-detail .meta, .message-detail .meta,
.message-list .meta { .message-list .meta {
margin-top: 3px; margin-top: 3px;