Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
1d352084
Commit
1d352084
authored
Feb 28, 2010
by
brandonaaron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use correct window reference in offset to work properly cross-frame. Fixes #6190.
parent
36faab43
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
6 deletions
+47
-6
offset.js
src/offset.js
+11
-4
offset.js
test/unit/offset.js
+36
-2
No files found.
src/offset.js
View file @
1d352084
...
@@ -16,10 +16,17 @@ if ( "getBoundingClientRect" in document.documentElement ) {
...
@@ -16,10 +16,17 @@ if ( "getBoundingClientRect" in document.documentElement ) {
return
jQuery
.
offset
.
bodyOffset
(
elem
);
return
jQuery
.
offset
.
bodyOffset
(
elem
);
}
}
var
box
=
elem
.
getBoundingClientRect
(),
doc
=
elem
.
ownerDocument
,
body
=
doc
.
body
,
docElem
=
doc
.
documentElement
,
var
box
=
elem
.
getBoundingClientRect
(),
clientTop
=
docElem
.
clientTop
||
body
.
clientTop
||
0
,
clientLeft
=
docElem
.
clientLeft
||
body
.
clientLeft
||
0
,
doc
=
elem
.
ownerDocument
,
top
=
box
.
top
+
(
self
.
pageYOffset
||
jQuery
.
support
.
boxModel
&&
docElem
.
scrollTop
||
body
.
scrollTop
)
-
clientTop
,
body
=
doc
.
body
,
left
=
box
.
left
+
(
self
.
pageXOffset
||
jQuery
.
support
.
boxModel
&&
docElem
.
scrollLeft
||
body
.
scrollLeft
)
-
clientLeft
;
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
};
return
{
top
:
top
,
left
:
left
};
};
};
...
...
test/unit/offset.js
View file @
1d352084
module
(
"offset"
);
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
)
{
testoffset
(
"absolute"
,
function
(
jQuery
)
{
expect
(
144
);
expect
(
144
);
...
@@ -306,8 +340,8 @@ testoffset("body", function( jQuery ) {
...
@@ -306,8 +340,8 @@ testoffset("body", function( jQuery ) {
});
});
test
(
"Chaining offset(coords) returns jQuery object"
,
function
()
{
test
(
"Chaining offset(coords) returns jQuery object"
,
function
()
{
expect
(
2
);
expect
(
2
);
var
coords
=
{
top
:
1
,
left
:
1
};
var
coords
=
{
top
:
1
,
left
:
1
};
equals
(
jQuery
(
"#absolute-1"
).
offset
(
coords
).
selector
,
"#absolute-1"
,
"offset(coords) returns jQuery object"
);
equals
(
jQuery
(
"#absolute-1"
).
offset
(
coords
).
selector
,
"#absolute-1"
,
"offset(coords) returns jQuery object"
);
equals
(
jQuery
(
"#non-existent"
).
offset
(
coords
).
selector
,
"#non-existent"
,
"offset(coords) with empty jQuery set returns jQuery object"
);
equals
(
jQuery
(
"#non-existent"
).
offset
(
coords
).
selector
,
"#non-existent"
,
"offset(coords) with empty jQuery set returns jQuery object"
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment