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
e64d3d4e
Commit
e64d3d4e
authored
Apr 14, 2011
by
Jordan Boesch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing bug 4146 - round 2!
parent
ca5bc202
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
17 deletions
+110
-17
css.js
src/css.js
+31
-17
dimensions.js
test/unit/dimensions.js
+79
-0
No files found.
src/css.js
View file @
e64d3d4e
...
@@ -338,25 +338,39 @@ curCSS = getComputedStyle || currentStyle;
...
@@ -338,25 +338,39 @@ curCSS = getComputedStyle || currentStyle;
function
getWH
(
elem
,
name
,
extra
)
{
function
getWH
(
elem
,
name
,
extra
)
{
var
which
=
name
===
"width"
?
cssWidth
:
cssHeight
,
var
which
=
name
===
"width"
?
cssWidth
:
cssHeight
,
val
=
name
===
"width"
?
elem
.
offsetWidth
:
elem
.
offsetHeight
;
cur
=
curCSS
(
elem
,
name
),
// We're addressing the way Firefox handles certain inputs and buttons, offsetWidth/height actually returns a normal width/height
if
(
extra
===
"border"
)
{
ff
=
/input|button/i
.
test
(
elem
.
tagName
.
toLowerCase
()
)
&&
curCSS
(
elem
,
'-moz-box-sizing'
)
===
'border-box'
;
return
val
;
// IE will return auto if we try to grab a width/height that is not set
if
(
ff
||
cur
===
'auto'
)
{
cur
=
name
===
"width"
?
elem
.
offsetWidth
:
elem
.
offsetHeight
;
}
}
jQuery
.
each
(
which
,
function
()
{
// Fixes an IE7 effects test. "Chain show hide" was returning "scroll" instead of "visible"
if
(
!
extra
)
{
if
(
name
==
"height"
){
val
-=
parseFloat
(
jQuery
.
css
(
elem
,
"padding"
+
this
))
||
0
;
elem
.
offsetHeight
;
}
}
if
(
extra
===
"margin"
)
{
var
val
=
parseFloat
(
cur
)
||
0
;
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
"margin"
+
this
))
||
0
;
if
(
extra
)
{
}
else
{
for
(
var
i
=
0
,
len
=
which
.
length
;
i
<
len
;
i
++
)
{
val
-=
parseFloat
(
jQuery
.
css
(
elem
,
"border"
+
this
+
"Width"
))
||
0
;
var
dir
=
which
[
i
];
// outerWidth/height
if
(
extra
===
"border"
||
extra
===
'margin'
)
{
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
"border"
+
dir
+
"Width"
))
||
0
;
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
"padding"
+
dir
))
||
0
;
if
(
extra
==
'margin'
)
{
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
"margin"
+
dir
))
||
0
;
}
}
// innerWidth/height
else
{
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
"padding"
+
dir
))
||
0
;
}
}
}
});
}
return
val
;
return
val
;
}
}
...
...
test/unit/dimensions.js
View file @
e64d3d4e
...
@@ -222,3 +222,82 @@ test("outerHeight()", function() {
...
@@ -222,3 +222,82 @@ test("outerHeight()", function() {
div
.
remove
();
div
.
remove
();
jQuery
.
removeData
(
$div
[
0
],
"olddisplay"
,
true
);
jQuery
.
removeData
(
$div
[
0
],
"olddisplay"
,
true
);
});
});
test
(
'width(), outerWidth(), innerWidth(), height(), outerHeight() and innerHeight() with inputs'
,
function
(){
expect
(
47
);
var
id
=
'input-width-test-group'
;
var
input_els
=
'submit reset button'
.
split
(
' '
);
var
html
=
'<div id="'
+
id
+
'" style="width:100px;">'
;
var
style
=
'width:35px;height:50px;padding:5px;border:1px solid #000;margin:2px;'
;
html
+=
'<div id="nothing-set-div">test</div>'
;
html
+=
'<div id="width-div-1" style="'
+
style
+
'">something</div>'
;
html
+=
'<button id="width-button-1" style="'
+
style
+
'">button</button>'
;
jQuery
.
each
(
input_els
,
function
()
{
html
+=
'<input class="width-input" type="'
+
this
+
'" style="'
+
style
+
'" />'
;
});
html
+=
'</div>'
;
jQuery
(
'#main'
).
append
(
html
);
equals
(
jQuery
(
'#nothing-set-div'
).
width
(),
100
,
'Width of unset div takes on parent'
);
jQuery
(
'#width-div-1, #width-button-1, .width-input'
).
each
(
function
(){
// Test widths
var
w
=
jQuery
(
this
).
width
();
var
outer_w
=
jQuery
(
this
).
outerWidth
();
var
outer_w_margin
=
jQuery
(
this
).
outerWidth
(
true
);
var
inner_w
=
jQuery
(
this
).
innerWidth
();
var
t
=
this
.
tagName
.
toLowerCase
()
+
((
this
.
type
)
?
'['
+
this
.
type
+
']'
:
''
);
equals
(
w
,
35
,
'Make sure width() works for '
+
t
);
equals
(
outer_w
,
47
,
'Make sure outerWidth() works for '
+
t
);
equals
(
outer_w_margin
,
51
,
'Make sure outerWidth(true) works for '
+
t
);
equals
(
inner_w
,
45
,
'Make sure innerWidth() works for '
+
t
);
// Test heights
var
h
=
jQuery
(
this
).
height
();
var
outer_h
=
jQuery
(
this
).
outerHeight
();
var
outer_h_margin
=
jQuery
(
this
).
outerHeight
(
true
);
var
inner_h
=
jQuery
(
this
).
innerHeight
();
equals
(
h
,
50
,
'Make sure height() works for '
+
t
);
equals
(
outer_h
,
62
,
'Make sure outerHeight() works for '
+
t
);
equals
(
outer_h_margin
,
66
,
'Make sure outerHeight(true) works for '
+
t
);
equals
(
inner_h
,
60
,
'Make sure innerHeight() works for '
+
t
);
});
var
inputsub
=
jQuery
(
'.width-input'
).
filter
(
'input[type=submit]'
);
inputsub
.
css
({
width
:
10
,
padding
:
0
,
margin
:
'3px'
,
border
:
'1px solid red'
,
height
:
15
});
var
w
=
inputsub
.
width
();
equals
(
w
,
10
,
'width() works after setting css using .css()'
);
var
outer_w
=
inputsub
.
outerWidth
();
equals
(
outer_w
,
12
,
'outerWidth() works after setting css using .css()'
);
var
outer_w_margin
=
inputsub
.
outerWidth
(
true
);
equals
(
outer_w_margin
,
18
,
'outerWidth(true) works after setting css using .css()'
);
var
h
=
inputsub
.
height
();
equals
(
h
,
15
,
'height() works after setting css using .css()'
);
var
outer_h
=
inputsub
.
outerHeight
();
equals
(
outer_h
,
17
,
'outerHeight() works after setting css using .css()'
);
var
outer_h_margin
=
inputsub
.
outerHeight
(
true
);
equals
(
outer_h_margin
,
23
,
'outerHeight(true) works after setting css using .css()'
);
jQuery
(
'#'
+
id
).
remove
();
});
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