Simplify avatar rendering
This commit is contained in:
parent
fa3699cdd3
commit
cecb438a52
6 changed files with 20 additions and 41 deletions
|
@ -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'></span>
|
<span class='avatar'><img src='{{ avatar_url }}' /></span>
|
||||||
<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'></span>
|
<span class='default avatar'><img src='{{ avatar_url }}' /></span>
|
||||||
</div>
|
</div>
|
||||||
<input type='file' name='avatar' class='file-input'>
|
<input type='file' name='avatar' class='file-input'>
|
||||||
</div>
|
</div>
|
||||||
|
@ -89,7 +89,7 @@
|
||||||
<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'></span>
|
<span class='avatar'><img src='{{ avatar_url }}' /></span>
|
||||||
<div class='contact-details'>
|
<div class='contact-details'>
|
||||||
<h3 class='contact-name'>
|
<h3 class='contact-name'>
|
||||||
{{ contact_name }}
|
{{ contact_name }}
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
<div class='contacts'>
|
<div class='contacts'>
|
||||||
{{ #contacts }}
|
{{ #contacts }}
|
||||||
<div>
|
<div>
|
||||||
<img class='avatar' src='{{ avatar }}'>
|
<span class='avatar'><img src='{{ avatar_url }}' /></span>
|
||||||
<span class='name'>{{ name }}</div>
|
<span class='name'>{{ name }}</div>
|
||||||
{{ #conflict }}
|
{{ #conflict }}
|
||||||
<button class='resolve'>Key Conflict</button>
|
<button class='resolve'>Key Conflict</button>
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
this.on('change:avatar', this.updateAvatarUrl);
|
this.on('change:avatar', this.updateAvatarUrl);
|
||||||
|
this.on('destroy', this.revokeAvatarUrl);
|
||||||
},
|
},
|
||||||
|
|
||||||
validate: function(attributes, options) {
|
validate: function(attributes, options) {
|
||||||
|
@ -194,11 +195,15 @@
|
||||||
return this.get('type') === 'private';
|
return this.get('type') === 'private';
|
||||||
},
|
},
|
||||||
|
|
||||||
updateAvatarUrl: function() {
|
revokeAvatarUrl: function() {
|
||||||
if (this.avatarUrl) {
|
if (this.avatarUrl) {
|
||||||
URL.revokeObjectURL(this.avatarUrl);
|
URL.revokeObjectURL(this.avatarUrl);
|
||||||
this.avatarUrl = null;
|
this.avatarUrl = null;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updateAvatarUrl: function() {
|
||||||
|
this.revokeAvatarUrl();
|
||||||
var avatar = this.get('avatar');
|
var avatar = this.get('avatar');
|
||||||
if (avatar) {
|
if (avatar) {
|
||||||
this.avatarUrl = URL.createObjectURL(
|
this.avatarUrl = URL.createObjectURL(
|
||||||
|
|
|
@ -44,7 +44,8 @@
|
||||||
contact_name: this.model.getTitle(),
|
contact_name: this.model.getTitle(),
|
||||||
last_message: this.model.get('lastMessage'),
|
last_message: this.model.get('lastMessage'),
|
||||||
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()
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -57,17 +58,6 @@
|
||||||
this.$el.removeClass('unread');
|
this.$el.removeClass('unread');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.model.get('avatar')) {
|
|
||||||
this.$el.find('.avatar').append(
|
|
||||||
new Whisper.AttachmentView({model: this.model.get('avatar')}).render().el
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.$el.find('.avatar').append(
|
|
||||||
$('<img>').attr('src', '/images/default.png')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
contacts: this.contacts().map(function(contact) {
|
contacts: this.contacts().map(function(contact) {
|
||||||
return {
|
return {
|
||||||
name : contact.getTitle(),
|
name : contact.getTitle(),
|
||||||
avatar : contact.get('avatar'),
|
avatar_url : contact.getAvatarUrl()
|
||||||
};
|
};
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -53,21 +53,11 @@
|
||||||
Mustache.render(this.template, {
|
Mustache.render(this.template, {
|
||||||
message: this.model.get('body'),
|
message: this.model.get('body'),
|
||||||
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())
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
var avatar;
|
|
||||||
if (contact && contact.get('avatar')) {
|
|
||||||
avatar = new Whisper.AttachmentView({
|
|
||||||
model: contact.get('avatar')
|
|
||||||
}).render().el;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
avatar = $('<img>').attr('src', '/images/default.png');
|
|
||||||
}
|
|
||||||
this.$el.find('.avatar').append(avatar);
|
|
||||||
|
|
||||||
twemoji.parse(this.el, { base: '/components/twemoji/', size: 16 });
|
twemoji.parse(this.el, { base: '/components/twemoji/', size: 16 });
|
||||||
|
|
||||||
var content = this.$el.find('.content');
|
var content = this.$el.find('.content');
|
||||||
|
|
|
@ -27,15 +27,6 @@
|
||||||
el: this.$el.find('.group-avatar')
|
el: this.$el.find('.group-avatar')
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.model.attributes.avatar) {
|
|
||||||
this.current_avatar = new Whisper.AttachmentView({
|
|
||||||
model: this.model.attributes.avatar
|
|
||||||
});
|
|
||||||
this.avatarInput.$default.append(
|
|
||||||
this.current_avatar.render().$el
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
},
|
},
|
||||||
|
@ -47,7 +38,10 @@
|
||||||
this.trigger('back');
|
this.trigger('back');
|
||||||
},
|
},
|
||||||
render_attributes: function() {
|
render_attributes: function() {
|
||||||
return { name: this.model.getTitle() };
|
return {
|
||||||
|
name: this.model.getTitle(),
|
||||||
|
avatar_url: this.model.getAvatarUrl()
|
||||||
|
};
|
||||||
},
|
},
|
||||||
send: function() {
|
send: function() {
|
||||||
return this.avatarInput.getFiles().then(function(avatarFiles) {
|
return this.avatarInput.getFiles().then(function(avatarFiles) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue