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
83c08ffa
Commit
83c08ffa
authored
Oct 12, 2011
by
Dave Methvin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #10478. Replace jQuery.isNaN with jQuery.isNumeric.
Thanks to Christian C. Salvadó for the unit tests!
parent
6afc2c07
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
5 deletions
+45
-5
core.js
src/core.js
+2
-2
css.js
src/css.js
+1
-1
data.js
src/data.js
+1
-1
dimensions.js
src/dimensions.js
+1
-1
core.js
test/unit/core.js
+40
-0
No files found.
src/core.js
View file @
83c08ffa
...
...
@@ -483,8 +483,8 @@ jQuery.extend({
return
obj
&&
typeof
obj
===
"object"
&&
"setInterval"
in
obj
;
},
isN
aN
:
function
(
obj
)
{
return
obj
==
null
||
!
rdigit
.
test
(
obj
)
||
isNaN
(
obj
);
isN
umeric
:
function
(
obj
)
{
return
obj
!=
null
&&
rdigit
.
test
(
obj
)
&&
!
isNaN
(
obj
);
},
type
:
function
(
obj
)
{
...
...
src/css.js
View file @
83c08ffa
...
...
@@ -211,7 +211,7 @@ if ( !jQuery.support.opacity ) {
set
:
function
(
elem
,
value
)
{
var
style
=
elem
.
style
,
currentStyle
=
elem
.
currentStyle
,
opacity
=
jQuery
.
isN
aN
(
value
)
?
""
:
"alpha(opacity="
+
value
*
100
+
")
"
,
opacity
=
jQuery
.
isN
umeric
(
value
)
?
"alpha(opacity="
+
value
*
100
+
")"
:
"
"
,
filter
=
currentStyle
&&
currentStyle
.
filter
||
style
.
filter
||
""
;
// IE has trouble with opacity if it does not have layout
...
...
src/data.js
View file @
83c08ffa
...
...
@@ -323,7 +323,7 @@ function dataAttr( elem, key, data ) {
data
=
data
===
"true"
?
true
:
data
===
"false"
?
false
:
data
===
"null"
?
null
:
!
jQuery
.
isNaN
(
data
)
?
parseFloat
(
data
)
:
jQuery
.
isNumeric
(
data
)
?
parseFloat
(
data
)
:
rbrace
.
test
(
data
)
?
jQuery
.
parseJSON
(
data
)
:
data
;
}
catch
(
e
)
{}
...
...
src/dimensions.js
View file @
83c08ffa
...
...
@@ -61,7 +61,7 @@ jQuery.each([ "Height", "Width" ], function( i, name ) {
var
orig
=
jQuery
.
css
(
elem
,
type
),
ret
=
parseFloat
(
orig
);
return
jQuery
.
isN
aN
(
ret
)
?
orig
:
ret
;
return
jQuery
.
isN
umeric
(
ret
)
?
ret
:
orig
;
// Set the width or height on the element (default to pixels if value is unitless)
}
else
{
...
...
test/unit/core.js
View file @
83c08ffa
...
...
@@ -454,6 +454,46 @@ test("isFunction", function() {
});
});
test
(
"isNumeric"
,
function
()
{
expect
(
33
);
var
t
=
jQuery
.
isNumeric
;
ok
(
t
(
"-10"
),
"Negative integer string"
);
ok
(
t
(
"0"
),
"Zero string"
);
ok
(
t
(
"5"
),
"Positive integer string"
);
ok
(
t
(
-
16
),
"Negative integer number"
);
ok
(
t
(
0
),
"Zero integer number"
);
ok
(
t
(
32
),
"Positive integer number"
);
ok
(
t
(
"040"
),
"Octal integer literal string"
);
ok
(
t
(
0144
),
"Octal integer literal"
);
ok
(
t
(
"0xFF"
),
"Hexadecimal integer literal string"
);
ok
(
t
(
0xFFF
),
"Hexadecimal integer literal"
);
ok
(
t
(
"-1.6"
),
"Negative floating point string"
);
ok
(
t
(
"4.536"
),
"Positive floating point string"
);
ok
(
t
(
-
2.6
),
"Negative floating point number"
);
ok
(
t
(
3.1415
),
"Positive floating point number"
);
ok
(
t
(
8
e5
),
"Exponential notation"
);
ok
(
t
(
"123e-2"
),
"Exponential notation string"
);
equals
(
t
(
""
),
false
,
"Empty string"
);
equals
(
t
(
" "
),
false
,
"Whitespace characters string"
);
equals
(
t
(
"
\
t
\
t"
),
false
,
"Tab characters string"
);
equals
(
t
(
"abcdefghijklm1234567890"
),
false
,
"Alphanumeric character string"
);
equals
(
t
(
"xabcdefx"
),
false
,
"Non-numeric character string"
);
equals
(
t
(
true
),
false
,
"Boolean true literal"
);
equals
(
t
(
false
),
false
,
"Boolean false literal"
);
equals
(
t
(
"bcfed5.2"
),
false
,
"Number with preceding non-numeric characters"
);
equals
(
t
(
"7.2acdgs"
),
false
,
"Number with trailling non-numeric characters"
);
equals
(
t
(
undefined
),
false
,
"Undefined value"
);
equals
(
t
(
null
),
false
,
"Null value"
);
equals
(
t
(
NaN
),
false
,
"NaN value"
);
equals
(
t
(
Infinity
),
false
,
"Infinity primitive"
);
equals
(
t
(
Number
.
POSITIVE_INFINITY
),
false
,
"Positive Infinity"
);
equals
(
t
(
Number
.
NEGATIVE_INFINITY
),
false
,
"Negative Infinity"
);
equals
(
t
({}),
false
,
"Empty object"
);
equals
(
t
(
function
(){}
),
false
,
"Instance of a function"
);
});
test
(
"isXMLDoc - HTML"
,
function
()
{
expect
(
4
);
...
...
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