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
3ba72f99
Commit
3ba72f99
authored
Aug 25, 2011
by
Dave Methvin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #464 from dmethvin/fix-10021-relative-negative-values
Fixes #10021. Allow negative relative values for `.css()`
parents
a839af03
5d954c1b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
10 deletions
+15
-10
css.js
src/css.js
+8
-9
css.js
test/unit/css.js
+7
-1
No files found.
src/css.js
View file @
3ba72f99
...
@@ -6,8 +6,7 @@ var ralpha = /alpha\([^)]*\)/i,
...
@@ -6,8 +6,7 @@ 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
=
/^
([
-+
])
=
([
-+.
\d
e
]
+
)
/
,
rrelNumFilter
=
/
[^
+
\-\.\d
e
]
+/g
,
cssShow
=
{
position
:
"absolute"
,
visibility
:
"hidden"
,
display
:
"block"
},
cssShow
=
{
position
:
"absolute"
,
visibility
:
"hidden"
,
display
:
"block"
},
cssWidth
=
[
"Left"
,
"Right"
],
cssWidth
=
[
"Left"
,
"Right"
],
...
@@ -84,18 +83,18 @@ jQuery.extend({
...
@@ -84,18 +83,18 @@ jQuery.extend({
if
(
value
!==
undefined
)
{
if
(
value
!==
undefined
)
{
type
=
typeof
value
;
type
=
typeof
value
;
// Make sure that NaN and null values aren't set. See: #7116
if
(
type
===
"number"
&&
isNaN
(
value
)
||
value
==
null
)
{
return
;
}
// convert relative number strings (+= or -=) to relative numbers. #7345
// convert relative number strings (+= or -=) to relative numbers. #7345
if
(
type
===
"string"
&&
rrelNum
.
test
(
value
)
)
{
if
(
type
===
"string"
&&
(
ret
=
rrelNum
.
exec
(
value
)
)
)
{
value
=
+
value
.
replace
(
rrelNumFilter
,
""
)
+
parseFloat
(
jQuery
.
css
(
elem
,
name
)
);
value
=
(
+
(
ret
[
1
]
+
1
)
*
+
ret
[
2
]
)
+
parseFloat
(
jQuery
.
css
(
elem
,
name
)
);
// Fixes bug #9237
// Fixes bug #9237
type
=
"number"
;
type
=
"number"
;
}
}
// Make sure that NaN and null values aren't set. See: #7116
if
(
value
==
null
||
type
===
"number"
&&
isNaN
(
value
)
)
{
return
;
}
// 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
===
"number"
&&
!
jQuery
.
cssNumber
[
origName
]
)
{
if
(
type
===
"number"
&&
!
jQuery
.
cssNumber
[
origName
]
)
{
value
+=
"px"
;
value
+=
"px"
;
...
...
test/unit/css.js
View file @
3ba72f99
...
@@ -109,7 +109,7 @@ test("css(String|Hash)", function() {
...
@@ -109,7 +109,7 @@ test("css(String|Hash)", function() {
});
});
test
(
"css() explicit and relative values"
,
function
()
{
test
(
"css() explicit and relative values"
,
function
()
{
expect
(
2
7
);
expect
(
2
9
);
var
$elem
=
jQuery
(
"#nothiddendiv"
);
var
$elem
=
jQuery
(
"#nothiddendiv"
);
$elem
.
css
({
width
:
1
,
height
:
1
,
paddingLeft
:
"1px"
,
opacity
:
1
});
$elem
.
css
({
width
:
1
,
height
:
1
,
paddingLeft
:
"1px"
,
opacity
:
1
});
...
@@ -141,6 +141,12 @@ test("css() explicit and relative values", function() {
...
@@ -141,6 +141,12 @@ test("css() explicit and relative values", function() {
$elem
.
css
(
"width"
,
"-=9px"
);
$elem
.
css
(
"width"
,
"-=9px"
);
equals
(
$elem
.
width
(),
1
,
"'-=9px' on width (params)"
);
equals
(
$elem
.
width
(),
1
,
"'-=9px' 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)"
);
$elem
.
css
({
paddingLeft
:
"+=4"
});
$elem
.
css
({
paddingLeft
:
"+=4"
});
equals
(
$elem
.
css
(
"paddingLeft"
),
"5px"
,
"'+=4' on paddingLeft (hash)"
);
equals
(
$elem
.
css
(
"paddingLeft"
),
"5px"
,
"'+=4' on paddingLeft (hash)"
);
...
...
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