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
a938d7b1
Commit
a938d7b1
authored
Nov 23, 2012
by
Richard Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No ticket: compress ajax. Close gh-1041.
parent
c27dc018
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
293 additions
and
328 deletions
+293
-328
ajax.js
src/ajax.js
+255
-282
jsonp.js
src/ajax/jsonp.js
+12
-19
script.js
src/ajax/script.js
+10
-9
xhr.js
src/ajax/xhr.js
+16
-18
No files found.
src/ajax.js
View file @
a938d7b1
This diff is collapsed.
Click to expand it.
src/ajax/jsonp.js
View file @
a938d7b1
var
oldCallbacks
=
[],
rquestion
=
/
\?
/
,
rjsonp
=
/
(
=
)\?(?=
&|$
)
|
\?\?
/
,
nonce
=
jQuery
.
now
();
rjsonp
=
/
(
=
)\?(?=
&|$
)
|
\?\?
/
;
// Default jsonp settings
jQuery
.
ajaxSetup
({
jsonp
:
"callback"
,
jsonpCallback
:
function
()
{
var
callback
=
oldCallbacks
.
pop
()
||
(
jQuery
.
expando
+
"_"
+
(
nonce
++
)
);
var
callback
=
oldCallbacks
.
pop
()
||
(
jQuery
.
expando
+
"_"
+
(
ajax_
nonce
++
)
);
this
[
callback
]
=
true
;
return
callback
;
}
...
...
@@ -17,30 +15,24 @@ jQuery.ajaxSetup({
jQuery
.
ajaxPrefilter
(
"json jsonp"
,
function
(
s
,
originalSettings
,
jqXHR
)
{
var
callbackName
,
overwritten
,
responseContainer
,
data
=
s
.
data
,
url
=
s
.
url
,
hasCallback
=
s
.
jsonp
!==
false
,
replaceInUrl
=
hasCallback
&&
rjsonp
.
test
(
url
),
replaceInData
=
hasCallback
&&
!
replaceInUrl
&&
typeof
data
===
"string"
&&
!
(
s
.
contentType
||
""
).
indexOf
(
"application/x-www-form-urlencoded"
)
&&
rjsonp
.
test
(
data
);
jsonProp
=
s
.
jsonp
!==
false
&&
(
rjsonp
.
test
(
s
.
url
)
?
"url"
:
typeof
s
.
data
===
"string"
&&
!
(
s
.
contentType
||
""
).
indexOf
(
"application/x-www-form-urlencoded"
)
&&
rjsonp
.
test
(
s
.
data
)
&&
"data"
);
// Handle iff the expected data type is "jsonp" or we have a parameter to set
if
(
s
.
dataTypes
[
0
]
===
"jsonp"
||
replaceInUrl
||
replaceInData
)
{
if
(
jsonProp
||
s
.
dataTypes
[
0
]
===
"jsonp"
)
{
// Get callback name, remembering preexisting value associated with it
callbackName
=
s
.
jsonpCallback
=
jQuery
.
isFunction
(
s
.
jsonpCallback
)
?
s
.
jsonpCallback
()
:
s
.
jsonpCallback
;
overwritten
=
window
[
callbackName
];
// Insert callback into url or form data
if
(
replaceInUrl
)
{
s
.
url
=
url
.
replace
(
rjsonp
,
"$1"
+
callbackName
);
}
else
if
(
replaceInData
)
{
s
.
data
=
data
.
replace
(
rjsonp
,
"$1"
+
callbackName
);
}
else
if
(
hasCallback
)
{
s
.
url
+=
(
rquestion
.
test
(
url
)
?
"&"
:
"?"
)
+
s
.
jsonp
+
"="
+
callbackName
;
if
(
jsonProp
)
{
s
[
jsonProp
]
=
s
[
jsonProp
].
replace
(
rjsonp
,
"$1"
+
callbackName
);
}
else
if
(
s
.
jsonp
!==
false
)
{
s
.
url
+=
(
ajax_rquery
.
test
(
s
.
url
)
?
"&"
:
"?"
)
+
s
.
jsonp
+
"="
+
callbackName
;
}
// Use data converter to retrieve json after script execution
...
...
@@ -55,6 +47,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
s
.
dataTypes
[
0
]
=
"json"
;
// Install callback
overwritten
=
window
[
callbackName
];
window
[
callbackName
]
=
function
()
{
responseContainer
=
arguments
;
};
...
...
src/ajax/script.js
View file @
a938d7b1
...
...
@@ -4,7 +4,7 @@ jQuery.ajaxSetup({
script
:
"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
},
contents
:
{
script
:
/
javascript|ecma
script/
script
:
/
(?:
java|ecma
)
script/
},
converters
:
{
"text script"
:
function
(
text
)
{
...
...
@@ -32,13 +32,13 @@ jQuery.ajaxTransport( "script", function(s) {
if
(
s
.
crossDomain
)
{
var
script
,
head
=
document
.
head
||
document
.
getElementsByTagName
(
"head"
)[
0
]
||
document
.
documentElement
;
head
=
document
.
head
||
jQuery
(
"head"
)[
0
]
||
document
.
documentElement
;
return
{
send
:
function
(
_
,
callback
)
{
script
=
document
.
createElement
(
"script"
);
script
=
document
.
createElement
(
"script"
);
script
.
async
=
true
;
...
...
@@ -57,12 +57,12 @@ jQuery.ajaxTransport( "script", function(s) {
script
.
onload
=
script
.
onreadystatechange
=
null
;
// Remove the script
if
(
head
&&
script
.
parentNode
)
{
head
.
removeChild
(
script
);
if
(
script
.
parentNode
)
{
script
.
parentNode
.
removeChild
(
script
);
}
// Dereference the script
script
=
undefined
;
script
=
null
;
// Callback if not abort
if
(
!
isAbort
)
{
...
...
@@ -70,14 +70,15 @@ jQuery.ajaxTransport( "script", function(s) {
}
}
};
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
// This arises when a base node is used (#2709 and #4378).
// Circumvent IE6 bugs with base elements (#2709 and #4378) by prepending
// Use native DOM manipulation to avoid our domManip AJAX trickery
head
.
insertBefore
(
script
,
head
.
firstChild
);
},
abort
:
function
()
{
if
(
script
)
{
script
.
onload
(
0
,
1
);
script
.
onload
(
undefined
,
true
);
}
}
};
...
...
src/ajax/xhr.js
View file @
a938d7b1
var
xhrCallbacks
,
var
xhrCallbacks
,
xhrSupported
,
xhrId
=
0
,
// #5280: Internet Explorer will keep connections alive if we don't abort on unload
xhrOnUnloadAbort
=
window
.
ActiveXObject
?
function
()
{
xhrOnUnloadAbort
=
window
.
ActiveXObject
&&
function
()
{
// Abort all pending requests
for
(
var
key
in
xhrCallbacks
)
{
xhrCallbacks
[
key
](
0
,
1
);
var
key
;
for
(
key
in
xhrCallbacks
)
{
xhrCallbacks
[
key
](
undefined
,
true
);
}
}
:
false
,
xhrId
=
0
;
};
// Functions to create xhrs
function
createStandardXHR
()
{
...
...
@@ -17,7 +18,7 @@ function createStandardXHR() {
function
createActiveXHR
()
{
try
{
return
new
window
.
ActiveXObject
(
"Microsoft.XMLHTTP"
);
return
new
window
.
ActiveXObject
(
"Microsoft.XMLHTTP"
);
}
catch
(
e
)
{}
}
...
...
@@ -37,15 +38,12 @@ jQuery.ajaxSettings.xhr = window.ActiveXObject ?
createStandardXHR
;
// Determine support properties
(
function
(
xhr
)
{
jQuery
.
extend
(
jQuery
.
support
,
{
ajax
:
!!
xhr
,
cors
:
!!
xhr
&&
(
"withCredentials"
in
xhr
)
});
})(
jQuery
.
ajaxSettings
.
xhr
()
);
xhrSupported
=
jQuery
.
ajaxSettings
.
xhr
();
jQuery
.
support
.
cors
=
!!
xhrSupported
&&
(
"withCredentials"
in
xhrSupported
);
xhrSupported
=
jQuery
.
support
.
ajax
=
!!
xhrSupported
;
// Create transport if the browser can provide an xhr
if
(
jQuery
.
support
.
ajax
)
{
if
(
xhrSupported
)
{
jQuery
.
ajaxTransport
(
function
(
s
)
{
// Cross domain only allowed if supported through XMLHttpRequest
...
...
@@ -86,7 +84,7 @@ if ( jQuery.support.ajax ) {
// (it can always be set on a per-request basis or even using ajaxSetup)
// For same-domain requests, won't change header if already provided.
if
(
!
s
.
crossDomain
&&
!
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
...
...
@@ -136,10 +134,10 @@ if ( jQuery.support.ajax ) {
xhr
.
abort
();
}
}
else
{
status
=
xhr
.
status
;
responseHeaders
=
xhr
.
getAllResponseHeaders
();
responses
=
{};
status
=
xhr
.
status
;
xml
=
xhr
.
responseXML
;
responseHeaders
=
xhr
.
getAllResponseHeaders
();
// Construct response list
if
(
xml
&&
xml
.
documentElement
/* #4958 */
)
{
...
...
@@ -211,7 +209,7 @@ if ( jQuery.support.ajax ) {
abort
:
function
()
{
if
(
callback
)
{
callback
(
0
,
1
);
callback
(
undefined
,
true
);
}
}
};
...
...
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