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
77536f5c
Commit
77536f5c
authored
Apr 06, 2012
by
Mike Sherov
Committed by
Dave Methvin
Apr 06, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #10996, simplify offset code by forsaking ancient browsers.
parent
91a6d9da
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
111 deletions
+14
-111
jshint-check.js
build/jshint-check.js
+2
-1
offset.js
src/offset.js
+7
-50
support.js
src/support.js
+5
-36
support.js
test/unit/support.js
+0
-24
No files found.
build/jshint-check.js
View file @
77536f5c
...
@@ -12,7 +12,8 @@
...
@@ -12,7 +12,8 @@
smarttabs
:
true
,
smarttabs
:
true
,
predef
:
[
predef
:
[
"define"
,
"define"
,
"DOMParser"
"DOMParser"
,
"WebKitPoint"
],
],
maxerr
:
100
maxerr
:
100
};
};
...
...
src/offset.js
View file @
77536f5c
(
function
(
jQuery
)
{
(
function
(
jQuery
)
{
var
getOffset
,
var
getOffset
,
rtable
=
/^t
(?:
able|d|h
)
$/i
,
rroot
=
/^
(?:
body|html
)
$/i
;
rroot
=
/^
(?:
body|html
)
$/i
;
if
(
"getBoundingClientRect"
in
document
.
documentElement
)
{
if
(
"getBoundingClientRect"
in
document
.
documentElement
)
{
getOffset
=
function
(
elem
,
doc
,
docElem
,
box
)
{
getOffset
=
function
(
elem
,
doc
,
docElem
)
{
var
box
;
try
{
try
{
box
=
elem
.
getBoundingClientRect
();
box
=
elem
.
getBoundingClientRect
();
}
catch
(
e
)
{}
}
catch
(
e
)
{}
...
@@ -29,56 +30,12 @@ if ( "getBoundingClientRect" in document.documentElement ) {
...
@@ -29,56 +30,12 @@ if ( "getBoundingClientRect" in document.documentElement ) {
}
else
{
}
else
{
getOffset
=
function
(
elem
,
doc
,
docElem
)
{
getOffset
=
function
(
elem
,
doc
,
docElem
)
{
var
computedStyle
,
if
(
!
jQuery
.
contains
(
docElem
,
elem
)
)
{
offsetParent
=
elem
.
offsetParent
,
return
{
top
:
0
,
left
:
0
};
prevOffsetParent
=
elem
,
body
=
doc
.
body
,
defaultView
=
doc
.
defaultView
,
prevComputedStyle
=
defaultView
?
defaultView
.
getComputedStyle
(
elem
,
null
)
:
elem
.
currentStyle
,
top
=
elem
.
offsetTop
,
left
=
elem
.
offsetLeft
;
while
(
(
elem
=
elem
.
parentNode
)
&&
elem
!==
body
&&
elem
!==
docElem
)
{
if
(
jQuery
.
support
.
fixedPosition
&&
prevComputedStyle
.
position
===
"fixed"
)
{
break
;
}
computedStyle
=
defaultView
?
defaultView
.
getComputedStyle
(
elem
,
null
)
:
elem
.
currentStyle
;
top
-=
elem
.
scrollTop
;
left
-=
elem
.
scrollLeft
;
if
(
elem
===
offsetParent
)
{
top
+=
elem
.
offsetTop
;
left
+=
elem
.
offsetLeft
;
if
(
jQuery
.
support
.
doesNotAddBorder
&&
!
(
jQuery
.
support
.
doesAddBorderForTableAndCells
&&
rtable
.
test
(
elem
.
nodeName
))
)
{
top
+=
parseFloat
(
computedStyle
.
borderTopWidth
)
||
0
;
left
+=
parseFloat
(
computedStyle
.
borderLeftWidth
)
||
0
;
}
prevOffsetParent
=
offsetParent
;
offsetParent
=
elem
.
offsetParent
;
}
}
var
point
=
getWindow
(
doc
).
webkitConvertPointFromNodeToPage
(
elem
,
new
WebKitPoint
(
0
,
0
)
);
return
{
top
:
point
.
y
,
left
:
point
.
x
};
if
(
jQuery
.
support
.
subtractsBorderForOverflowNotVisible
&&
computedStyle
.
overflow
!==
"visible"
)
{
top
+=
parseFloat
(
computedStyle
.
borderTopWidth
)
||
0
;
left
+=
parseFloat
(
computedStyle
.
borderLeftWidth
)
||
0
;
}
prevComputedStyle
=
computedStyle
;
}
if
(
prevComputedStyle
.
position
===
"relative"
||
prevComputedStyle
.
position
===
"static"
)
{
top
+=
body
.
offsetTop
;
left
+=
body
.
offsetLeft
;
}
if
(
jQuery
.
support
.
fixedPosition
&&
prevComputedStyle
.
position
===
"fixed"
)
{
top
+=
Math
.
max
(
docElem
.
scrollTop
,
body
.
scrollTop
);
left
+=
Math
.
max
(
docElem
.
scrollLeft
,
body
.
scrollLeft
);
}
return
{
top
:
top
,
left
:
left
};
};
};
}
}
...
...
src/support.js
View file @
77536f5c
...
@@ -178,9 +178,8 @@ jQuery.support = (function() {
...
@@ -178,9 +178,8 @@ jQuery.support = (function() {
// Run tests that need a body at doc ready
// Run tests that need a body at doc ready
jQuery
(
function
()
{
jQuery
(
function
()
{
var
container
,
outer
,
inner
,
table
,
td
,
offsetSupport
,
var
container
,
offsetSupport
,
marginDiv
,
marginDiv
,
conMarginTop
,
style
,
html
,
positionTopLeftWidthHeight
,
conMarginTop
=
1
,
paddingMarginBorderVisibility
,
paddingMarginBorder
,
body
=
document
.
getElementsByTagName
(
"body"
)[
0
];
body
=
document
.
getElementsByTagName
(
"body"
)[
0
];
if
(
!
body
)
{
if
(
!
body
)
{
...
@@ -188,17 +187,8 @@ jQuery.support = (function() {
...
@@ -188,17 +187,8 @@ jQuery.support = (function() {
return
;
return
;
}
}
conMarginTop
=
1
;
paddingMarginBorder
=
"padding:0;margin:0;border:"
;
positionTopLeftWidthHeight
=
"position:absolute;top:0;left:0;width:1px;height:1px;"
;
paddingMarginBorderVisibility
=
paddingMarginBorder
+
"0;visibility:hidden;"
;
style
=
"style='"
+
positionTopLeftWidthHeight
+
paddingMarginBorder
+
"5px solid #000;"
;
html
=
"<div "
+
style
+
"display:block;'><div style='"
+
paddingMarginBorder
+
"0;display:block;overflow:hidden;'></div></div>"
+
"<table "
+
style
+
"' cellpadding='0' cellspacing='0'>"
+
"<tr><td></td></tr></table>"
;
container
=
document
.
createElement
(
"div"
);
container
=
document
.
createElement
(
"div"
);
container
.
style
.
cssText
=
paddingMarginBorderVisibility
+
"
width:0;height:0;position:static;top:0;margin-top:"
+
conMarginTop
+
"px"
;
container
.
style
.
cssText
=
"visibility:hidden;border:0;
width:0;height:0;position:static;top:0;margin-top:"
+
conMarginTop
+
"px"
;
body
.
insertBefore
(
container
,
body
.
firstChild
);
body
.
insertBefore
(
container
,
body
.
firstChild
);
// Construct the test element
// Construct the test element
...
@@ -212,7 +202,7 @@ jQuery.support = (function() {
...
@@ -212,7 +202,7 @@ jQuery.support = (function() {
// display:none (it is still safe to use offsets if a parent element is
// display:none (it is still safe to use offsets if a parent element is
// hidden; don safety goggles and see bug #4512 for more information).
// hidden; don safety goggles and see bug #4512 for more information).
// (only IE 8 fails this test)
// (only IE 8 fails this test)
div
.
innerHTML
=
"<table><tr><td style='
"
+
paddingMarginBorder
+
"
0;display:none'></td><td>t</td></tr></table>"
;
div
.
innerHTML
=
"<table><tr><td style='
padding:0;margin:0;border:
0;display:none'></td><td>t</td></tr></table>"
;
tds
=
div
.
getElementsByTagName
(
"td"
);
tds
=
div
.
getElementsByTagName
(
"td"
);
isSupported
=
(
tds
[
0
].
offsetHeight
===
0
);
isSupported
=
(
tds
[
0
].
offsetHeight
===
0
);
...
@@ -260,31 +250,10 @@ jQuery.support = (function() {
...
@@ -260,31 +250,10 @@ jQuery.support = (function() {
support
.
shrinkWrapBlocks
=
(
div
.
offsetWidth
!==
3
);
support
.
shrinkWrapBlocks
=
(
div
.
offsetWidth
!==
3
);
}
}
div
.
style
.
cssText
=
positionTopLeftWidthHeight
+
paddingMarginBorderVisibility
;
div
.
innerHTML
=
html
;
outer
=
div
.
firstChild
;
inner
=
outer
.
firstChild
;
td
=
outer
.
nextSibling
.
firstChild
.
firstChild
;
offsetSupport
=
{
offsetSupport
=
{
doesNotAddBorder
:
(
inner
.
offsetTop
!==
5
),
doesNotIncludeMarginInBodyOffset
:
(
body
.
offsetTop
!==
conMarginTop
)
doesAddBorderForTableAndCells
:
(
td
.
offsetTop
===
5
)
};
};
inner
.
style
.
position
=
"fixed"
;
inner
.
style
.
top
=
"20px"
;
// safari subtracts parent border width here which is 5px
offsetSupport
.
fixedPosition
=
(
inner
.
offsetTop
===
20
||
inner
.
offsetTop
===
15
);
inner
.
style
.
position
=
inner
.
style
.
top
=
""
;
outer
.
style
.
overflow
=
"hidden"
;
outer
.
style
.
position
=
"relative"
;
offsetSupport
.
subtractsBorderForOverflowNotVisible
=
(
inner
.
offsetTop
===
-
5
);
offsetSupport
.
doesNotIncludeMarginInBodyOffset
=
(
body
.
offsetTop
!==
conMarginTop
);
if
(
window
.
getComputedStyle
)
{
if
(
window
.
getComputedStyle
)
{
div
.
style
.
marginTop
=
"1%"
;
div
.
style
.
marginTop
=
"1%"
;
support
.
pixelMargin
=
(
window
.
getComputedStyle
(
div
,
null
)
||
{
marginTop
:
0
}
).
marginTop
!==
"1%"
;
support
.
pixelMargin
=
(
window
.
getComputedStyle
(
div
,
null
)
||
{
marginTop
:
0
}
).
marginTop
!==
"1%"
;
...
...
test/unit/support.js
View file @
77536f5c
...
@@ -98,10 +98,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
...
@@ -98,10 +98,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets"
:
true
,
"reliableHiddenOffsets"
:
true
,
"ajax"
:
true
,
"ajax"
:
true
,
"cors"
:
true
,
"cors"
:
true
,
"doesNotAddBorder"
:
true
,
"doesAddBorderForTableAndCells"
:
false
,
"fixedPosition"
:
true
,
"subtractsBorderForOverflowNotVisible"
:
false
,
"doesNotIncludeMarginInBodyOffset"
:
true
"doesNotIncludeMarginInBodyOffset"
:
true
};
};
for
(
i
in
expected
)
{
for
(
i
in
expected
)
{
...
@@ -141,10 +137,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
...
@@ -141,10 +137,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets"
:
false
,
"reliableHiddenOffsets"
:
false
,
"ajax"
:
true
,
"ajax"
:
true
,
"cors"
:
false
,
"cors"
:
false
,
"doesNotAddBorder"
:
false
,
"doesAddBorderForTableAndCells"
:
true
,
"fixedPosition"
:
true
,
"subtractsBorderForOverflowNotVisible"
:
false
,
"doesNotIncludeMarginInBodyOffset"
:
true
"doesNotIncludeMarginInBodyOffset"
:
true
};
};
for
(
i
in
expected
)
{
for
(
i
in
expected
)
{
...
@@ -164,11 +156,8 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
...
@@ -164,11 +156,8 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"cors"
:
false
,
"cors"
:
false
,
"cssFloat"
:
false
,
"cssFloat"
:
false
,
"deleteExpando"
:
false
,
"deleteExpando"
:
false
,
"doesAddBorderForTableAndCells"
:
true
,
"doesNotAddBorder"
:
true
,
"doesNotIncludeMarginInBodyOffset"
:
true
,
"doesNotIncludeMarginInBodyOffset"
:
true
,
"enctype"
:
true
,
"enctype"
:
true
,
"fixedPosition"
:
true
,
"focusinBubbles"
:
true
,
"focusinBubbles"
:
true
,
"getSetAttribute"
:
false
,
"getSetAttribute"
:
false
,
"hrefNormalized"
:
false
,
"hrefNormalized"
:
false
,
...
@@ -186,7 +175,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
...
@@ -186,7 +175,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableMarginRight"
:
true
,
"reliableMarginRight"
:
true
,
"shrinkWrapBlocks"
:
false
,
"shrinkWrapBlocks"
:
false
,
"submitBubbles"
:
false
,
"submitBubbles"
:
false
,
"subtractsBorderForOverflowNotVisible"
:
false
,
"tbody"
:
false
,
"tbody"
:
false
,
"style"
:
false
"style"
:
false
};
};
...
@@ -227,10 +215,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
...
@@ -227,10 +215,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets"
:
false
,
"reliableHiddenOffsets"
:
false
,
"ajax"
:
true
,
"ajax"
:
true
,
"cors"
:
false
,
"cors"
:
false
,
"doesNotAddBorder"
:
true
,
"doesAddBorderForTableAndCells"
:
true
,
"fixedPosition"
:
false
,
"subtractsBorderForOverflowNotVisible"
:
false
,
"doesNotIncludeMarginInBodyOffset"
:
true
"doesNotIncludeMarginInBodyOffset"
:
true
};
};
for
(
i
in
expected
)
{
for
(
i
in
expected
)
{
...
@@ -270,10 +254,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
...
@@ -270,10 +254,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets"
:
true
,
"reliableHiddenOffsets"
:
true
,
"ajax"
:
true
,
"ajax"
:
true
,
"cors"
:
true
,
"cors"
:
true
,
"doesNotAddBorder"
:
true
,
"doesAddBorderForTableAndCells"
:
false
,
"fixedPosition"
:
true
,
"subtractsBorderForOverflowNotVisible"
:
false
,
"doesNotIncludeMarginInBodyOffset"
:
true
"doesNotIncludeMarginInBodyOffset"
:
true
};
};
for
(
i
in
expected
)
{
for
(
i
in
expected
)
{
...
@@ -313,10 +293,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
...
@@ -313,10 +293,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets"
:
true
,
"reliableHiddenOffsets"
:
true
,
"ajax"
:
true
,
"ajax"
:
true
,
"cors"
:
true
,
"cors"
:
true
,
"doesNotAddBorder"
:
true
,
"doesAddBorderForTableAndCells"
:
true
,
"fixedPosition"
:
true
,
"subtractsBorderForOverflowNotVisible"
:
false
,
"doesNotIncludeMarginInBodyOffset"
:
true
"doesNotIncludeMarginInBodyOffset"
:
true
};
};
for
(
i
in
expected
)
{
for
(
i
in
expected
)
{
...
...
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