Skip to content
This repository has been archived by the owner on Jun 14, 2020. It is now read-only.

Commit

Permalink
Fixed problem with tips plugin when no border was specified. Also res…
Browse files Browse the repository at this point in the history
…et tip defaults.

Tip width/height defaults set back to 14(px) and border width set to 0.

Also optimized tips plugin to make sure properties weren't set on <canvas> elements when not needed
i.e. when border width was set to zero. This also fixed the rendering problem when no border width was specified.
  • Loading branch information
Craga89 committed Jul 15, 2010
1 parent 08e0d4a commit 8ee1716
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/tips.js
Expand Up @@ -320,29 +320,35 @@ function Tip(qTip, command)
switch(self.method)
{
case 'canvas':
// Determine tip coordinates based on dimensions
coords = calculateTip(mimic.string(), width * 2, height * 2);

// Setup canvas properties
// Grab canvas context
context = inner.get(0).getContext('2d');
context.fillStyle = color.fill;
context.miterLimit = 0;
context.clearRect(0,0,3000,3000);
context.translate(
mimic.x === 'left' ? 0 : mimic.x === 'right' ? -width : -width / 2,
mimic.y === 'top' ? 0 : mimic.y === 'bottom' ? -height : -height / 2
);


// Determine tip coordinates based on dimensions
if(self.border) {
coords = calculateTip(mimic.string(), width * 2, height * 2);

// Setup additional border properties
context.strokeStyle = color.border;
context.lineWidth = self.border + 1;
context.lineJoin = 'miter';
context.miterLimit = 100;
context.translate(
mimic.x === 'left' ? 0 : mimic.x === 'right' ? -width : -width / 2,
mimic.y === 'top' ? 0 : mimic.y === 'bottom' ? -height : -height / 2
);
}
else {
coords = calculateTip(mimic.string(), width, height);
}

// Setup canvas properties
context.fillStyle = color.fill;
context.miterLimit = 0;
context.clearRect(0,0,3000,3000);

// Draw the canvas tip (Delayed til after DOM creation)
for(i; i < 2; i++) {
context.globalCompositeOperation = i ? 'destination-in' : 'source-over';
context.globalCompositeOperation = i && self.border ? 'destination-in' : 'source-over';
context.beginPath();
context.moveTo(coords[0][0], coords[0][1]);
context.lineTo(coords[1][0], coords[1][1]);
Expand Down Expand Up @@ -479,9 +485,9 @@ $.fn.qtip.plugins.tip.sanitize = function(opts)
if(typeof opts.style.tip !== 'object'){ opts.style.tip = { corner: opts.style.tip }; }
if(typeof opts.style.tip.method !== 'string'){ opts.style.tip.method = TRUE; }
if(!(/canvas|polygon/i).test(opts.style.tip.method)){ opts.style.tip.method = TRUE; }
if(typeof opts.style.tip.width !== 'number'){ opts.style.tip.width = 30; }
if(typeof opts.style.tip.height !== 'number'){ opts.style.tip.height = 30; }
if(typeof opts.style.tip.border !== 'number'){ opts.style.tip.border = 8; }
if(typeof opts.style.tip.width !== 'number'){ opts.style.tip.width = 14; }
if(typeof opts.style.tip.height !== 'number'){ opts.style.tip.height = 14; }
if(typeof opts.style.tip.border !== 'number'){ opts.style.tip.border = 0; }
}
};

0 comments on commit 8ee1716

Please sign in to comment.