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

Commit

Permalink
Standardised the offset plugin and fixed bug with overflow containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Craga89 committed Feb 7, 2012
1 parent df63eaa commit f7b9f1f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 41 deletions.
21 changes: 8 additions & 13 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: Mon Feb 6 19:01:26 2012 +0000
* Date: Tue Feb 7 19:31:47 2012 +0000
*/

/*jslint browser: true, onevar: true, undef: true, nomen: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: true */
Expand Down Expand Up @@ -1783,9 +1783,8 @@ PLUGINS = QTIP.plugins = {
// Custom (more correct for qTip!) offset calculator
offset: function(elem, container) {
var pos = elem.offset(),
parent = container,
deep = 0,
docBody = document.body,
parent = container, scrolled,
coffset, overflow;

function scroll(e, i) {
Expand All @@ -1797,25 +1796,21 @@ PLUGINS = QTIP.plugins = {
// Compensate for non-static containers offset
do {
if(parent.css('position') !== 'static') {
coffset = parent[0] === docBody ?
{ left: parseInt(parent.css('left'), 10) || 0, top: parseInt(parent.css('top'), 10) || 0 } :
parent.position();
coffset = parent.position();

// Account for element positioning, borders and margins
pos.left -= coffset.left + (parseInt(parent.css('borderLeftWidth'), 10) || 0) + (parseInt(parent.css('marginLeft'), 10) || 0);
pos.top -= coffset.top + (parseInt(parent.css('borderTopWidth'), 10) || 0);
pos.top -= coffset.top + (parseInt(parent.css('borderTopWidth'), 10) || 0) + (parseInt(parent.css('marginTop'), 10) || 0);

overflow = parent.css('overflow');
if(overflow === 'scroll' || overflow === 'auto') {
scroll(parent, 1); deep++;
}
// If this is the first parent element with an overflow of "scroll" or "auto", store it
if(!scrolled && (overflow = parent.css('overflow')) !== 'hidden' && overflow !== 'visible') { scrolled = parent; }
}

if(parent[0] === docBody) { break; }
}
while(parent = parent.offsetParent());

// Compensate for containers scroll if it also has an offsetParent
if(container[0] !== docBody && deep) { scroll( container, 1 ); }
if(scrolled && scrolled[0] !== docBody) { scroll( scrolled, 1 ); }
}

return pos;
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: Mon Feb 6 19:01:26 2012 +0000
* Date: Tue Feb 7 19:31:47 2012 +0000
*/

/* Core qTip styles */
Expand Down
21 changes: 8 additions & 13 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: Mon Feb 6 19:01:26 2012 +0000
* Date: Tue Feb 7 19:31:47 2012 +0000
*/

/*jslint browser: true, onevar: true, undef: true, nomen: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: true */
Expand Down Expand Up @@ -1783,9 +1783,8 @@ PLUGINS = QTIP.plugins = {
// Custom (more correct for qTip!) offset calculator
offset: function(elem, container) {
var pos = elem.offset(),
parent = container,
deep = 0,
docBody = document.body,
parent = container, scrolled,
coffset, overflow;

function scroll(e, i) {
Expand All @@ -1797,25 +1796,21 @@ PLUGINS = QTIP.plugins = {
// Compensate for non-static containers offset
do {
if(parent.css('position') !== 'static') {
coffset = parent[0] === docBody ?
{ left: parseInt(parent.css('left'), 10) || 0, top: parseInt(parent.css('top'), 10) || 0 } :
parent.position();
coffset = parent.position();

// Account for element positioning, borders and margins
pos.left -= coffset.left + (parseInt(parent.css('borderLeftWidth'), 10) || 0) + (parseInt(parent.css('marginLeft'), 10) || 0);
pos.top -= coffset.top + (parseInt(parent.css('borderTopWidth'), 10) || 0);
pos.top -= coffset.top + (parseInt(parent.css('borderTopWidth'), 10) || 0) + (parseInt(parent.css('marginTop'), 10) || 0);

overflow = parent.css('overflow');
if(overflow === 'scroll' || overflow === 'auto') {
scroll(parent, 1); deep++;
}
// If this is the first parent element with an overflow of "scroll" or "auto", store it
if(!scrolled && (overflow = parent.css('overflow')) !== 'hidden' && overflow !== 'visible') { scrolled = parent; }
}

if(parent[0] === docBody) { break; }
}
while(parent = parent.offsetParent());

// Compensate for containers scroll if it also has an offsetParent
if(container[0] !== docBody && deep) { scroll( container, 1 ); }
if(scrolled && scrolled[0] !== docBody) { scroll( scrolled, 1 ); }
}

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

Large diffs are not rendered by default.

19 changes: 7 additions & 12 deletions src/core.js
Expand Up @@ -1720,9 +1720,8 @@ PLUGINS = QTIP.plugins = {
// Custom (more correct for qTip!) offset calculator
offset: function(elem, container) {
var pos = elem.offset(),
parent = container,
deep = 0,
docBody = document.body,
parent = container, scrolled,
coffset, overflow;

function scroll(e, i) {
Expand All @@ -1734,25 +1733,21 @@ PLUGINS = QTIP.plugins = {
// Compensate for non-static containers offset
do {
if(parent.css('position') !== 'static') {
coffset = parent[0] === docBody ?
{ left: parseInt(parent.css('left'), 10) || 0, top: parseInt(parent.css('top'), 10) || 0 } :
parent.position();
coffset = parent.position();

// Account for element positioning, borders and margins
pos.left -= coffset.left + (parseInt(parent.css('borderLeftWidth'), 10) || 0) + (parseInt(parent.css('marginLeft'), 10) || 0);
pos.top -= coffset.top + (parseInt(parent.css('borderTopWidth'), 10) || 0);
pos.top -= coffset.top + (parseInt(parent.css('borderTopWidth'), 10) || 0) + (parseInt(parent.css('marginTop'), 10) || 0);

overflow = parent.css('overflow');
if(overflow === 'scroll' || overflow === 'auto') {
scroll(parent, 1); deep++;
}
// If this is the first parent element with an overflow of "scroll" or "auto", store it
if(!scrolled && (overflow = parent.css('overflow')) !== 'hidden' && overflow !== 'visible') { scrolled = parent; }
}

if(parent[0] === docBody) { break; }
}
while(parent = parent.offsetParent());

// Compensate for containers scroll if it also has an offsetParent
if(container[0] !== docBody && deep) { scroll( container, 1 ); }
if(scrolled && scrolled[0] !== docBody) { scroll( scrolled, 1 ); }
}

return pos;
Expand Down

0 comments on commit f7b9f1f

Please sign in to comment.