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
44a3b583
Commit
44a3b583
authored
Apr 04, 2011
by
Dan Heberden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve relative string performance in .css and some code cleanup
parent
123dd72e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
25 deletions
+37
-25
css.js
src/css.js
+10
-9
css.js
test/unit/css.js
+27
-16
No files found.
src/css.js
View file @
44a3b583
...
@@ -7,8 +7,8 @@ var ralpha = /alpha\([^)]*\)/i,
...
@@ -7,8 +7,8 @@ var ralpha = /alpha\([^)]*\)/i,
rupper
=
/
([
A-Z
]
|^ms
)
/g
,
rupper
=
/
([
A-Z
]
|^ms
)
/g
,
rnumpx
=
/^-
?\d
+
(?:
px
)?
$/i
,
rnumpx
=
/^-
?\d
+
(?:
px
)?
$/i
,
rnum
=
/^-
?\d
/
,
rnum
=
/^-
?\d
/
,
rrelNum
=
/=/
,
rrelNum
=
/
^
[
+
\-]
=/
,
rrel
String
=
/
[^
+
\-
\d
e
]
+/g
,
rrel
NumFilter
=
/
[^
+
\-\.
\d
e
]
+/g
,
cssShow
=
{
position
:
"absolute"
,
visibility
:
"hidden"
,
display
:
"block"
},
cssShow
=
{
position
:
"absolute"
,
visibility
:
"hidden"
,
display
:
"block"
},
cssWidth
=
[
"Left"
,
"Right"
],
cssWidth
=
[
"Left"
,
"Right"
],
...
@@ -77,26 +77,27 @@ jQuery.extend({
...
@@ -77,26 +77,27 @@ jQuery.extend({
}
}
// Make sure that we're working with the right name
// Make sure that we're working with the right name
var
ret
,
parsed
,
type
,
origName
=
jQuery
.
camelCase
(
name
),
var
ret
,
type
,
origName
=
jQuery
.
camelCase
(
name
),
style
=
elem
.
style
,
hooks
=
jQuery
.
cssHooks
[
origName
];
style
=
elem
.
style
,
hooks
=
jQuery
.
cssHooks
[
origName
];
name
=
jQuery
.
cssProps
[
origName
]
||
origName
;
name
=
jQuery
.
cssProps
[
origName
]
||
origName
;
// Check if we're setting a value
// Check if we're setting a value
if
(
value
!==
undefined
)
{
if
(
value
!==
undefined
)
{
type
=
typeof
value
;
// Make sure that NaN and null values aren't set. See: #7116
// Make sure that NaN and null values aren't set. See: #7116
if
(
type
of
value
===
"number"
&&
isNaN
(
value
)
||
value
==
null
)
{
if
(
type
===
"number"
&&
isNaN
(
value
)
||
value
==
null
)
{
return
;
return
;
}
}
// convert string to number or relative number
// convert relative number strings (+= or -=) to relative numbers. #7345
if
(
type
===
"string"
)
{
if
(
type
===
"string"
&&
rrelNum
.
test
(
value
)
)
{
parsed
=
+
value
.
replace
(
rrelString
,
''
);
value
=
+
value
.
replace
(
rrelNumFilter
,
''
)
+
parseFloat
(
jQuery
.
css
(
elem
,
name
)
);
value
=
rrelNum
.
test
(
value
)
?
parsed
+
jQuery
.
css
(
elem
,
name
)
:
parsed
;
}
}
// If a number was passed in, add 'px' to the (except for certain CSS properties)
// If a number was passed in, add 'px' to the (except for certain CSS properties)
if
(
type
of
value
===
"number"
&&
!
jQuery
.
cssNumber
[
origName
]
)
{
if
(
type
===
"number"
&&
!
jQuery
.
cssNumber
[
origName
]
)
{
value
+=
"px"
;
value
+=
"px"
;
}
}
...
...
test/unit/css.js
View file @
44a3b583
...
@@ -106,24 +106,35 @@ test("css(String|Hash)", function() {
...
@@ -106,24 +106,35 @@ test("css(String|Hash)", function() {
});
});
test
(
"css() explicit and relative values"
,
function
()
{
test
(
"css() explicit and relative values"
,
function
()
{
expect
(
9
);
var
$elem
=
jQuery
(
'#nothiddendiv'
);
var
$elem
=
jQuery
(
'#nothiddendiv'
);
$elem
.
css
({
width
:
1
,
height
:
1
});
$elem
.
css
({
width
:
1
,
height
:
1
});
ok
(
[
$elem
.
width
(),
$elem
.
height
()],
[
1
,
1
]
);
equals
(
$elem
.
width
(),
1
,
"Initial css set or width/height works (hash)"
);
$elem
.
css
({
width
:
"+=9"
,
height
:
"+=9"
});
ok
(
[
$elem
.
width
(),
$elem
.
height
()],
[
10
,
10
]
);
$elem
.
css
({
width
:
"+=9"
});
$elem
.
css
({
width
:
"-=9"
,
height
:
"-=9"
});
equals
(
$elem
.
width
(),
10
,
"'+=9' on width (hash)"
);
ok
(
[
$elem
.
width
(),
$elem
.
height
()],
[
1
,
1
]
);
$elem
.
css
({
width
:
"+=9px"
,
height
:
"+=9px"
});
$elem
.
css
({
width
:
"-=9"
});
ok
(
[
$elem
.
width
(),
$elem
.
height
()],
[
10
,
10
]
);
equals
(
$elem
.
width
(),
1
,
"'-=9' on width (hash)"
);
$elem
.
css
({
width
:
"-=9px"
,
height
:
"-=9px"
});
ok
(
[
$elem
.
width
(),
$elem
.
height
()],
[
1
,
1
]
);
$elem
.
css
({
width
:
"+=9px"
});
$elem
.
css
(
"width"
,
"+=9"
).
css
(
"height"
,
"+=9"
);
equals
(
$elem
.
width
(),
10
,
"'+=9px' on width (hash)"
);
ok
(
[
$elem
.
width
(),
$elem
.
height
()],
[
10
,
10
]
);
$elem
.
css
(
"width"
,
"+9"
).
css
(
"height"
,
"+9"
);
$elem
.
css
({
width
:
"-=9px"
});
ok
(
[
$elem
.
width
(),
$elem
.
height
()],
[
9
,
9
]
);
equals
(
$elem
.
width
(),
1
,
"'-=9px' on width (hash)"
);
$elem
.
css
(
"width"
,
"-9"
).
css
(
"height"
,
"-9"
);
ok
(
[
$elem
.
width
(),
$elem
.
height
()],
[
0
,
0
]
);
$elem
.
css
(
"width"
,
"+=9"
);
equals
(
$elem
.
width
(),
10
,
"'+=9' on width (params)"
);
$elem
.
css
(
"width"
,
"-=9"
)
;
equals
(
$elem
.
width
(),
1
,
"'-=9' on width (params)"
);
$elem
.
css
(
"width"
,
"+=9px"
);
equals
(
$elem
.
width
(),
10
,
"'+=9px' on width (params)"
);
$elem
.
css
(
"width"
,
"-=9px"
);
equals
(
$elem
.
width
(),
1
,
"'-=9px' on width (params)"
);
});
});
test
(
"css(String, Object)"
,
function
()
{
test
(
"css(String, Object)"
,
function
()
{
...
...
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