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
5376a809
Commit
5376a809
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 #10413, #10679. Fix box-sizing:border-box and add css vendor prefix support.
parent
77536f5c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
41 deletions
+129
-41
css.js
src/css.js
+72
-37
support.js
src/support.js
+4
-0
dimensions.js
test/unit/dimensions.js
+53
-4
No files found.
src/css.js
View file @
5376a809
...
@@ -13,12 +13,35 @@ var ralpha = /alpha\([^)]*\)/i,
...
@@ -13,12 +13,35 @@ var ralpha = /alpha\([^)]*\)/i,
// order is important!
// order is important!
cssExpand
=
[
"Top"
,
"Right"
,
"Bottom"
,
"Left"
],
cssExpand
=
[
"Top"
,
"Right"
,
"Bottom"
,
"Left"
],
cssPrefixes
=
[
"O"
,
"Webkit"
,
"Moz"
,
"ms"
],
curCSS
,
curCSS
,
getComputedStyle
,
getComputedStyle
,
currentStyle
;
currentStyle
;
// return a css property mapped to a potentially vendor prefixed property
function
vendorPropName
(
style
,
name
)
{
// shortcut for names that are not vendor prefixed
if
(
name
in
style
)
{
return
name
;
}
// check for vendor prefixed names
var
capName
=
name
.
charAt
(
0
).
toUpperCase
()
+
name
.
slice
(
1
),
origName
=
name
,
i
=
cssPrefixes
.
length
;
while
(
i
--
)
{
name
=
cssPrefixes
[
i
]
+
capName
;
if
(
name
in
style
)
{
return
name
;
}
}
return
origName
;
}
jQuery
.
fn
.
css
=
function
(
name
,
value
)
{
jQuery
.
fn
.
css
=
function
(
name
,
value
)
{
return
jQuery
.
access
(
this
,
function
(
elem
,
name
,
value
)
{
return
jQuery
.
access
(
this
,
function
(
elem
,
name
,
value
)
{
return
value
!==
undefined
?
return
value
!==
undefined
?
...
@@ -72,10 +95,15 @@ jQuery.extend({
...
@@ -72,10 +95,15 @@ jQuery.extend({
}
}
// Make sure that we're working with the right name
// Make sure that we're working with the right name
var
ret
,
type
,
origName
=
jQuery
.
camelCase
(
name
),
var
ret
,
type
,
hooks
,
style
=
elem
.
style
,
hooks
=
jQuery
.
cssHooks
[
origName
];
origName
=
jQuery
.
camelCase
(
name
),
style
=
elem
.
style
;
name
=
jQuery
.
cssProps
[
origName
]
||
origName
;
name
=
jQuery
.
cssProps
[
origName
]
||
(
jQuery
.
cssProps
[
origName
]
=
vendorPropName
(
style
,
origName
)
);
// gets hook for the prefixed version
// followed by the unprefixed version
hooks
=
jQuery
.
cssHooks
[
name
]
||
jQuery
.
cssHooks
[
origName
];
// Check if we're setting a value
// Check if we're setting a value
if
(
value
!==
undefined
)
{
if
(
value
!==
undefined
)
{
...
@@ -119,12 +147,15 @@ jQuery.extend({
...
@@ -119,12 +147,15 @@ jQuery.extend({
},
},
css
:
function
(
elem
,
name
,
extra
)
{
css
:
function
(
elem
,
name
,
extra
)
{
var
ret
,
hooks
;
var
ret
,
hooks
,
origName
=
jQuery
.
camelCase
(
name
);
// Make sure that we're working with the right name
// Make sure that we're working with the right name
name
=
jQuery
.
camelCase
(
name
);
name
=
jQuery
.
cssProps
[
origName
]
||
(
jQuery
.
cssProps
[
origName
]
=
vendorPropName
(
elem
.
style
,
origName
)
);
hooks
=
jQuery
.
cssHooks
[
name
];
name
=
jQuery
.
cssProps
[
name
]
||
name
;
// gets hook for the prefixed version
// followed by the unprefixed version
hooks
=
jQuery
.
cssHooks
[
name
]
||
jQuery
.
cssHooks
[
origName
];
// cssFloat needs a special treatment
// cssFloat needs a special treatment
if
(
name
===
"cssFloat"
)
{
if
(
name
===
"cssFloat"
)
{
...
@@ -244,24 +275,11 @@ function getWidthOrHeight( elem, name, extra ) {
...
@@ -244,24 +275,11 @@ function getWidthOrHeight( elem, name, extra ) {
// Start with offset property
// Start with offset property
var
val
=
name
===
"width"
?
elem
.
offsetWidth
:
elem
.
offsetHeight
,
var
val
=
name
===
"width"
?
elem
.
offsetWidth
:
elem
.
offsetHeight
,
i
=
name
===
"width"
?
1
:
0
,
i
=
name
===
"width"
?
1
:
0
,
len
=
4
;
len
=
4
,
usedOffset
=
true
;
if
(
val
>
0
)
{
if
(
extra
!==
"border"
)
{
for
(
;
i
<
len
;
i
+=
2
)
{
if
(
!
extra
)
{
val
-=
parseFloat
(
jQuery
.
css
(
elem
,
"padding"
+
cssExpand
[
i
]
)
)
||
0
;
}
if
(
extra
===
"margin"
)
{
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
extra
+
cssExpand
[
i
]
)
)
||
0
;
}
else
{
val
-=
parseFloat
(
jQuery
.
css
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
)
)
||
0
;
}
}
}
return
val
+
"px"
;
if
(
val
<=
0
)
{
}
usedOffset
=
false
;
// Fall back to computed then uncomputed css if necessary
// Fall back to computed then uncomputed css if necessary
val
=
curCSS
(
elem
,
name
);
val
=
curCSS
(
elem
,
name
);
...
@@ -276,7 +294,23 @@ function getWidthOrHeight( elem, name, extra ) {
...
@@ -276,7 +294,23 @@ function getWidthOrHeight( elem, name, extra ) {
// Normalize "", auto, and prepare for extra
// Normalize "", auto, and prepare for extra
val
=
parseFloat
(
val
)
||
0
;
val
=
parseFloat
(
val
)
||
0
;
}
//if we're using border-box, the css width/height value behaves like the offsetWidth/Height property!
if
(
usedOffset
||
(
jQuery
.
support
.
boxSizing
&&
jQuery
.
css
(
elem
,
"boxSizing"
)
===
"border-box"
)
)
{
if
(
extra
!==
"border"
)
{
for
(
;
i
<
len
;
i
+=
2
)
{
if
(
!
extra
)
{
val
-=
parseFloat
(
jQuery
.
css
(
elem
,
"padding"
+
cssExpand
[
i
]
)
)
||
0
;
}
if
(
extra
===
"margin"
)
{
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
extra
+
cssExpand
[
i
]
)
)
||
0
;
}
else
{
val
-=
parseFloat
(
jQuery
.
css
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
)
)
||
0
;
}
}
}
}
else
{
// Add padding, border, margin
// Add padding, border, margin
if
(
extra
)
{
if
(
extra
)
{
for
(
;
i
<
len
;
i
+=
2
)
{
for
(
;
i
<
len
;
i
+=
2
)
{
...
@@ -285,7 +319,8 @@ function getWidthOrHeight( elem, name, extra ) {
...
@@ -285,7 +319,8 @@ function getWidthOrHeight( elem, name, extra ) {
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
)
)
||
0
;
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
)
)
||
0
;
}
}
if
(
extra
===
"margin"
)
{
if
(
extra
===
"margin"
)
{
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
extra
+
cssExpand
[
i
])
)
||
0
;
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
extra
+
cssExpand
[
i
]
)
)
||
0
;
}
}
}
}
}
}
}
...
...
src/support.js
View file @
5376a809
...
@@ -180,6 +180,7 @@ jQuery.support = (function() {
...
@@ -180,6 +180,7 @@ jQuery.support = (function() {
jQuery
(
function
()
{
jQuery
(
function
()
{
var
container
,
offsetSupport
,
marginDiv
,
var
container
,
offsetSupport
,
marginDiv
,
conMarginTop
=
1
,
conMarginTop
=
1
,
boxSizingPrefixes
=
[
""
,
"-moz-"
,
"-webkit-"
,
""
],
body
=
document
.
getElementsByTagName
(
"body"
)[
0
];
body
=
document
.
getElementsByTagName
(
"body"
)[
0
];
if
(
!
body
)
{
if
(
!
body
)
{
...
@@ -250,6 +251,9 @@ jQuery.support = (function() {
...
@@ -250,6 +251,9 @@ jQuery.support = (function() {
support
.
shrinkWrapBlocks
=
(
div
.
offsetWidth
!==
3
);
support
.
shrinkWrapBlocks
=
(
div
.
offsetWidth
!==
3
);
}
}
div
.
style
.
cssText
=
boxSizingPrefixes
.
join
(
"box-sizing:border-box;"
)
+
"width:4px;padding:1px;border:1px;display:block"
;
support
.
boxSizing
=
(
div
.
offsetWidth
===
4
);
offsetSupport
=
{
offsetSupport
=
{
doesNotIncludeMarginInBodyOffset
:
(
body
.
offsetTop
!==
conMarginTop
)
doesNotIncludeMarginInBodyOffset
:
(
body
.
offsetTop
!==
conMarginTop
)
};
};
...
...
test/unit/dimensions.js
View file @
5376a809
...
@@ -230,12 +230,13 @@ test("outerWidth()", function() {
...
@@ -230,12 +230,13 @@ test("outerWidth()", function() {
jQuery
.
removeData
(
$div
[
0
],
"olddisplay"
,
true
);
jQuery
.
removeData
(
$div
[
0
],
"olddisplay"
,
true
);
});
});
test
(
"child of a hidden elem has accurate inner/outer/Width()/Height() see #9441 #9300"
,
function
()
{
test
(
"child of a hidden elem
(or unconnected node)
has accurate inner/outer/Width()/Height() see #9441 #9300"
,
function
()
{
expect
(
8
);
expect
(
16
);
// setup html
// setup html
var
$divNormal
=
jQuery
(
"<div>"
).
css
({
width
:
"100px"
,
height
:
"100px"
,
border
:
"10px solid white"
,
padding
:
"2px"
,
margin
:
"3px"
}),
var
$divNormal
=
jQuery
(
"<div>"
).
css
({
width
:
"100px"
,
height
:
"100px"
,
border
:
"10px solid white"
,
padding
:
"2px"
,
margin
:
"3px"
}),
$divChild
=
$divNormal
.
clone
(),
$divChild
=
$divNormal
.
clone
(),
$divUnconnected
=
$divNormal
.
clone
(),
$divHiddenParent
=
jQuery
(
"<div>"
).
css
(
"display"
,
"none"
).
append
(
$divChild
).
appendTo
(
"body"
);
$divHiddenParent
=
jQuery
(
"<div>"
).
css
(
"display"
,
"none"
).
append
(
$divChild
).
appendTo
(
"body"
);
$divNormal
.
appendTo
(
"body"
);
$divNormal
.
appendTo
(
"body"
);
...
@@ -250,6 +251,17 @@ test("child of a hidden elem has accurate inner/outer/Width()/Height() see #944
...
@@ -250,6 +251,17 @@ test("child of a hidden elem has accurate inner/outer/Width()/Height() see #944
equal
(
$divChild
.
outerHeight
(),
$divNormal
.
outerHeight
(),
"child of a hidden element outerHeight() is wrong see #9441"
);
equal
(
$divChild
.
outerHeight
(),
$divNormal
.
outerHeight
(),
"child of a hidden element outerHeight() is wrong see #9441"
);
equal
(
$divChild
.
outerHeight
(
true
),
$divNormal
.
outerHeight
(
true
),
"child of a hidden element outerHeight( true ) is wrong see #9300"
);
equal
(
$divChild
.
outerHeight
(
true
),
$divNormal
.
outerHeight
(
true
),
"child of a hidden element outerHeight( true ) is wrong see #9300"
);
// tests that child div of an unconnected div works the same as a normal div
equal
(
$divUnconnected
.
width
(),
$divNormal
.
width
(),
"unconnected element width() is wrong see #9441"
);
equal
(
$divUnconnected
.
innerWidth
(),
$divNormal
.
innerWidth
(),
"unconnected element innerWidth() is wrong see #9441"
);
equal
(
$divUnconnected
.
outerWidth
(),
$divNormal
.
outerWidth
(),
"unconnected element outerWidth() is wrong see #9441"
);
equal
(
$divUnconnected
.
outerWidth
(
true
),
$divNormal
.
outerWidth
(
true
),
"unconnected element outerWidth( true ) is wrong see #9300"
);
equal
(
$divUnconnected
.
height
(),
$divNormal
.
height
(),
"unconnected element height() is wrong see #9441"
);
equal
(
$divUnconnected
.
innerHeight
(),
$divNormal
.
innerHeight
(),
"unconnected element innerHeight() is wrong see #9441"
);
equal
(
$divUnconnected
.
outerHeight
(),
$divNormal
.
outerHeight
(),
"unconnected element outerHeight() is wrong see #9441"
);
equal
(
$divUnconnected
.
outerHeight
(
true
),
$divNormal
.
outerHeight
(
true
),
"unconnected element outerHeight( true ) is wrong see #9300"
);
// teardown html
// teardown html
$divHiddenParent
.
remove
();
$divHiddenParent
.
remove
();
$divNormal
.
remove
();
$divNormal
.
remove
();
...
@@ -278,6 +290,43 @@ test("getting dimensions shouldnt modify runtimeStyle see #9233", function() {
...
@@ -278,6 +290,43 @@ test("getting dimensions shouldnt modify runtimeStyle see #9233", function() {
$div
.
remove
();
$div
.
remove
();
});
});
test
(
"box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413"
,
function
()
{
expect
(
16
);
// setup html
var
$divNormal
=
jQuery
(
"<div>"
).
css
({
boxSizing
:
"border-box"
,
width
:
"100px"
,
height
:
"100px"
,
border
:
"10px solid white"
,
padding
:
"2px"
,
margin
:
"3px"
}),
$divChild
=
$divNormal
.
clone
(),
$divUnconnected
=
$divNormal
.
clone
(),
$divHiddenParent
=
jQuery
(
"<div>"
).
css
(
"display"
,
"none"
).
append
(
$divChild
).
appendTo
(
"body"
);
$divNormal
.
appendTo
(
"body"
);
// tests that child div of a hidden div works the same as a normal div
equal
(
$divChild
.
width
(),
$divNormal
.
width
(),
"child of a hidden element width() is wrong see #10413"
);
equal
(
$divChild
.
innerWidth
(),
$divNormal
.
innerWidth
(),
"child of a hidden element innerWidth() is wrong see #10413"
);
equal
(
$divChild
.
outerWidth
(),
$divNormal
.
outerWidth
(),
"child of a hidden element outerWidth() is wrong see #10413"
);
equal
(
$divChild
.
outerWidth
(
true
),
$divNormal
.
outerWidth
(
true
),
"child of a hidden element outerWidth( true ) is wrong see #10413"
);
equal
(
$divChild
.
height
(),
$divNormal
.
height
(),
"child of a hidden element height() is wrong see #10413"
);
equal
(
$divChild
.
innerHeight
(),
$divNormal
.
innerHeight
(),
"child of a hidden element innerHeight() is wrong see #10413"
);
equal
(
$divChild
.
outerHeight
(),
$divNormal
.
outerHeight
(),
"child of a hidden element outerHeight() is wrong see #10413"
);
equal
(
$divChild
.
outerHeight
(
true
),
$divNormal
.
outerHeight
(
true
),
"child of a hidden element outerHeight( true ) is wrong see #10413"
);
// tests that child div of an unconnected div works the same as a normal div
equal
(
$divUnconnected
.
width
(),
$divNormal
.
width
(),
"unconnected element width() is wrong see #10413"
);
equal
(
$divUnconnected
.
innerWidth
(),
$divNormal
.
innerWidth
(),
"unconnected element innerWidth() is wrong see #10413"
);
equal
(
$divUnconnected
.
outerWidth
(),
$divNormal
.
outerWidth
(),
"unconnected element outerWidth() is wrong see #10413"
);
equal
(
$divUnconnected
.
outerWidth
(
true
),
$divNormal
.
outerWidth
(
true
),
"unconnected element outerWidth( true ) is wrong see #10413"
);
equal
(
$divUnconnected
.
height
(),
$divNormal
.
height
(),
"unconnected element height() is wrong see #10413"
);
equal
(
$divUnconnected
.
innerHeight
(),
$divNormal
.
innerHeight
(),
"unconnected element innerHeight() is wrong see #10413"
);
equal
(
$divUnconnected
.
outerHeight
(),
$divNormal
.
outerHeight
(),
"unconnected element outerHeight() is wrong see #10413"
);
equal
(
$divUnconnected
.
outerHeight
(
true
),
$divNormal
.
outerHeight
(
true
),
"unconnected element outerHeight( true ) is wrong see #10413"
);
// teardown html
$divHiddenParent
.
remove
();
$divNormal
.
remove
();
});
test
(
"outerHeight()"
,
function
()
{
test
(
"outerHeight()"
,
function
()
{
expect
(
11
);
expect
(
11
);
...
...
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