From bc1fda388e9df7d7217f093100ef4080c6275159 Mon Sep 17 00:00:00 2001 From: Vlad Chernushevich Date: Fri, 28 Jun 2013 16:38:18 +0200 Subject: [PATCH] Adjust letter-spacing depending on OS. More comments. --- client/assets/src/views/favicon.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/client/assets/src/views/favicon.js b/client/assets/src/views/favicon.js index bbda5a0..7fce7ce 100644 --- a/client/assets/src/views/favicon.js +++ b/client/assets/src/views/favicon.js @@ -3,12 +3,15 @@ _kiwi.view.Favicon = Backbone.View.extend({ var that = this, $win = $(window); - this.has_canvas_support = !!window.CanvasRenderingContext2D; this.has_focus = true; this.highlight_count = 0; + // Check for html5 canvas support + this.has_canvas_support = !!window.CanvasRenderingContext2D; + // Store the original favicon this.original_favicon = $('link[rel~="icon"]')[0].href; + // Reset favicon notifications when user focuses window $win.on('focus', function () { that.has_focus = true; that._resetHighlights(); @@ -48,6 +51,7 @@ _kiwi.view.Favicon = Backbone.View.extend({ favicon_image.src = this.original_favicon; favicon_image.onload = function() { + // Clear canvas from prevous iteration context.clearRect(0, 0, canvas.width, canvas.height); // Draw the favicon itself context.drawImage(favicon_image, 0, 0, favicon_image.width, favicon_image.height); @@ -56,12 +60,20 @@ _kiwi.view.Favicon = Backbone.View.extend({ }, _drawBubble: function (label, canvas) { - var letter_spacing = -1.5, + var letter_spacing, bubble_width = 0, bubble_height = 0, context = test = canvas.getContext('2d'), canvas_width = canvas.width, canvas_height = canvas.height; + // Different letter spacing for MacOS + if (navigator.appVersion.indexOf("Mac") !== -1) { + letter_spacing = -1.5; + } + else { + letter_spacing = -1; + } + // Setup a test canvas to get text width test.font = context.font = 'bold 10px Arial'; test.textAlign = 'right'; @@ -93,6 +105,7 @@ _kiwi.view.Favicon = Backbone.View.extend({ }, _getCanvas: function () { + // Check if canvas exists if (!this.canvas) { canvas = document.createElement('canvas'); canvas.width = 16; -- 2.25.1