Commit 862af642 authored by JC Brand's avatar JC Brand

Move avatar markup to a template and make size configurable

parent fe37b4e5
...@@ -124,6 +124,7 @@ require.config({ ...@@ -124,6 +124,7 @@ require.config({
"action": "src/templates/action", "action": "src/templates/action",
"add_contact_dropdown": "src/templates/add_contact_dropdown", "add_contact_dropdown": "src/templates/add_contact_dropdown",
"add_contact_form": "src/templates/add_contact_form", "add_contact_form": "src/templates/add_contact_form",
"avatar": "src/templates/avatar",
"bookmark": "src/templates/bookmark", "bookmark": "src/templates/bookmark",
"bookmarks_list": "src/templates/bookmarks_list", "bookmarks_list": "src/templates/bookmarks_list",
"change_status_message": "src/templates/change_status_message", "change_status_message": "src/templates/change_status_message",
......
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
"tpl!new_day", "tpl!new_day",
"tpl!action", "tpl!action",
"tpl!message", "tpl!message",
"tpl!toolbar" "tpl!toolbar",
"tpl!avatar"
], factory); ], factory);
}(this, function ( }(this, function (
converse, converse,
...@@ -23,7 +24,8 @@ ...@@ -23,7 +24,8 @@
tpl_new_day, tpl_new_day,
tpl_action, tpl_action,
tpl_message, tpl_message,
tpl_toolbar tpl_toolbar,
tpl_avatar
) { ) {
"use strict"; "use strict";
converse.templates.chatbox = tpl_chatbox; converse.templates.chatbox = tpl_chatbox;
...@@ -31,6 +33,7 @@ ...@@ -31,6 +33,7 @@
converse.templates.action = tpl_action; converse.templates.action = tpl_action;
converse.templates.message = tpl_message; converse.templates.message = tpl_message;
converse.templates.toolbar = tpl_toolbar; converse.templates.toolbar = tpl_toolbar;
converse.templates.avatar = tpl_avatar;
var $ = converse_api.env.jQuery, var $ = converse_api.env.jQuery,
utils = converse_api.env.utils, utils = converse_api.env.utils,
...@@ -76,6 +79,8 @@ ...@@ -76,6 +79,8 @@
*/ */
this.updateSettings({ this.updateSettings({
show_toolbar: true, show_toolbar: true,
chatview_avatar_width: 32,
chatview_avatar_height: 32,
}); });
converse.ChatBoxView = Backbone.View.extend({ converse.ChatBoxView = Backbone.View.extend({
...@@ -680,8 +685,13 @@ ...@@ -680,8 +685,13 @@
if (!this.model.get('image')) { if (!this.model.get('image')) {
return; return;
} }
var width = converse.chatview_avatar_width;
var height = converse.chatview_avatar_height;
var img_src = 'data:'+this.model.get('image_type')+';base64,'+this.model.get('image'), var img_src = 'data:'+this.model.get('image_type')+';base64,'+this.model.get('image'),
canvas = $('<canvas height="32px" width="32px" class="avatar"></canvas>').get(0); canvas = $(converse.templates.avatar({
'width': width,
'height': height
})).get(0);
if (!(canvas.getContext && canvas.getContext('2d'))) { if (!(canvas.getContext && canvas.getContext('2d'))) {
return this; return this;
...@@ -691,9 +701,9 @@ ...@@ -691,9 +701,9 @@
img.onload = function () { img.onload = function () {
var ratio = img.width/img.height; var ratio = img.width/img.height;
if (ratio < 1) { if (ratio < 1) {
ctx.drawImage(img, 0,0, 32, 32*(1/ratio)); ctx.drawImage(img, 0,0, width, height*(1/ratio));
} else { } else {
ctx.drawImage(img, 0,0, 32, 32*ratio); ctx.drawImage(img, 0,0, width, height*ratio);
} }
}; };
......
<canvas height="32px" width="32px" class="avatar"></canvas>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment