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

Commit

Permalink
Several shift/tip bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Craga89 committed Apr 14, 2011
1 parent 39d4933 commit 404f8be
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 70 deletions.
12 changes: 6 additions & 6 deletions dist/jquery.qtip.basic.js
Expand Up @@ -9,7 +9,7 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
* Date: Thu Apr 14 20:23:41 2011 +0100
* Date: Thu Apr 14 23:46:32 2011 +0100
*/

"use strict"; // Enable ECMAScript "strict" operation for this function. See more: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
Expand Down Expand Up @@ -1055,11 +1055,11 @@ function QTip(target, options, id, attr)
// Make sure this axis is enabled for reposition
if (!readjust.horizontal) { return 0; }

var viewportScroll = (viewport.offset.left || 0) + viewport.scrollLeft,
var viewportScroll = viewport.scrollLeft,
myWidth = my.x === 'left' ? elemWidth : my.x === 'right' ? -elemWidth : -elemWidth / 2,
atWidth = at.x === 'left' ? targetWidth : at.x === 'right' ? -targetWidth : -targetWidth / 2,
tipAdjust = tip && tip.precedance === 'x' ? options.style.tip.width : 0,
overflowLeft = viewportScroll - posLeft - tipAdjust,
overflowLeft = (viewport.offset.left || 0) + viewportScroll - posLeft - tipAdjust,
overflowRight = posLeft + elemWidth - viewport.width - viewportScroll + tipAdjust,
offset = myWidth - (my.precedance === 'x' || my.x === my.y ? atWidth : 0),
isCenter = my.x === 'center';
Expand All @@ -1082,18 +1082,18 @@ function QTip(target, options, id, attr)
}

// Make sure we haven't made things worse with the adjustment and return the adjusted difference
if(position.left < 0 && -position.left > overflowRight) { position.left = posLeft; }
if(position.left < viewportScroll && -position.left > overflowRight) { position.left = posLeft; }
return position.left - posLeft;
},
top: function(posTop) {
// Make sure this axis is enabled for reposition
if (!readjust.vertical) { return 0; }

var viewportScroll = (viewport.offset.top || 0) + viewport.scrollTop,
var viewportScroll = viewport.scrollTop,
myHeight = my.y === 'top' ? elemHeight : my.y === 'bottom' ? -elemHeight : -elemHeight / 2,
atHeight = at.y === 'top' ? targetHeight : at.y === 'bottom' ? -targetHeight : -targetHeight / 2,
tipAdjust = tip && tip.precedance === 'y' ? options.style.tip.height : 0,
overflowTop = viewportScroll - posTop - tipAdjust,
overflowTop = (viewport.offset.top || 0) + viewportScroll - posTop - tipAdjust,
overflowBottom = posTop + elemHeight - viewport.height - viewportScroll + tipAdjust,
offset = myHeight - (my.precedance === 'y' || my.x === my.y ? atHeight : 0),
isCenter = my.y === 'center';
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.qtip.css
Expand Up @@ -9,7 +9,7 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
* Date: Thu Apr 14 20:23:41 2011 +0100
* Date: Thu Apr 14 23:46:32 2011 +0100
*/

/* Fluid class for determining actual width in IE */
Expand Down
51 changes: 21 additions & 30 deletions dist/jquery.qtip.js
Expand Up @@ -9,7 +9,7 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
* Date: Thu Apr 14 20:23:41 2011 +0100
* Date: Thu Apr 14 23:46:32 2011 +0100
*/

"use strict"; // Enable ECMAScript "strict" operation for this function. See more: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
Expand Down Expand Up @@ -1055,11 +1055,11 @@ function QTip(target, options, id, attr)
// Make sure this axis is enabled for reposition
if (!readjust.horizontal) { return 0; }

var viewportScroll = (viewport.offset.left || 0) + viewport.scrollLeft,
var viewportScroll = viewport.scrollLeft,
myWidth = my.x === 'left' ? elemWidth : my.x === 'right' ? -elemWidth : -elemWidth / 2,
atWidth = at.x === 'left' ? targetWidth : at.x === 'right' ? -targetWidth : -targetWidth / 2,
tipAdjust = tip && tip.precedance === 'x' ? options.style.tip.width : 0,
overflowLeft = viewportScroll - posLeft - tipAdjust,
overflowLeft = (viewport.offset.left || 0) + viewportScroll - posLeft - tipAdjust,
overflowRight = posLeft + elemWidth - viewport.width - viewportScroll + tipAdjust,
offset = myWidth - (my.precedance === 'x' || my.x === my.y ? atWidth : 0),
isCenter = my.x === 'center';
Expand All @@ -1082,18 +1082,18 @@ function QTip(target, options, id, attr)
}

// Make sure we haven't made things worse with the adjustment and return the adjusted difference
if(position.left < 0 && -position.left > overflowRight) { position.left = posLeft; }
if(position.left < viewportScroll && -position.left > overflowRight) { position.left = posLeft; }
return position.left - posLeft;
},
top: function(posTop) {
// Make sure this axis is enabled for reposition
if (!readjust.vertical) { return 0; }

var viewportScroll = (viewport.offset.top || 0) + viewport.scrollTop,
var viewportScroll = viewport.scrollTop,
myHeight = my.y === 'top' ? elemHeight : my.y === 'bottom' ? -elemHeight : -elemHeight / 2,
atHeight = at.y === 'top' ? targetHeight : at.y === 'bottom' ? -targetHeight : -targetHeight / 2,
tipAdjust = tip && tip.precedance === 'y' ? options.style.tip.height : 0,
overflowTop = viewportScroll - posTop - tipAdjust,
overflowTop = (viewport.offset.top || 0) + viewportScroll - posTop - tipAdjust,
overflowBottom = posTop + elemHeight - viewport.height - viewportScroll + tipAdjust,
offset = myHeight - (my.precedance === 'y' || my.x === my.y ? atHeight : 0),
isCenter = my.y === 'center';
Expand Down Expand Up @@ -1956,7 +1956,7 @@ function Tip(qTip, command)
var newCorner = $.extend({}, self.corner),
adjusted = pos.adjusted,
shift = qTip.options.position.adjust.method.substr(0, 5) === 'shift',
adjust = { left: 0, top: 0 },
adjust = { left: 0, top: 0, shift: shift },
offset;

// Make sure our tip position isn't fixed e.g. doesn't adjust with adjust.screen
Expand All @@ -1976,7 +1976,7 @@ function Tip(qTip, command)
}

// No shifting took place if both offets are zero...
if(!adjust.left && !adjust.top) { shift = FALSE; }
if(!adjust.left && !adjust.top) { shift = adjust.shift = FALSE; }
}

// Adjustment type = Flip
Expand All @@ -2002,16 +2002,11 @@ function Tip(qTip, command)
offset.option = Math.max(0, opts.offset);

// Adjust position to accomodate tip dimensions
if((shift && adjust.top && !adjust.left) || !shift || !offset) {
pos.left -= offset.left.charAt ? offset.option : (offset.right ? -1 : 1) * offset.left;
}
if((shift && adjust.left && !adjust.top) || !shift || !offset) {
pos.top -= offset.top.charAt ? offset.option : (offset.bottom ? -1 : 1) * offset.top;
}

// Make sure we also adjust for tip offset in shift repositioning
if(shift && adjust.left && newCorner.precedance === 'y') { pos.left -= offset.option; }
else if(shift && adjust.top && newCorner.precedance === 'x') { pos.top -= offset.option; }
pos.left -= shift && adjust.left || offset.left.charAt ? offset.option : 0;
pos.left -= ((shift && adjust.top && !adjust.left) || !shift ? (offset.right ? -1 : 1) * offset.left : 0) || 0;

pos.top -= shift && adjust.top || offset.top.charAt ? offset.option : 0;
pos.top -= ((shift && adjust.left && !adjust.top) || !shift ? (offset.bottom ? -1 : 1) * offset.top : 0) || 0;

// Cache details
cache.left = adjusted.left; cache.top = adjusted.top;
Expand Down Expand Up @@ -2311,11 +2306,12 @@ function Tip(qTip, command)
},

// Tip positioning method
position: function(corner, offsets, set)
position: function(corner, adjust, set)
{
var tip = elems.tip,
position = {},
precedance, dimensions,corners;
userOffset = Math.max(0, opts.offset),
offsets, precedance, dimensions, corners;

// Return if tips are disabled or tip is not yet rendered
if(opts.corner === FALSE || !tip) { return FALSE; }
Expand All @@ -2329,15 +2325,12 @@ function Tip(qTip, command)

// Setup corners and offset array
corners = [ corner.x, corner.y ];
offsets = [
Math.max(0, opts.offset + (offsets ? offsets.left : 0)),
Math.max(0, opts.offset + (offsets ? offsets.top : 0))
];
offsets = [ adjust ? adjust.left : 0, adjust ? adjust.top : 0 ];
if(precedance === 'x') { corners.reverse(); offsets.reverse(); }

// Calculate tip position
$.each(corners, function(i, side) {
var d, b, br;
var b, br;

if(side === 'center') {
b = precedance === 'y' ? 'left' : 'top';
Expand All @@ -2347,12 +2340,10 @@ function Tip(qTip, command)
else {
b = borderWidth(corner, side, TRUE);
br = borderRadius(corner);
d = i && precedance === 'y' ? 'height' : 'width';

position[ side ] = Math.min(
tooltip[d]() - size[d] - border,
i ? borderWidth(corner, side) + (!i ? br : 0) : offsets[i] + (br > b ? br : 0)
);
position[ side ] = i ? borderWidth(corner, side) : adjust && adjust.shift ?
br > offsets[i] ? (br > b ? br : 0) : offsets[i] + userOffset :
offsets[i] + userOffset + (br > b ? br : 0);
}
});

Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.qtip.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/jquery.qtip.pack.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/core.js
Expand Up @@ -1013,11 +1013,11 @@ function QTip(target, options, id, attr)
// Make sure this axis is enabled for reposition
if (!readjust.horizontal) { return 0; }

var viewportScroll = (viewport.offset.left || 0) + viewport.scrollLeft,
var viewportScroll = viewport.scrollLeft,
myWidth = my.x === 'left' ? elemWidth : my.x === 'right' ? -elemWidth : -elemWidth / 2,
atWidth = at.x === 'left' ? targetWidth : at.x === 'right' ? -targetWidth : -targetWidth / 2,
tipAdjust = tip && tip.precedance === 'x' ? options.style.tip.width : 0,
overflowLeft = viewportScroll - posLeft - tipAdjust,
overflowLeft = (viewport.offset.left || 0) + viewportScroll - posLeft - tipAdjust,
overflowRight = posLeft + elemWidth - viewport.width - viewportScroll + tipAdjust,
offset = myWidth - (my.precedance === 'x' || my.x === my.y ? atWidth : 0),
isCenter = my.x === 'center';
Expand All @@ -1040,18 +1040,18 @@ function QTip(target, options, id, attr)
}

// Make sure we haven't made things worse with the adjustment and return the adjusted difference
if(position.left < 0 && -position.left > overflowRight) { position.left = posLeft; }
if(position.left < viewportScroll && -position.left > overflowRight) { position.left = posLeft; }
return position.left - posLeft;
},
top: function(posTop) {
// Make sure this axis is enabled for reposition
if (!readjust.vertical) { return 0; }

var viewportScroll = (viewport.offset.top || 0) + viewport.scrollTop,
var viewportScroll = viewport.scrollTop,
myHeight = my.y === 'top' ? elemHeight : my.y === 'bottom' ? -elemHeight : -elemHeight / 2,
atHeight = at.y === 'top' ? targetHeight : at.y === 'bottom' ? -targetHeight : -targetHeight / 2,
tipAdjust = tip && tip.precedance === 'y' ? options.style.tip.height : 0,
overflowTop = viewportScroll - posTop - tipAdjust,
overflowTop = (viewport.offset.top || 0) + viewportScroll - posTop - tipAdjust,
overflowBottom = posTop + elemHeight - viewport.height - viewportScroll + tipAdjust,
offset = myHeight - (my.precedance === 'y' || my.x === my.y ? atHeight : 0),
isCenter = my.y === 'center';
Expand Down
39 changes: 15 additions & 24 deletions src/tips.js
Expand Up @@ -82,7 +82,7 @@ function Tip(qTip, command)
var newCorner = $.extend({}, self.corner),
adjusted = pos.adjusted,
shift = qTip.options.position.adjust.method.substr(0, 5) === 'shift',
adjust = { left: 0, top: 0 },
adjust = { left: 0, top: 0, shift: shift },
offset;

// Make sure our tip position isn't fixed e.g. doesn't adjust with adjust.screen
Expand All @@ -102,7 +102,7 @@ function Tip(qTip, command)
}

// No shifting took place if both offets are zero...
if(!adjust.left && !adjust.top) { shift = FALSE; }
if(!adjust.left && !adjust.top) { shift = adjust.shift = FALSE; }
}

// Adjustment type = Flip
Expand All @@ -128,16 +128,11 @@ function Tip(qTip, command)
offset.option = Math.max(0, opts.offset);

// Adjust position to accomodate tip dimensions
if((shift && adjust.top && !adjust.left) || !shift || !offset) {
pos.left -= offset.left.charAt ? offset.option : (offset.right ? -1 : 1) * offset.left;
}
if((shift && adjust.left && !adjust.top) || !shift || !offset) {
pos.top -= offset.top.charAt ? offset.option : (offset.bottom ? -1 : 1) * offset.top;
}

// Make sure we also adjust for tip offset in shift repositioning
if(shift && adjust.left && newCorner.precedance === 'y') { pos.left -= offset.option; }
else if(shift && adjust.top && newCorner.precedance === 'x') { pos.top -= offset.option; }
pos.left -= shift && adjust.left || offset.left.charAt ? offset.option : 0;
pos.left -= ((shift && adjust.top && !adjust.left) || !shift ? (offset.right ? -1 : 1) * offset.left : 0) || 0;

pos.top -= shift && adjust.top || offset.top.charAt ? offset.option : 0;
pos.top -= ((shift && adjust.left && !adjust.top) || !shift ? (offset.bottom ? -1 : 1) * offset.top : 0) || 0;

// Cache details
cache.left = adjusted.left; cache.top = adjusted.top;
Expand Down Expand Up @@ -437,11 +432,12 @@ function Tip(qTip, command)
},

// Tip positioning method
position: function(corner, offsets, set)
position: function(corner, adjust, set)
{
var tip = elems.tip,
position = {},
precedance, dimensions,corners;
userOffset = Math.max(0, opts.offset),
offsets, precedance, dimensions, corners;

// Return if tips are disabled or tip is not yet rendered
if(opts.corner === FALSE || !tip) { return FALSE; }
Expand All @@ -455,15 +451,12 @@ function Tip(qTip, command)

// Setup corners and offset array
corners = [ corner.x, corner.y ];
offsets = [
Math.max(0, opts.offset + (offsets ? offsets.left : 0)),
Math.max(0, opts.offset + (offsets ? offsets.top : 0))
];
offsets = [ adjust ? adjust.left : 0, adjust ? adjust.top : 0 ];
if(precedance === 'x') { corners.reverse(); offsets.reverse(); }

// Calculate tip position
$.each(corners, function(i, side) {
var d, b, br;
var b, br;

if(side === 'center') {
b = precedance === 'y' ? 'left' : 'top';
Expand All @@ -473,12 +466,10 @@ function Tip(qTip, command)
else {
b = borderWidth(corner, side, TRUE);
br = borderRadius(corner);
d = i && precedance === 'y' ? 'height' : 'width';

position[ side ] = Math.min(
tooltip[d]() - size[d] - border,
i ? borderWidth(corner, side) + (!i ? br : 0) : offsets[i] + (br > b ? br : 0)
);
position[ side ] = i ? borderWidth(corner, side) : adjust && adjust.shift ?
br > offsets[i] ? (br > b ? br : 0) : offsets[i] + userOffset :
offsets[i] + userOffset + (br > b ? br : 0);
}
});

Expand Down

0 comments on commit 404f8be

Please sign in to comment.