mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Use correct window reference in offset to work properly cross-frame. Fixes #6190.
This commit is contained in:
parent
36faab439a
commit
1d352084c4
@ -16,10 +16,17 @@ if ( "getBoundingClientRect" in document.documentElement ) {
|
||||
return jQuery.offset.bodyOffset( elem );
|
||||
}
|
||||
|
||||
var box = elem.getBoundingClientRect(), doc = elem.ownerDocument, body = doc.body, docElem = doc.documentElement,
|
||||
clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
|
||||
top = box.top + (self.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop ) - clientTop,
|
||||
left = box.left + (self.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft) - clientLeft;
|
||||
var box = elem.getBoundingClientRect(),
|
||||
doc = elem.ownerDocument,
|
||||
body = doc.body,
|
||||
docElem = doc.documentElement,
|
||||
win = getWindow(doc),
|
||||
clientTop = docElem.clientTop || body.clientTop || 0,
|
||||
clientLeft = docElem.clientLeft || body.clientLeft || 0,
|
||||
scrollTop = (win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop ),
|
||||
scrollLeft = (win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft),
|
||||
top = box.top + scrollTop - clientTop,
|
||||
left = box.left + scrollLeft - clientLeft;
|
||||
|
||||
return { top: top, left: left };
|
||||
};
|
||||
|
@ -1,5 +1,39 @@
|
||||
module("offset");
|
||||
|
||||
testoffset("absolute"/* in iframe */, function($, iframe) {
|
||||
expect(4);
|
||||
|
||||
var doc = iframe.document, tests;
|
||||
|
||||
// force a scroll value on the main window
|
||||
// this insures that the results will be wrong
|
||||
// if the offset method is using the scroll offset
|
||||
// of the parent window
|
||||
var forceScroll = jQuery('<div>', { width: 2000, height: 2000 }).appendTo('body');
|
||||
window.scrollTo(1, 1);
|
||||
|
||||
// get offset
|
||||
tests = [
|
||||
{ id: '#absolute-1', top: 1, left: 1 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
equals( jQuery( this.id, doc ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
|
||||
equals( jQuery( this.id, doc ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" );
|
||||
});
|
||||
|
||||
|
||||
// get position
|
||||
tests = [
|
||||
{ id: '#absolute-1', top: 0, left: 0 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
equals( jQuery( this.id, doc ).position().top, this.top, "jQuery('" + this.id + "').position().top" );
|
||||
equals( jQuery( this.id, doc ).position().left, this.left, "jQuery('" + this.id + "').position().left" );
|
||||
});
|
||||
|
||||
forceScroll.remove();
|
||||
});
|
||||
|
||||
testoffset("absolute", function( jQuery ) {
|
||||
expect(144);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user