Check if canvas is supported before trying to render the user avatar.

This commit is contained in:
JC Brand 2013-11-15 22:27:24 +02:00
parent 490d96fd26
commit 4a1eac06cb
2 changed files with 8 additions and 3 deletions

View File

@ -5,6 +5,7 @@ Changelog
------------------
* Don't load OTR crypto if the browser doesn't have a CSRNG [jcbrand]
* Check if canvas is supported before trying to render the user avatar [jcbrand]
0.7.0 (2013-11-13)
------------------

View File

@ -1207,9 +1207,13 @@
return;
}
var img_src = 'data:'+this.model.get('image_type')+';base64,'+this.model.get('image'),
canvas = $('<canvas height="33px" width="33px" class="avatar"></canvas>'),
ctx = canvas.get(0).getContext('2d'),
img = new Image(); // Create new Image object
canvas = $('<canvas height="33px" width="33px" class="avatar"></canvas>').get(0);
if (!(canvas.getContext && canvas.getContext('2d'))) {
return this;
}
var ctx = canvas.getContext('2d');
var img = new Image(); // Create new Image object
img.onload = function() {
var ratio = img.width/img.height;
ctx.drawImage(img, 0,0, 35*ratio, 35);