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
dac716ca
Commit
dac716ca
authored
Dec 18, 2014
by
Oleg Gaidarenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CSS: simplify hack of css getter for the computed values
Ref gh-1906
parent
d9d8906c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
10 deletions
+18
-10
curCSS.js
src/css/curCSS.js
+2
-10
testsuite.css
test/data/testsuite.css
+5
-0
css.js
test/unit/css.js
+11
-0
No files found.
src/css/curCSS.js
View file @
dac716ca
...
@@ -72,7 +72,7 @@ if ( window.getComputedStyle ) {
...
@@ -72,7 +72,7 @@ if ( window.getComputedStyle ) {
};
};
curCSS
=
function
(
elem
,
name
,
computed
)
{
curCSS
=
function
(
elem
,
name
,
computed
)
{
var
left
,
r
s
,
rsLeft
,
r
et
,
var
left
,
ret
,
style
=
elem
.
style
;
style
=
elem
.
style
;
computed
=
computed
||
getStyles
(
elem
);
computed
=
computed
||
getStyles
(
elem
);
...
@@ -84,7 +84,7 @@ if ( window.getComputedStyle ) {
...
@@ -84,7 +84,7 @@ if ( window.getComputedStyle ) {
ret
=
style
[
name
];
ret
=
style
[
name
];
}
}
//
From the awesome
hack by Dean Edwards
//
Simplified
hack by Dean Edwards
// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
// If we're not dealing with a regular pixel number
// If we're not dealing with a regular pixel number
...
@@ -97,21 +97,13 @@ if ( window.getComputedStyle ) {
...
@@ -97,21 +97,13 @@ if ( window.getComputedStyle ) {
// Remember the original values
// Remember the original values
left
=
style
.
left
;
left
=
style
.
left
;
rs
=
elem
.
runtimeStyle
;
rsLeft
=
rs
&&
rs
.
left
;
// Put in the new values to get a computed value out
// Put in the new values to get a computed value out
if
(
rsLeft
)
{
rs
.
left
=
elem
.
currentStyle
.
left
;
}
style
.
left
=
name
===
"fontSize"
?
"1em"
:
ret
;
style
.
left
=
name
===
"fontSize"
?
"1em"
:
ret
;
ret
=
style
.
pixelLeft
+
"px"
;
ret
=
style
.
pixelLeft
+
"px"
;
// Revert the changed values
// Revert the changed values
style
.
left
=
left
;
style
.
left
=
left
;
if
(
rsLeft
)
{
rs
.
left
=
rsLeft
;
}
}
}
// Support: IE<9
// Support: IE<9
...
...
test/data/testsuite.css
View file @
dac716ca
...
@@ -163,3 +163,8 @@ section { background:#f0f; display:block; }
...
@@ -163,3 +163,8 @@ section { background:#f0f; display:block; }
-ms-filter
:
"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"
;
-ms-filter
:
"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"
;
}
}
.get-computed-value
{
padding-left
:
50%
;
width
:
20%
;
font-size
:
2em
;
}
test/unit/css.js
View file @
dac716ca
...
@@ -119,6 +119,17 @@ test("css(String|Hash)", function() {
...
@@ -119,6 +119,17 @@ test("css(String|Hash)", function() {
"Make sure that a string z-index is returned from css('z-index') (#14432)."
);
"Make sure that a string z-index is returned from css('z-index') (#14432)."
);
});
});
test
(
"css(String) computed values"
,
3
,
function
()
{
var
div
=
jQuery
(
"<div/>"
).
addClass
(
"get-computed-value"
),
fixture
=
document
.
getElementById
(
"qunit-fixture"
);
div
.
appendTo
(
fixture
);
strictEqual
(
div
.
css
(
"padding-left"
),
"500px"
,
"should get computed value for padding-left property"
);
strictEqual
(
div
.
css
(
"width"
),
"200px"
,
"should get computed value for width property"
);
strictEqual
(
div
.
css
(
"font-size"
),
"32px"
,
"should get computed value for font-size property"
);
});
test
(
"css() explicit and relative values"
,
29
,
function
()
{
test
(
"css() explicit and relative values"
,
29
,
function
()
{
var
$elem
=
jQuery
(
"#nothiddendiv"
);
var
$elem
=
jQuery
(
"#nothiddendiv"
);
...
...
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