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
e56de77d
Commit
e56de77d
authored
Jan 05, 2011
by
Colin Snover
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaning up trailing whitespace again.
parent
ae6655bc
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
295 additions
and
295 deletions
+295
-295
ajax.js
src/ajax.js
+122
-122
core.js
src/core.js
+32
-32
jsonp.js
src/transports/jsonp.js
+13
-13
script.js
src/transports/script.js
+16
-16
xhr.js
src/transports/xhr.js
+43
-43
ajax.js
test/unit/ajax.js
+3
-3
core.js
test/unit/core.js
+66
-66
No files found.
src/ajax.js
View file @
e56de77d
This diff is collapsed.
Click to expand it.
src/core.js
View file @
e56de77d
...
@@ -59,7 +59,7 @@ var jQuery = function( selector, context ) {
...
@@ -59,7 +59,7 @@ var jQuery = function( selector, context ) {
// Has the ready events already been bound?
// Has the ready events already been bound?
readyBound
=
false
,
readyBound
=
false
,
// The deferred used on DOM ready
// The deferred used on DOM ready
readyList
,
readyList
,
...
@@ -252,11 +252,11 @@ jQuery.fn = jQuery.prototype = {
...
@@ -252,11 +252,11 @@ jQuery.fn = jQuery.prototype = {
each
:
function
(
callback
,
args
)
{
each
:
function
(
callback
,
args
)
{
return
jQuery
.
each
(
this
,
callback
,
args
);
return
jQuery
.
each
(
this
,
callback
,
args
);
},
},
ready
:
function
()
{
ready
:
function
()
{
// Attach the listeners
// Attach the listeners
jQuery
.
bindReady
();
jQuery
.
bindReady
();
// Change ready & apply
// Change ready & apply
return
(
jQuery
.
fn
.
ready
=
readyList
.
complete
).
apply
(
this
,
arguments
);
return
(
jQuery
.
fn
.
ready
=
readyList
.
complete
).
apply
(
this
,
arguments
);
},
},
...
@@ -406,7 +406,7 @@ jQuery.extend({
...
@@ -406,7 +406,7 @@ jQuery.extend({
// If there are functions bound, to execute
// If there are functions bound, to execute
readyList
.
fire
(
document
,
[
jQuery
]
);
readyList
.
fire
(
document
,
[
jQuery
]
);
// Trigger any bound ready events
// Trigger any bound ready events
if
(
jQuery
.
fn
.
trigger
)
{
if
(
jQuery
.
fn
.
trigger
)
{
jQuery
(
document
).
trigger
(
"ready"
).
unbind
(
"ready"
);
jQuery
(
document
).
trigger
(
"ready"
).
unbind
(
"ready"
);
...
@@ -543,7 +543,7 @@ jQuery.extend({
...
@@ -543,7 +543,7 @@ jQuery.extend({
jQuery
.
error
(
"Invalid JSON: "
+
data
);
jQuery
.
error
(
"Invalid JSON: "
+
data
);
}
}
},
},
// Cross-browser xml parsing
// Cross-browser xml parsing
// (xml & tmp used internally)
// (xml & tmp used internally)
parseXML
:
function
(
data
,
xml
,
tmp
)
{
parseXML
:
function
(
data
,
xml
,
tmp
)
{
...
@@ -556,13 +556,13 @@ jQuery.extend({
...
@@ -556,13 +556,13 @@ jQuery.extend({
xml
.
async
=
"false"
;
xml
.
async
=
"false"
;
xml
.
loadXML
(
data
);
xml
.
loadXML
(
data
);
}
}
tmp
=
xml
.
documentElement
;
tmp
=
xml
.
documentElement
;
if
(
!
tmp
||
!
tmp
.
nodeName
||
tmp
.
nodeName
===
"parsererror"
)
{
if
(
!
tmp
||
!
tmp
.
nodeName
||
tmp
.
nodeName
===
"parsererror"
)
{
jQuery
.
error
(
"Invalid XML: "
+
data
);
jQuery
.
error
(
"Invalid XML: "
+
data
);
}
}
return
xml
;
return
xml
;
},
},
...
@@ -800,10 +800,10 @@ jQuery.extend({
...
@@ -800,10 +800,10 @@ jQuery.extend({
now
:
function
()
{
now
:
function
()
{
return
(
new
Date
()).
getTime
();
return
(
new
Date
()).
getTime
();
},
},
// Create a simple deferred (one callbacks list)
// Create a simple deferred (one callbacks list)
_Deferred
:
function
()
{
_Deferred
:
function
()
{
var
// callbacks list
var
// callbacks list
callbacks
=
[],
callbacks
=
[],
// stored [ context , args ]
// stored [ context , args ]
...
@@ -814,24 +814,24 @@ jQuery.extend({
...
@@ -814,24 +814,24 @@ jQuery.extend({
cancelled
,
cancelled
,
// the deferred itself
// the deferred itself
deferred
=
{
deferred
=
{
// complete( f1, f2, ...)
// complete( f1, f2, ...)
complete
:
function
()
{
complete
:
function
()
{
if
(
!
cancelled
)
{
if
(
!
cancelled
)
{
var
args
=
arguments
,
var
args
=
arguments
,
i
,
i
,
length
,
length
,
elem
,
elem
,
type
,
type
,
_fired
;
_fired
;
if
(
fired
)
{
if
(
fired
)
{
_fired
=
fired
;
_fired
=
fired
;
fired
=
0
;
fired
=
0
;
}
}
for
(
i
=
0
,
length
=
args
.
length
;
i
<
length
;
i
++
)
{
for
(
i
=
0
,
length
=
args
.
length
;
i
<
length
;
i
++
)
{
elem
=
args
[
i
];
elem
=
args
[
i
];
type
=
jQuery
.
type
(
elem
);
type
=
jQuery
.
type
(
elem
);
...
@@ -841,21 +841,21 @@ jQuery.extend({
...
@@ -841,21 +841,21 @@ jQuery.extend({
callbacks
.
push
(
elem
);
callbacks
.
push
(
elem
);
}
}
}
}
if
(
_fired
)
{
if
(
_fired
)
{
deferred
.
fire
(
_fired
[
0
]
,
_fired
[
1
]
);
deferred
.
fire
(
_fired
[
0
]
,
_fired
[
1
]
);
}
}
}
}
return
this
;
return
this
;
},
},
// resolve with given context and args
// resolve with given context and args
fire
:
function
(
context
,
args
)
{
fire
:
function
(
context
,
args
)
{
if
(
!
cancelled
&&
!
fired
&&
!
firing
)
{
if
(
!
cancelled
&&
!
fired
&&
!
firing
)
{
firing
=
1
;
firing
=
1
;
try
{
try
{
while
(
callbacks
[
0
]
)
{
while
(
callbacks
[
0
]
)
{
callbacks
.
shift
().
apply
(
context
,
args
);
callbacks
.
shift
().
apply
(
context
,
args
);
...
@@ -868,18 +868,18 @@ jQuery.extend({
...
@@ -868,18 +868,18 @@ jQuery.extend({
}
}
return
this
;
return
this
;
},
},
// resolve with this as context and given arguments
// resolve with this as context and given arguments
resolve
:
function
()
{
resolve
:
function
()
{
deferred
.
fire
(
jQuery
.
isFunction
(
this
.
promise
)
?
this
.
promise
()
:
this
,
arguments
);
deferred
.
fire
(
jQuery
.
isFunction
(
this
.
promise
)
?
this
.
promise
()
:
this
,
arguments
);
return
this
;
return
this
;
},
},
// Has this deferred been resolved?
// Has this deferred been resolved?
isResolved
:
function
()
{
isResolved
:
function
()
{
return
!!
(
firing
||
fired
);
return
!!
(
firing
||
fired
);
},
},
// Cancel
// Cancel
cancel
:
function
()
{
cancel
:
function
()
{
cancelled
=
1
;
cancelled
=
1
;
...
@@ -887,18 +887,18 @@ jQuery.extend({
...
@@ -887,18 +887,18 @@ jQuery.extend({
return
this
;
return
this
;
}
}
};
};
return
deferred
;
return
deferred
;
},
},
// Full fledged deferred (two callbacks list)
// Full fledged deferred (two callbacks list)
// Typical success/error system
// Typical success/error system
Deferred
:
function
(
func
)
{
Deferred
:
function
(
func
)
{
var
deferred
=
jQuery
.
_Deferred
(),
var
deferred
=
jQuery
.
_Deferred
(),
failDeferred
=
jQuery
.
_Deferred
();
failDeferred
=
jQuery
.
_Deferred
();
// Add errorDeferred methods and redefine cancel
// Add errorDeferred methods and redefine cancel
jQuery
.
extend
(
deferred
,
{
jQuery
.
extend
(
deferred
,
{
then
:
function
(
completeCallbacks
,
failCallbacks
)
{
then
:
function
(
completeCallbacks
,
failCallbacks
)
{
...
@@ -923,18 +923,18 @@ jQuery.extend({
...
@@ -923,18 +923,18 @@ jQuery.extend({
}
}
}
);
}
);
// Make sure only one callback list will be used
// Make sure only one callback list will be used
deferred
.
then
(
failDeferred
.
cancel
,
deferred
.
cancel
);
deferred
.
then
(
failDeferred
.
cancel
,
deferred
.
cancel
);
// Unexpose cancel
// Unexpose cancel
delete
deferred
.
cancel
;
delete
deferred
.
cancel
;
// Call given func if any
// Call given func if any
if
(
func
)
{
if
(
func
)
{
func
.
call
(
deferred
,
deferred
);
func
.
call
(
deferred
,
deferred
);
}
}
return
deferred
;
return
deferred
;
},
},
...
...
src/transports/jsonp.js
View file @
e56de77d
...
@@ -15,11 +15,11 @@ jQuery.ajaxSettings.jsonpCallback = function() {
...
@@ -15,11 +15,11 @@ jQuery.ajaxSettings.jsonpCallback = function() {
// 3) ensure options jsonp is always provided so that jsonp requests are always
// 3) ensure options jsonp is always provided so that jsonp requests are always
// json request with the jsonp option set
// json request with the jsonp option set
jQuery
.
ajax
.
prefilter
(
"json jsonp"
,
function
(
s
)
{
jQuery
.
ajax
.
prefilter
(
"json jsonp"
,
function
(
s
)
{
var
transportDataType
=
s
.
dataTypes
[
0
];
var
transportDataType
=
s
.
dataTypes
[
0
];
s
.
dataTypes
[
0
]
=
"json"
;
s
.
dataTypes
[
0
]
=
"json"
;
if
(
s
.
jsonp
||
if
(
s
.
jsonp
||
transportDataType
===
"jsonp"
||
transportDataType
===
"jsonp"
||
transportDataType
===
"json"
&&
(
jsre
.
test
(
s
.
url
)
||
typeof
(
s
.
data
)
===
"string"
&&
jsre
.
test
(
s
.
data
)
)
)
{
transportDataType
===
"json"
&&
(
jsre
.
test
(
s
.
url
)
||
typeof
(
s
.
data
)
===
"string"
&&
jsre
.
test
(
s
.
data
)
)
)
{
...
@@ -29,34 +29,34 @@ jQuery.ajax.prefilter("json jsonp", function(s) {
...
@@ -29,34 +29,34 @@ jQuery.ajax.prefilter("json jsonp", function(s) {
jQuery
.
isFunction
(
s
.
jsonpCallback
)
?
s
.
jsonpCallback
()
:
s
.
jsonpCallback
,
jQuery
.
isFunction
(
s
.
jsonpCallback
)
?
s
.
jsonpCallback
()
:
s
.
jsonpCallback
,
url
=
s
.
url
.
replace
(
jsre
,
"="
+
jsonpCallback
+
"$1"
),
url
=
s
.
url
.
replace
(
jsre
,
"="
+
jsonpCallback
+
"$1"
),
data
=
s
.
url
==
url
&&
typeof
(
s
.
data
)
===
"string"
?
s
.
data
.
replace
(
jsre
,
"="
+
jsonpCallback
+
"$1"
)
:
s
.
data
;
data
=
s
.
url
==
url
&&
typeof
(
s
.
data
)
===
"string"
?
s
.
data
.
replace
(
jsre
,
"="
+
jsonpCallback
+
"$1"
)
:
s
.
data
;
if
(
url
==
s
.
url
&&
data
==
s
.
data
)
{
if
(
url
==
s
.
url
&&
data
==
s
.
data
)
{
url
=
url
+=
(
rquery_jsonp
.
test
(
url
)
?
"&"
:
"?"
)
+
jsonp
+
"="
+
jsonpCallback
;
url
=
url
+=
(
rquery_jsonp
.
test
(
url
)
?
"&"
:
"?"
)
+
jsonp
+
"="
+
jsonpCallback
;
}
}
s
.
url
=
url
;
s
.
url
=
url
;
s
.
data
=
data
;
s
.
data
=
data
;
}
}
// Bind transport to json dataType
// Bind transport to json dataType
}).
transport
(
"json"
,
function
(
s
)
{
}).
transport
(
"json"
,
function
(
s
)
{
if
(
s
.
jsonp
)
{
if
(
s
.
jsonp
)
{
// Put callback in place
// Put callback in place
var
responseContainer
,
var
responseContainer
,
jsonpCallback
=
s
.
jsonpCallback
,
jsonpCallback
=
s
.
jsonpCallback
,
previous
=
window
[
jsonpCallback
];
previous
=
window
[
jsonpCallback
];
window
[
jsonpCallback
]
=
function
(
response
)
{
window
[
jsonpCallback
]
=
function
(
response
)
{
responseContainer
=
[
response
];
responseContainer
=
[
response
];
};
};
s
.
complete
=
[
function
()
{
s
.
complete
=
[
function
()
{
// Set callback back to previous value
// Set callback back to previous value
window
[
jsonpCallback
]
=
previous
;
window
[
jsonpCallback
]
=
previous
;
// Call if it was a function and we have a response
// Call if it was a function and we have a response
if
(
previous
)
{
if
(
previous
)
{
if
(
responseContainer
&&
jQuery
.
isFunction
(
previous
)
)
{
if
(
responseContainer
&&
jQuery
.
isFunction
(
previous
)
)
{
...
@@ -66,9 +66,9 @@ jQuery.ajax.prefilter("json jsonp", function(s) {
...
@@ -66,9 +66,9 @@ jQuery.ajax.prefilter("json jsonp", function(s) {
// else, more memory leak avoidance
// else, more memory leak avoidance
try
{
delete
window
[
jsonpCallback
];
}
catch
(
e
){}
try
{
delete
window
[
jsonpCallback
];
}
catch
(
e
){}
}
}
},
s
.
complete
];
},
s
.
complete
];
// Use data converter to retrieve json after script execution
// Use data converter to retrieve json after script execution
s
.
converters
[
"script json"
]
=
function
()
{
s
.
converters
[
"script json"
]
=
function
()
{
if
(
!
responseContainer
)
{
if
(
!
responseContainer
)
{
...
@@ -76,7 +76,7 @@ jQuery.ajax.prefilter("json jsonp", function(s) {
...
@@ -76,7 +76,7 @@ jQuery.ajax.prefilter("json jsonp", function(s) {
}
}
return
responseContainer
[
0
];
return
responseContainer
[
0
];
};
};
// Delegate to script transport
// Delegate to script transport
return
"script"
;
return
"script"
;
}
}
...
...
src/transports/script.js
View file @
e56de77d
...
@@ -6,11 +6,11 @@ jQuery.extend( true, jQuery.ajaxSettings , {
...
@@ -6,11 +6,11 @@ jQuery.extend( true, jQuery.ajaxSettings , {
accepts
:
{
accepts
:
{
script
:
"text/javascript, application/javascript"
script
:
"text/javascript, application/javascript"
},
},
contents
:
{
contents
:
{
script
:
/javascript/
script
:
/javascript/
},
},
converters
:
{
converters
:
{
"text script"
:
jQuery
.
globalEval
"text script"
:
jQuery
.
globalEval
}
}
...
@@ -18,22 +18,22 @@ jQuery.extend( true, jQuery.ajaxSettings , {
...
@@ -18,22 +18,22 @@ jQuery.extend( true, jQuery.ajaxSettings , {
// Bind script tag hack transport
// Bind script tag hack transport
jQuery
.
ajax
.
transport
(
"script"
,
function
(
s
)
{
jQuery
.
ajax
.
transport
(
"script"
,
function
(
s
)
{
// Handle cache special case
// Handle cache special case
if
(
s
.
cache
===
undefined
)
{
if
(
s
.
cache
===
undefined
)
{
s
.
cache
=
false
;
s
.
cache
=
false
;
}
}
// This transport only deals with cross domain get requests
// This transport only deals with cross domain get requests
if
(
s
.
crossDomain
&&
s
.
async
&&
(
s
.
type
===
"GET"
||
!
s
.
data
)
)
{
if
(
s
.
crossDomain
&&
s
.
async
&&
(
s
.
type
===
"GET"
||
!
s
.
data
)
)
{
s
.
global
=
false
;
s
.
global
=
false
;
var
script
,
var
script
,
head
=
document
.
getElementsByTagName
(
"head"
)[
0
]
||
document
.
documentElement
;
head
=
document
.
getElementsByTagName
(
"head"
)[
0
]
||
document
.
documentElement
;
return
{
return
{
send
:
function
(
_
,
callback
)
{
send
:
function
(
_
,
callback
)
{
script
=
document
.
createElement
(
"script"
);
script
=
document
.
createElement
(
"script"
);
...
@@ -43,24 +43,24 @@ jQuery.ajax.transport("script", function(s) {
...
@@ -43,24 +43,24 @@ jQuery.ajax.transport("script", function(s) {
if
(
s
.
scriptCharset
)
{
if
(
s
.
scriptCharset
)
{
script
.
charset
=
s
.
scriptCharset
;
script
.
charset
=
s
.
scriptCharset
;
}
}
script
.
src
=
s
.
url
;
script
.
src
=
s
.
url
;
// Attach handlers for all browsers
// Attach handlers for all browsers
script
.
onload
=
script
.
onreadystatechange
=
function
(
_
,
statusText
)
{
script
.
onload
=
script
.
onreadystatechange
=
function
(
_
,
statusText
)
{
if
(
!
script
.
readyState
||
/loaded|complete/
.
test
(
script
.
readyState
)
)
{
if
(
!
script
.
readyState
||
/loaded|complete/
.
test
(
script
.
readyState
)
)
{
// Handle memory leak in IE
// Handle memory leak in IE
script
.
onload
=
script
.
onreadystatechange
=
null
;
script
.
onload
=
script
.
onreadystatechange
=
null
;
// Remove the script
// Remove the script
if
(
head
&&
script
.
parentNode
)
{
if
(
head
&&
script
.
parentNode
)
{
head
.
removeChild
(
script
);
head
.
removeChild
(
script
);
}
}
script
=
0
;
script
=
0
;
// Callback
// Callback
callback
(
statusText
?
0
:
200
,
statusText
||
"success"
);
callback
(
statusText
?
0
:
200
,
statusText
||
"success"
);
}
}
...
@@ -69,7 +69,7 @@ jQuery.ajax.transport("script", function(s) {
...
@@ -69,7 +69,7 @@ jQuery.ajax.transport("script", function(s) {
// This arises when a base node is used (#2709 and #4378).
// This arises when a base node is used (#2709 and #4378).
head
.
insertBefore
(
script
,
head
.
firstChild
);
head
.
insertBefore
(
script
,
head
.
firstChild
);
},
},
abort
:
function
(
statusText
)
{
abort
:
function
(
statusText
)
{
if
(
script
)
{
if
(
script
)
{
script
.
onload
(
0
,
statusText
);
script
.
onload
(
0
,
statusText
);
...
...
src/transports/xhr.js
View file @
e56de77d
...
@@ -2,28 +2,28 @@
...
@@ -2,28 +2,28 @@
var
// Next fake timer id
var
// Next fake timer id
xhrPollingId
=
jQuery
.
now
(),
xhrPollingId
=
jQuery
.
now
(),
// Callbacks hashtable
// Callbacks hashtable
xhrs
=
{},
xhrs
=
{},
// #5280: see end of file
// #5280: see end of file
xhrUnloadAbortMarker
=
[];
xhrUnloadAbortMarker
=
[];
jQuery
.
ajax
.
transport
(
function
(
s
,
determineDataType
)
{
jQuery
.
ajax
.
transport
(
function
(
s
,
determineDataType
)
{
// Cross domain only allowed if supported through XMLHttpRequest
// Cross domain only allowed if supported through XMLHttpRequest
if
(
!
s
.
crossDomain
||
jQuery
.
support
.
cors
)
{
if
(
!
s
.
crossDomain
||
jQuery
.
support
.
cors
)
{
var
callback
;
var
callback
;
return
{
return
{
send
:
function
(
headers
,
complete
)
{
send
:
function
(
headers
,
complete
)
{
var
xhr
=
s
.
xhr
(),
var
xhr
=
s
.
xhr
(),
handle
;
handle
;
// Open the socket
// Open the socket
// Passing null username, generates a login popup on Opera (#2865)
// Passing null username, generates a login popup on Opera (#2865)
if
(
s
.
username
)
{
if
(
s
.
username
)
{
...
@@ -31,7 +31,7 @@ jQuery.ajax.transport( function( s , determineDataType ) {
...
@@ -31,7 +31,7 @@ jQuery.ajax.transport( function( s , determineDataType ) {
}
else
{
}
else
{
xhr
.
open
(
s
.
type
,
s
.
url
,
s
.
async
);
xhr
.
open
(
s
.
type
,
s
.
url
,
s
.
async
);
}
}
// Requested-With header
// Requested-With header
// Not set for crossDomain requests with no content
// Not set for crossDomain requests with no content
// (see why at http://trac.dojotoolkit.org/ticket/9486)
// (see why at http://trac.dojotoolkit.org/ticket/9486)
...
@@ -39,16 +39,16 @@ jQuery.ajax.transport( function( s , determineDataType ) {
...
@@ -39,16 +39,16 @@ jQuery.ajax.transport( function( s , determineDataType ) {
if
(
!
(
s
.
crossDomain
&&
!
s
.
hasContent
)
&&
!
headers
[
"x-requested-with"
]
)
{
if
(
!
(
s
.
crossDomain
&&
!
s
.
hasContent
)
&&
!
headers
[
"x-requested-with"
]
)
{
headers
[
"x-requested-with"
]
=
"XMLHttpRequest"
;
headers
[
"x-requested-with"
]
=
"XMLHttpRequest"
;
}
}
// Need an extra try/catch for cross domain requests in Firefox 3
// Need an extra try/catch for cross domain requests in Firefox 3
try
{
try
{
jQuery
.
each
(
headers
,
function
(
key
,
value
)
{
jQuery
.
each
(
headers
,
function
(
key
,
value
)
{
xhr
.
setRequestHeader
(
key
,
value
);
xhr
.
setRequestHeader
(
key
,
value
);
});
});
}
catch
(
_
)
{}
}
catch
(
_
)
{}
// Do send the request
// Do send the request
try
{
try
{
xhr
.
send
(
(
s
.
hasContent
&&
s
.
data
)
||
null
);
xhr
.
send
(
(
s
.
hasContent
&&
s
.
data
)
||
null
);
...
@@ -56,55 +56,55 @@ jQuery.ajax.transport( function( s , determineDataType ) {
...
@@ -56,55 +56,55 @@ jQuery.ajax.transport( function( s , determineDataType ) {
complete
(
0
,
"error"
,
""
+
e
);
complete
(
0
,
"error"
,
""
+
e
);
return
;
return
;
}
}
// Listener
// Listener
callback
=
function
(
abortStatusText
)
{
callback
=
function
(
abortStatusText
)
{
// Was never called and is aborted or complete
// Was never called and is aborted or complete
if
(
callback
&&
(
abortStatusText
||
xhr
.
readyState
===
4
)
)
{
if
(
callback
&&
(
abortStatusText
||
xhr
.
readyState
===
4
)
)
{
// Do not listen anymore
// Do not listen anymore
if
(
handle
)
{
if
(
handle
)
{
xhr
.
onreadystatechange
=
jQuery
.
noop
;
xhr
.
onreadystatechange
=
jQuery
.
noop
;
delete
xhrs
[
handle
];
delete
xhrs
[
handle
];
handle
=
undefined
;
handle
=
undefined
;
}
}
callback
=
0
;
callback
=
0
;
// Get info
// Get info
var
status
,
statusText
,
response
,
responseHeaders
;
var
status
,
statusText
,
response
,
responseHeaders
;
if
(
abortStatusText
)
{
if
(
abortStatusText
)
{
if
(
xhr
.
readyState
!==
4
)
{
if
(
xhr
.
readyState
!==
4
)
{
xhr
.
abort
();
xhr
.
abort
();
}
}
// Stop here if unloadAbort
// Stop here if unloadAbort
if
(
abortStatusText
===
xhrUnloadAbortMarker
)
{
if
(
abortStatusText
===
xhrUnloadAbortMarker
)
{
return
;
return
;
}
}
status
=
0
;
status
=
0
;
statusText
=
abortStatusText
;
statusText
=
abortStatusText
;
}
else
{
}
else
{
status
=
xhr
.
status
;
status
=
xhr
.
status
;
try
{
// Firefox throws an exception when accessing statusText for faulty cross-domain requests
try
{
// Firefox throws an exception when accessing statusText for faulty cross-domain requests
statusText
=
xhr
.
statusText
;
statusText
=
xhr
.
statusText
;
}
catch
(
e
)
{
}
catch
(
e
)
{
statusText
=
""
;
// We normalize with Webkit giving an empty statusText
statusText
=
""
;
// We normalize with Webkit giving an empty statusText
}
}
responseHeaders
=
xhr
.
getAllResponseHeaders
();
responseHeaders
=
xhr
.
getAllResponseHeaders
();
// Filter status for non standard behaviours
// Filter status for non standard behaviours
// (so many they seem to be the actual "standard")
// (so many they seem to be the actual "standard")
status
=
status
=
...
@@ -129,10 +129,10 @@ jQuery.ajax.transport( function( s , determineDataType ) {
...
@@ -129,10 +129,10 @@ jQuery.ajax.transport( function( s , determineDataType ) {
:
:
status
status
);
);
// Guess response if needed & update datatype accordingly
// Guess response if needed & update datatype accordingly
if
(
status
>=
200
&&
status
<
300
)
{
if
(
status
>=
200
&&
status
<
300
)
{
response
=
response
=
determineDataType
(
determineDataType
(
s
,
s
,
xhr
.
getResponseHeader
(
"content-type"
),
xhr
.
getResponseHeader
(
"content-type"
),
...
@@ -140,30 +140,30 @@ jQuery.ajax.transport( function( s , determineDataType ) {
...
@@ -140,30 +140,30 @@ jQuery.ajax.transport( function( s , determineDataType ) {
xhr
.
responseXML
);
xhr
.
responseXML
);
}
}
}
}
// Call complete
// Call complete
complete
(
status
,
statusText
,
response
,
responseHeaders
);
complete
(
status
,
statusText
,
response
,
responseHeaders
);
}
}
};
};
// if we're in sync mode
// if we're in sync mode
// or it's in cache and has been retrieved directly (IE6 & IE7)
// or it's in cache and has been retrieved directly (IE6 & IE7)
// we need to manually fire the callback
// we need to manually fire the callback
if
(
!
s
.
async
||
xhr
.
readyState
===
4
)
{
if
(
!
s
.
async
||
xhr
.
readyState
===
4
)
{
callback
();
callback
();
}
else
{
}
else
{
// Listener is externalized to handle abort on unload
// Listener is externalized to handle abort on unload
handle
=
xhrPollingId
++
;
handle
=
xhrPollingId
++
;
xhrs
[
handle
]
=
xhr
;
xhrs
[
handle
]
=
xhr
;
xhr
.
onreadystatechange
=
function
()
{
xhr
.
onreadystatechange
=
function
()
{
callback
();
callback
();
};
};
}
}
},
},
abort
:
function
(
statusText
)
{
abort
:
function
(
statusText
)
{
if
(
callback
)
{
if
(
callback
)
{
callback
(
statusText
);
callback
(
statusText
);
...
@@ -175,17 +175,17 @@ jQuery.ajax.transport( function( s , determineDataType ) {
...
@@ -175,17 +175,17 @@ jQuery.ajax.transport( function( s , determineDataType ) {
// #5280: we need to abort on unload or IE will keep connections alive
// #5280: we need to abort on unload or IE will keep connections alive
jQuery
(
window
).
bind
(
"unload"
,
function
()
{
jQuery
(
window
).
bind
(
"unload"
,
function
()
{
// Abort all pending requests
// Abort all pending requests
jQuery
.
each
(
xhrs
,
function
(
_
,
xhr
)
{
jQuery
.
each
(
xhrs
,
function
(
_
,
xhr
)
{
if
(
xhr
.
onreadystatechange
)
{
if
(
xhr
.
onreadystatechange
)
{
xhr
.
onreadystatechange
(
xhrUnloadAbortMarker
);
xhr
.
onreadystatechange
(
xhrUnloadAbortMarker
);
}
}
});
});
// Resest polling structure to be safe
// Resest polling structure to be safe
xhrs
=
{};
xhrs
=
{};
});
});
})(
jQuery
);
})(
jQuery
);
test/unit/ajax.js
View file @
e56de77d
...
@@ -1638,7 +1638,7 @@ test("jQuery ajax - failing cross-domain", function() {
...
@@ -1638,7 +1638,7 @@ test("jQuery ajax - failing cross-domain", function() {
stop
();
stop
();
var
i
=
2
;
var
i
=
2
;
if
(
jQuery
.
ajax
({
if
(
jQuery
.
ajax
({
url
:
'http://somewebsitethatdoesnotexist-67864863574657654.com'
,
url
:
'http://somewebsitethatdoesnotexist-67864863574657654.com'
,
success
:
function
(){
ok
(
false
,
"success"
);
},
success
:
function
(){
ok
(
false
,
"success"
);
},
...
@@ -1648,7 +1648,7 @@ test("jQuery ajax - failing cross-domain", function() {
...
@@ -1648,7 +1648,7 @@ test("jQuery ajax - failing cross-domain", function() {
ok
(
true
,
"no transport"
);
ok
(
true
,
"no transport"
);
if
(
!
--
i
)
start
();
if
(
!
--
i
)
start
();
}
}
if
(
jQuery
.
ajax
({
if
(
jQuery
.
ajax
({
url
:
'http://www.google.com'
,
url
:
'http://www.google.com'
,
success
:
function
(){
ok
(
false
,
"success"
);
},
success
:
function
(){
ok
(
false
,
"success"
);
},
...
@@ -1658,7 +1658,7 @@ test("jQuery ajax - failing cross-domain", function() {
...
@@ -1658,7 +1658,7 @@ test("jQuery ajax - failing cross-domain", function() {
ok
(
true
,
"no transport"
);
ok
(
true
,
"no transport"
);
if
(
!
--
i
)
start
();
if
(
!
--
i
)
start
();
}
}
});
});
test
(
"jQuery ajax - atom+xml"
,
function
()
{
test
(
"jQuery ajax - atom+xml"
,
function
()
{
...
...
test/unit/core.js
View file @
e56de77d
...
@@ -151,7 +151,7 @@ test("selector state", function() {
...
@@ -151,7 +151,7 @@ test("selector state", function() {
test
=
jQuery
(
"#main"
).
eq
(
0
);
test
=
jQuery
(
"#main"
).
eq
(
0
);
equals
(
test
.
selector
,
"#main.slice(0,1)"
,
"#main eq Selector"
);
equals
(
test
.
selector
,
"#main.slice(0,1)"
,
"#main eq Selector"
);
equals
(
test
.
context
,
document
,
"#main eq Context"
);
equals
(
test
.
context
,
document
,
"#main eq Context"
);
var
d
=
"<div />"
;
var
d
=
"<div />"
;
equals
(
equals
(
jQuery
(
d
).
appendTo
(
jQuery
(
d
)).
selector
,
jQuery
(
d
).
appendTo
(
jQuery
(
d
)).
selector
,
...
@@ -253,38 +253,38 @@ test("isPlainObject", function() {
...
@@ -253,38 +253,38 @@ test("isPlainObject", function() {
// The use case that we want to match
// The use case that we want to match
ok
(
jQuery
.
isPlainObject
({}),
"{}"
);
ok
(
jQuery
.
isPlainObject
({}),
"{}"
);
// Not objects shouldn't be matched
// Not objects shouldn't be matched
ok
(
!
jQuery
.
isPlainObject
(
""
),
"string"
);
ok
(
!
jQuery
.
isPlainObject
(
""
),
"string"
);
ok
(
!
jQuery
.
isPlainObject
(
0
)
&&
!
jQuery
.
isPlainObject
(
1
),
"number"
);
ok
(
!
jQuery
.
isPlainObject
(
0
)
&&
!
jQuery
.
isPlainObject
(
1
),
"number"
);
ok
(
!
jQuery
.
isPlainObject
(
true
)
&&
!
jQuery
.
isPlainObject
(
false
),
"boolean"
);
ok
(
!
jQuery
.
isPlainObject
(
true
)
&&
!
jQuery
.
isPlainObject
(
false
),
"boolean"
);
ok
(
!
jQuery
.
isPlainObject
(
null
),
"null"
);
ok
(
!
jQuery
.
isPlainObject
(
null
),
"null"
);
ok
(
!
jQuery
.
isPlainObject
(
undefined
),
"undefined"
);
ok
(
!
jQuery
.
isPlainObject
(
undefined
),
"undefined"
);
// Arrays shouldn't be matched
// Arrays shouldn't be matched
ok
(
!
jQuery
.
isPlainObject
([]),
"array"
);
ok
(
!
jQuery
.
isPlainObject
([]),
"array"
);
// Instantiated objects shouldn't be matched
// Instantiated objects shouldn't be matched
ok
(
!
jQuery
.
isPlainObject
(
new
Date
),
"new Date"
);
ok
(
!
jQuery
.
isPlainObject
(
new
Date
),
"new Date"
);
var
fn
=
function
(){};
var
fn
=
function
(){};
// Functions shouldn't be matched
// Functions shouldn't be matched
ok
(
!
jQuery
.
isPlainObject
(
fn
),
"fn"
);
ok
(
!
jQuery
.
isPlainObject
(
fn
),
"fn"
);
// Again, instantiated objects shouldn't be matched
// Again, instantiated objects shouldn't be matched
ok
(
!
jQuery
.
isPlainObject
(
new
fn
),
"new fn (no methods)"
);
ok
(
!
jQuery
.
isPlainObject
(
new
fn
),
"new fn (no methods)"
);
// Makes the function a little more realistic
// Makes the function a little more realistic
// (and harder to detect, incidentally)
// (and harder to detect, incidentally)
fn
.
prototype
=
{
someMethod
:
function
(){}};
fn
.
prototype
=
{
someMethod
:
function
(){}};
// Again, instantiated objects shouldn't be matched
// Again, instantiated objects shouldn't be matched
ok
(
!
jQuery
.
isPlainObject
(
new
fn
),
"new fn"
);
ok
(
!
jQuery
.
isPlainObject
(
new
fn
),
"new fn"
);
// DOM Element
// DOM Element
ok
(
!
jQuery
.
isPlainObject
(
document
.
createElement
(
"div"
)),
"DOM Element"
);
ok
(
!
jQuery
.
isPlainObject
(
document
.
createElement
(
"div"
)),
"DOM Element"
);
// Window
// Window
ok
(
!
jQuery
.
isPlainObject
(
window
),
"window"
);
ok
(
!
jQuery
.
isPlainObject
(
window
),
"window"
);
...
@@ -298,7 +298,7 @@ test("isPlainObject", function() {
...
@@ -298,7 +298,7 @@ test("isPlainObject", function() {
document
.
body
.
removeChild
(
iframe
);
document
.
body
.
removeChild
(
iframe
);
start
();
start
();
};
};
var
doc
=
iframe
.
contentDocument
||
iframe
.
contentWindow
.
document
;
var
doc
=
iframe
.
contentDocument
||
iframe
.
contentWindow
.
document
;
doc
.
open
();
doc
.
open
();
doc
.
write
(
"<body onload='window.parent.iframeDone(Object);'>"
);
doc
.
write
(
"<body onload='window.parent.iframeDone(Object);'>"
);
...
@@ -659,7 +659,7 @@ test("jQuery.merge()", function() {
...
@@ -659,7 +659,7 @@ test("jQuery.merge()", function() {
// Fixed at [5998], #3641
// Fixed at [5998], #3641
same
(
parse
([
-
2
,
-
1
],
[
0
,
1
,
2
]),
[
-
2
,
-
1
,
0
,
1
,
2
],
"Second array including a zero (falsy)"
);
same
(
parse
([
-
2
,
-
1
],
[
0
,
1
,
2
]),
[
-
2
,
-
1
,
0
,
1
,
2
],
"Second array including a zero (falsy)"
);
// After fixing #5527
// After fixing #5527
same
(
parse
([],
[
null
,
undefined
]),
[
null
,
undefined
],
"Second array including null and undefined values"
);
same
(
parse
([],
[
null
,
undefined
]),
[
null
,
undefined
],
"Second array including null and undefined values"
);
same
(
parse
({
length
:
0
},
[
1
,
2
]),
{
length
:
2
,
0
:
1
,
1
:
2
},
"First array like"
);
same
(
parse
({
length
:
0
},
[
1
,
2
]),
{
length
:
2
,
0
:
1
,
1
:
2
},
"First array like"
);
...
@@ -694,7 +694,7 @@ test("jQuery.extend(Object, Object)", function() {
...
@@ -694,7 +694,7 @@ test("jQuery.extend(Object, Object)", function() {
equals
(
deep1
.
foo2
,
document
,
"Make sure that a deep clone was not attempted on the document"
);
equals
(
deep1
.
foo2
,
document
,
"Make sure that a deep clone was not attempted on the document"
);
ok
(
jQuery
.
extend
(
true
,
{},
nestedarray
).
arr
!==
arr
,
"Deep extend of object must clone child array"
);
ok
(
jQuery
.
extend
(
true
,
{},
nestedarray
).
arr
!==
arr
,
"Deep extend of object must clone child array"
);
// #5991
// #5991
ok
(
jQuery
.
isArray
(
jQuery
.
extend
(
true
,
{
arr
:
{}
},
nestedarray
).
arr
),
"Cloned array heve to be an Array"
);
ok
(
jQuery
.
isArray
(
jQuery
.
extend
(
true
,
{
arr
:
{}
},
nestedarray
).
arr
),
"Cloned array heve to be an Array"
);
ok
(
jQuery
.
isPlainObject
(
jQuery
.
extend
(
true
,
{
arr
:
arr
},
{
arr
:
{}
}).
arr
),
"Cloned object heve to be an plain object"
);
ok
(
jQuery
.
isPlainObject
(
jQuery
.
extend
(
true
,
{
arr
:
arr
},
{
arr
:
{}
}).
arr
),
"Cloned object heve to be an plain object"
);
...
@@ -715,13 +715,13 @@ test("jQuery.extend(Object, Object)", function() {
...
@@ -715,13 +715,13 @@ test("jQuery.extend(Object, Object)", function() {
empty
=
{};
empty
=
{};
jQuery
.
extend
(
true
,
empty
,
optionsWithCustomObject
);
jQuery
.
extend
(
true
,
empty
,
optionsWithCustomObject
);
ok
(
empty
.
foo
&&
empty
.
foo
.
date
===
customObject
,
"Custom objects copy correctly (no methods)"
);
ok
(
empty
.
foo
&&
empty
.
foo
.
date
===
customObject
,
"Custom objects copy correctly (no methods)"
);
// Makes the class a little more realistic
// Makes the class a little more realistic
myKlass
.
prototype
=
{
someMethod
:
function
(){}
};
myKlass
.
prototype
=
{
someMethod
:
function
(){}
};
empty
=
{};
empty
=
{};
jQuery
.
extend
(
true
,
empty
,
optionsWithCustomObject
);
jQuery
.
extend
(
true
,
empty
,
optionsWithCustomObject
);
ok
(
empty
.
foo
&&
empty
.
foo
.
date
===
customObject
,
"Custom objects copy correctly"
);
ok
(
empty
.
foo
&&
empty
.
foo
.
date
===
customObject
,
"Custom objects copy correctly"
);
var
ret
=
jQuery
.
extend
(
true
,
{
foo
:
4
},
{
foo
:
new
Number
(
5
)
}
);
var
ret
=
jQuery
.
extend
(
true
,
{
foo
:
4
},
{
foo
:
new
Number
(
5
)
}
);
ok
(
ret
.
foo
==
5
,
"Wrapped numbers copy correctly"
);
ok
(
ret
.
foo
==
5
,
"Wrapped numbers copy correctly"
);
...
@@ -849,10 +849,10 @@ test("jQuery.makeArray", function(){
...
@@ -849,10 +849,10 @@ test("jQuery.makeArray", function(){
test
(
"jQuery.isEmptyObject"
,
function
(){
test
(
"jQuery.isEmptyObject"
,
function
(){
expect
(
2
);
expect
(
2
);
equals
(
true
,
jQuery
.
isEmptyObject
({}),
"isEmptyObject on empty object literal"
);
equals
(
true
,
jQuery
.
isEmptyObject
({}),
"isEmptyObject on empty object literal"
);
equals
(
false
,
jQuery
.
isEmptyObject
({
a
:
1
}),
"isEmptyObject on non-empty object literal"
);
equals
(
false
,
jQuery
.
isEmptyObject
({
a
:
1
}),
"isEmptyObject on non-empty object literal"
);
// What about this ?
// What about this ?
// equals(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
// equals(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
});
});
...
@@ -878,23 +878,23 @@ test("jQuery.proxy", function(){
...
@@ -878,23 +878,23 @@ test("jQuery.proxy", function(){
test
(
"jQuery.parseJSON"
,
function
(){
test
(
"jQuery.parseJSON"
,
function
(){
expect
(
8
);
expect
(
8
);
equals
(
jQuery
.
parseJSON
(),
null
,
"Nothing in, null out."
);
equals
(
jQuery
.
parseJSON
(),
null
,
"Nothing in, null out."
);
equals
(
jQuery
.
parseJSON
(
null
),
null
,
"Nothing in, null out."
);
equals
(
jQuery
.
parseJSON
(
null
),
null
,
"Nothing in, null out."
);
equals
(
jQuery
.
parseJSON
(
""
),
null
,
"Nothing in, null out."
);
equals
(
jQuery
.
parseJSON
(
""
),
null
,
"Nothing in, null out."
);
same
(
jQuery
.
parseJSON
(
"{}"
),
{},
"Plain object parsing."
);
same
(
jQuery
.
parseJSON
(
"{}"
),
{},
"Plain object parsing."
);
same
(
jQuery
.
parseJSON
(
'{"test":1}'
),
{
"test"
:
1
},
"Plain object parsing."
);
same
(
jQuery
.
parseJSON
(
'{"test":1}'
),
{
"test"
:
1
},
"Plain object parsing."
);
same
(
jQuery
.
parseJSON
(
'
\
n{"test":1}'
),
{
"test"
:
1
},
"Make sure leading whitespaces are handled."
);
same
(
jQuery
.
parseJSON
(
'
\
n{"test":1}'
),
{
"test"
:
1
},
"Make sure leading whitespaces are handled."
);
try
{
try
{
jQuery
.
parseJSON
(
"{a:1}"
);
jQuery
.
parseJSON
(
"{a:1}"
);
ok
(
false
,
"Test malformed JSON string."
);
ok
(
false
,
"Test malformed JSON string."
);
}
catch
(
e
)
{
}
catch
(
e
)
{
ok
(
true
,
"Test malformed JSON string."
);
ok
(
true
,
"Test malformed JSON string."
);
}
}
try
{
try
{
jQuery
.
parseJSON
(
"{'a':1}"
);
jQuery
.
parseJSON
(
"{'a':1}"
);
ok
(
false
,
"Test malformed JSON string."
);
ok
(
false
,
"Test malformed JSON string."
);
...
@@ -904,48 +904,48 @@ test("jQuery.parseJSON", function(){
...
@@ -904,48 +904,48 @@ test("jQuery.parseJSON", function(){
});
});
test
(
"jQuery._Deferred()"
,
function
()
{
test
(
"jQuery._Deferred()"
,
function
()
{
expect
(
10
);
expect
(
10
);
var
deferred
,
var
deferred
,
object
,
object
,
test
;
test
;
deferred
=
jQuery
.
_Deferred
();
deferred
=
jQuery
.
_Deferred
();
test
=
false
;
test
=
false
;
deferred
.
complete
(
function
(
value
)
{
deferred
.
complete
(
function
(
value
)
{
equals
(
value
,
"value"
,
"Test pre-resolve callback"
);
equals
(
value
,
"value"
,
"Test pre-resolve callback"
);
test
=
true
;
test
=
true
;
}
);
}
);
deferred
.
resolve
(
"value"
);
deferred
.
resolve
(
"value"
);
ok
(
test
,
"Test pre-resolve callbacks called right away"
);
ok
(
test
,
"Test pre-resolve callbacks called right away"
);
test
=
false
;
test
=
false
;
deferred
.
complete
(
function
(
value
)
{
deferred
.
complete
(
function
(
value
)
{
equals
(
value
,
"value"
,
"Test post-resolve callback"
);
equals
(
value
,
"value"
,
"Test post-resolve callback"
);
test
=
true
;
test
=
true
;
}
);
}
);
ok
(
test
,
"Test post-resolve callbacks called right away"
);
ok
(
test
,
"Test post-resolve callbacks called right away"
);
deferred
.
cancel
();
deferred
.
cancel
();
test
=
true
;
test
=
true
;
deferred
.
complete
(
function
()
{
deferred
.
complete
(
function
()
{
ok
(
false
,
"Cancel was ignored"
);
ok
(
false
,
"Cancel was ignored"
);
test
=
false
;
test
=
false
;
}
);
}
);
ok
(
test
,
"Test cancel"
);
ok
(
test
,
"Test cancel"
);
deferred
=
jQuery
.
_Deferred
().
resolve
();
deferred
=
jQuery
.
_Deferred
().
resolve
();
try
{
try
{
deferred
.
complete
(
function
()
{
deferred
.
complete
(
function
()
{
throw
"Error"
;
throw
"Error"
;
...
@@ -956,77 +956,77 @@ test("jQuery._Deferred()", function() {
...
@@ -956,77 +956,77 @@ test("jQuery._Deferred()", function() {
strictEqual
(
e
,
"Error"
,
"Test deferred propagates exceptions"
);
strictEqual
(
e
,
"Error"
,
"Test deferred propagates exceptions"
);
deferred
.
complete
();
deferred
.
complete
();
}
}
test
=
""
;
test
=
""
;
deferred
=
jQuery
.
_Deferred
().
complete
(
function
()
{
deferred
=
jQuery
.
_Deferred
().
complete
(
function
()
{
test
+=
"A"
;
test
+=
"A"
;
},
function
()
{
},
function
()
{
test
+=
"B"
;
test
+=
"B"
;
}
).
resolve
();
}
).
resolve
();
strictEqual
(
test
,
"AB"
,
"Test multiple complete parameters"
);
strictEqual
(
test
,
"AB"
,
"Test multiple complete parameters"
);
test
=
""
;
test
=
""
;
deferred
.
complete
(
function
()
{
deferred
.
complete
(
function
()
{
deferred
.
complete
(
function
()
{
deferred
.
complete
(
function
()
{
test
+=
"C"
;
test
+=
"C"
;
}
);
}
);
test
+=
"A"
;
test
+=
"A"
;
},
function
()
{
},
function
()
{
test
+=
"B"
;
test
+=
"B"
;
}
);
}
);
strictEqual
(
test
,
"ABC"
,
"Test complete callbacks order"
);
strictEqual
(
test
,
"ABC"
,
"Test complete callbacks order"
);
deferred
=
jQuery
.
_Deferred
();
deferred
=
jQuery
.
_Deferred
();
deferred
.
fire
(
jQuery
,
[
document
]
).
complete
(
function
(
doc
)
{
deferred
.
fire
(
jQuery
,
[
document
]
).
complete
(
function
(
doc
)
{
ok
(
this
===
jQuery
&&
arguments
.
length
===
1
&&
doc
===
document
,
"Test fire context & args"
);
ok
(
this
===
jQuery
&&
arguments
.
length
===
1
&&
doc
===
document
,
"Test fire context & args"
);
});
});
});
});
test
(
"jQuery.Deferred()"
,
function
()
{
test
(
"jQuery.Deferred()"
,
function
()
{
expect
(
4
);
expect
(
4
);
jQuery
.
Deferred
(
function
(
defer
)
{
jQuery
.
Deferred
(
function
(
defer
)
{
strictEqual
(
this
,
defer
,
"Defer passed as this & first argument"
);
strictEqual
(
this
,
defer
,
"Defer passed as this & first argument"
);
this
.
resolve
(
"done"
);
this
.
resolve
(
"done"
);
}).
then
(
function
(
value
)
{
}).
then
(
function
(
value
)
{
strictEqual
(
value
,
"done"
,
"Passed function executed"
);
strictEqual
(
value
,
"done"
,
"Passed function executed"
);
});
});
jQuery
.
Deferred
().
resolve
().
then
(
function
()
{
jQuery
.
Deferred
().
resolve
().
then
(
function
()
{
ok
(
true
,
"Success on resolve"
);
ok
(
true
,
"Success on resolve"
);
},
function
()
{
},
function
()
{
ok
(
false
,
"Error on resolve"
);
ok
(
false
,
"Error on resolve"
);
});
});
jQuery
.
Deferred
().
reject
().
then
(
function
()
{
jQuery
.
Deferred
().
reject
().
then
(
function
()
{
ok
(
false
,
"Success on reject"
);
ok
(
false
,
"Success on reject"
);
},
function
()
{
},
function
()
{
ok
(
true
,
"Error on reject"
);
ok
(
true
,
"Error on reject"
);
});
});
});
});
test
(
"jQuery.when()"
,
function
()
{
test
(
"jQuery.when()"
,
function
()
{
expect
(
21
);
expect
(
21
);
// Some other objects
// Some other objects
jQuery
.
each
(
{
jQuery
.
each
(
{
"an empty string"
:
""
,
"an empty string"
:
""
,
"a non-empty string"
:
"some string"
,
"a non-empty string"
:
"some string"
,
"zero"
:
0
,
"zero"
:
0
,
...
@@ -1036,17 +1036,17 @@ test("jQuery.when()", function() {
...
@@ -1036,17 +1036,17 @@ test("jQuery.when()", function() {
"null"
:
null
,
"null"
:
null
,
"undefined"
:
undefined
,
"undefined"
:
undefined
,
"a plain object"
:
{}
"a plain object"
:
{}
}
,
function
(
message
,
value
)
{
}
,
function
(
message
,
value
)
{
ok
(
jQuery
.
isFunction
(
jQuery
.
when
(
value
).
then
(
function
(
resolveValue
)
{
ok
(
jQuery
.
isFunction
(
jQuery
.
when
(
value
).
then
(
function
(
resolveValue
)
{
strictEqual
(
resolveValue
,
value
,
"Test the promise was resolved with "
+
message
);
strictEqual
(
resolveValue
,
value
,
"Test the promise was resolved with "
+
message
);
}
).
promise
)
,
"Test "
+
message
+
" triggers the creation of a new Promise"
);
}
).
promise
)
,
"Test "
+
message
+
" triggers the creation of a new Promise"
);
}
);
}
);
var
cache
,
i
;
var
cache
,
i
;
for
(
i
=
1
;
i
<
4
;
i
++
)
{
for
(
i
=
1
;
i
<
4
;
i
++
)
{
jQuery
.
when
(
cache
||
jQuery
.
Deferred
(
function
()
{
jQuery
.
when
(
cache
||
jQuery
.
Deferred
(
function
()
{
this
.
resolve
(
i
);
this
.
resolve
(
i
);
...
...
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