smparkes-envjs 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/envjsrb +157 -73
- data/bin/jquery-1.3.2-test.js +11 -4
- data/lib/envjs/env.js +935 -11028
- data/lib/envjs/net/cgi.rb +94 -0
- data/lib/envjs/net/file.rb +4 -4
- data/lib/envjs/runtime.rb +80 -24
- data/test/call-load-test.js +0 -2
- data/test/firebug/errorIcon.png +0 -0
- data/test/firebug/firebug.css +209 -0
- data/test/firebug/firebug.html +23 -0
- data/test/firebug/firebug.js +672 -0
- data/test/firebug/firebugx.js +10 -0
- data/test/firebug/infoIcon.png +0 -0
- data/test/firebug/warningIcon.png +0 -0
- data/test/fixtures/html/events.html +171 -0
- data/test/fixtures/html/iframe1.html +46 -0
- data/test/fixtures/html/iframe1a.html +46 -0
- data/test/fixtures/html/iframe2.html +45 -0
- data/test/fixtures/html/iframe3.html +28 -0
- data/test/fixtures/html/iframeN.html +57 -0
- data/test/fixtures/html/malformed.html +181 -0
- data/test/fixtures/html/scope.html +81 -0
- data/test/fixtures/html/trivial.html +19 -0
- data/test/fixtures/html/with_js.html +26 -0
- data/test/fixtures/images/icon-blue.png +0 -0
- data/test/fixtures/js/external_script.js +1 -0
- data/test/fixtures/js/script.js +1 -0
- data/test/fixtures/js/script_error.js +2 -0
- data/test/html/malformed.html +1 -0
- data/test/index.html +21 -19
- data/test/{primaryTests.js → primary-tests.js} +1 -3
- data/test/{prototype.js → prototype-test.js} +0 -2
- data/test/qunit/qunit/qunit.css +0 -0
- data/test/qunit/qunit/qunit.js +2 -2
- data/test/{qunit/qunit/qunit.js.smp → specs/dist/env.spec.js} +539 -7
- data/test/specs/envjs.spec.css +46 -0
- data/test/specs/parser/html.js +31 -0
- data/test/specs/parser/spec.html +40 -0
- data/test/specs/parser/xml.js +31 -0
- data/test/specs/qunit.bdd.js +210 -0
- data/test/{qunit.smp/qunit → specs}/qunit.css +0 -0
- data/test/{qunit.smp/qunit → specs}/qunit.js +2 -2
- data/test/specs/template/spec-0.js +31 -0
- data/test/specs/template/spec-1.js +31 -0
- data/test/specs/template/spec.html +40 -0
- data/test/specs/window/css.js +23 -0
- data/test/specs/window/dialog.js +25 -0
- data/test/specs/window/document.js +23 -0
- data/test/specs/window/event.js +25 -0
- data/test/specs/window/history.js +34 -0
- data/test/specs/window/location.js +34 -0
- data/test/specs/window/navigator.js +71 -0
- data/test/specs/window/screen.js +42 -0
- data/test/specs/window/spec.html +48 -0
- data/test/specs/window/timer.js +26 -0
- data/test/specs/window/window.js +53 -0
- data/test/specs/xhr/spec.html +47 -0
- data/test/specs/xhr/xhr.js +31 -0
- data/test/test.js +10 -0
- data/test/unit/elementmembers.js +31 -0
- data/test/unit/nu.validator.js +34 -0
- data/test/unit/onload.js +1 -3
- data/test/unit/parser.js +106 -98
- data/test/unit/prototypecompat.js +2 -2
- data/test/vendor/jQuery/1.3.2/ChangeLog.txt +98 -0
- data/test/vendor/jQuery/1.3.2/GPL-LICENSE.txt +278 -0
- data/test/vendor/jQuery/1.3.2/MIT-LICENSE.txt +20 -0
- data/test/vendor/jQuery/1.3.2/Makefile +154 -0
- data/test/vendor/jQuery/1.3.2/README +67 -0
- data/test/vendor/jQuery/1.3.2/build/ant-contrib-0.6.jar +0 -0
- data/test/vendor/jQuery/1.3.2/build/build/min.js +11 -0
- data/test/vendor/jQuery/1.3.2/build/build/pack.js +19 -0
- data/test/vendor/jQuery/1.3.2/build/js/Packer.js +209 -0
- data/test/vendor/jQuery/1.3.2/build/js/ParseMaster.js +106 -0
- data/test/vendor/jQuery/1.3.2/build/js/Words.js +62 -0
- data/test/vendor/jQuery/1.3.2/build/js/base2.js +978 -0
- data/test/vendor/jQuery/1.3.2/build/js/jsmin.js +316 -0
- data/test/vendor/jQuery/1.3.2/build/js/json.js +117 -0
- data/test/vendor/jQuery/1.3.2/build/js/pack.js +316 -0
- data/test/vendor/jQuery/1.3.2/build/js/parse.js +105 -0
- data/test/vendor/jQuery/1.3.2/build/js/writeFile.js +19 -0
- data/test/vendor/jQuery/1.3.2/build/js/xml.js +25 -0
- data/test/vendor/jQuery/1.3.2/build/js.jar +0 -0
- data/test/vendor/jQuery/1.3.2/build/runtest/env.js +1 -0
- data/test/vendor/jQuery/1.3.2/build/runtest/test.js +106 -0
- data/test/vendor/jQuery/1.3.2/build/runtest/testrunner.js +197 -0
- data/test/vendor/jQuery/1.3.2/build/speed/benchmarker.css +65 -0
- data/test/vendor/jQuery/1.3.2/build/speed/benchmarker.js +181 -0
- data/test/vendor/jQuery/1.3.2/build/speed/index.html +72 -0
- data/test/vendor/jQuery/1.3.2/build/speed/jquery-basis.js +3549 -0
- data/test/vendor/jQuery/1.3.2/build/style.xsl +99 -0
- data/test/vendor/jQuery/1.3.2/build/yuicompressor-2.4.2.jar +0 -0
- data/test/vendor/jQuery/1.3.2/build.xml +123 -0
- data/test/vendor/jQuery/1.3.2/dist/jquery.js +4376 -0
- data/test/vendor/jQuery/1.3.2/reminder.txt +3 -0
- data/test/vendor/jQuery/1.3.2/src/ajax.js +541 -0
- data/test/vendor/jQuery/1.3.2/src/core.js +1255 -0
- data/test/vendor/jQuery/1.3.2/src/data.js +145 -0
- data/test/vendor/jQuery/1.3.2/src/dimensions.js +49 -0
- data/test/vendor/jQuery/1.3.2/src/event.js +684 -0
- data/test/vendor/jQuery/1.3.2/src/fx.js +407 -0
- data/test/vendor/jQuery/1.3.2/src/intro.js +13 -0
- data/test/vendor/jQuery/1.3.2/src/offset.js +155 -0
- data/test/vendor/jQuery/1.3.2/src/outro.js +1 -0
- data/test/vendor/jQuery/1.3.2/src/selector.js +1015 -0
- data/test/vendor/jQuery/1.3.2/src/support.js +112 -0
- data/test/vendor/jQuery/1.3.2/test/data/cow.jpg +0 -0
- data/test/vendor/jQuery/1.3.2/test/data/dashboard.xml +11 -0
- data/test/vendor/jQuery/1.3.2/test/data/echoQuery.php +1 -0
- data/test/vendor/jQuery/1.3.2/test/data/iframe.html +8 -0
- data/test/vendor/jQuery/1.3.2/test/data/json.php +9 -0
- data/test/vendor/jQuery/1.3.2/test/data/json_assigned_obj.js +1 -0
- data/test/vendor/jQuery/1.3.2/test/data/json_obj.js +1 -0
- data/test/vendor/jQuery/1.3.2/test/data/jsonp.php +10 -0
- data/test/vendor/jQuery/1.3.2/test/data/name.html +1 -0
- data/test/vendor/jQuery/1.3.2/test/data/name.php +29 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/absolute.html +39 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/body.html +24 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/fixed.html +33 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/relative.html +31 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/scroll.html +39 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/static.html +31 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/table.html +43 -0
- data/test/vendor/jQuery/1.3.2/test/data/params_html.php +12 -0
- data/test/vendor/jQuery/1.3.2/test/data/test.html +7 -0
- data/test/vendor/jQuery/1.3.2/test/data/test.js +3 -0
- data/test/vendor/jQuery/1.3.2/test/data/test.php +7 -0
- data/test/vendor/jQuery/1.3.2/test/data/test2.html +5 -0
- data/test/vendor/jQuery/1.3.2/test/data/test3.html +3 -0
- data/test/vendor/jQuery/1.3.2/test/data/testrunner.js +1 -0
- data/test/vendor/jQuery/1.3.2/test/data/text.php +12 -0
- data/test/vendor/jQuery/1.3.2/test/data/with_fries.xml +25 -0
- data/test/vendor/jQuery/1.3.2/test/index.html +229 -0
- data/test/vendor/jQuery/1.3.2/test/jqenv-1259090275493.html +247 -0
- data/test/vendor/jQuery/1.3.2/test/jqenv-1259091671501.html +247 -0
- data/test/vendor/jQuery/1.3.2/test/jqenv-1259175319655.html +247 -0
- data/test/vendor/jQuery/1.3.2/test/offset.html +28 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/jquery/1.2.1/jquery.js +11 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/jquery/1.2.3/jquery.js +11 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/mootools/1.11/mootools.js +1577 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/prototype/1.6.0.2/prototype.js +4221 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/builder.js +131 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/controls.js +835 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/dragdrop.js +944 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/effects.js +1090 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/scriptaculous.js +51 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/slider.js +278 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/unittest.js +564 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/builder.js +136 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/controls.js +965 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/dragdrop.js +974 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/effects.js +1122 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/scriptaculous.js +58 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/slider.js +275 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/sound.js +55 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/unittest.js +568 -0
- data/test/vendor/jQuery/1.3.2/test/polluted.php +64 -0
- data/test/vendor/jQuery/1.3.2/test/qunit/testrunner.js +780 -0
- data/test/vendor/jQuery/1.3.2/test/qunit/testsuite.css +120 -0
- data/test/vendor/jQuery/1.3.2/test/test.js +41 -0
- data/test/vendor/jQuery/1.3.2/test/unit/ajax.js +856 -0
- data/test/vendor/jQuery/1.3.2/test/unit/core.js +1872 -0
- data/test/vendor/jQuery/1.3.2/test/unit/data.js +160 -0
- data/test/vendor/jQuery/1.3.2/test/unit/dimensions.js +86 -0
- data/test/vendor/jQuery/1.3.2/test/unit/event.js +670 -0
- data/test/vendor/jQuery/1.3.2/test/unit/fx.js +451 -0
- data/test/vendor/jQuery/1.3.2/test/unit/offset.js +173 -0
- data/test/vendor/jQuery/1.3.2/test/unit/selector.js +395 -0
- data/test/vendor/jQuery/1.3.2/test/xhtml.php +5 -0
- data/test/vendor/jQuery/1.3.2/version.txt +1 -0
- metadata +158 -22
- data/lib/envjs/runtime.rb.smp +0 -133
- data/test/envjs-call-load-test.js +0 -5
- data/test/envjs-prototype.js +0 -5
- data/test/qunit/package.json +0 -21
- data/test/qunit/test/index.html +0 -17
- data/test/qunit/test/same.js +0 -1368
- data/test/qunit/test/test.js +0 -136
- data/test/qunit.smp/package.json +0 -21
- data/test/qunit.smp/test/index.html +0 -17
- data/test/qunit.smp/test/same.js +0 -1368
- data/test/qunit.smp/test/test.js +0 -136
- data/test/rhino-call-load-test.js +0 -5
- data/test/rhino-prototype.js +0 -5
- data/test/test-with-envs-jar.js +0 -8
- data/test/test-with-rhino-jar.js +0 -9
@@ -0,0 +1,541 @@
|
|
1
|
+
jQuery.fn.extend({
|
2
|
+
// Keep a copy of the old load
|
3
|
+
_load: jQuery.fn.load,
|
4
|
+
|
5
|
+
load: function( url, params, callback ) {
|
6
|
+
if ( typeof url !== "string" )
|
7
|
+
return this._load( url );
|
8
|
+
|
9
|
+
var off = url.indexOf(" ");
|
10
|
+
if ( off >= 0 ) {
|
11
|
+
var selector = url.slice(off, url.length);
|
12
|
+
url = url.slice(0, off);
|
13
|
+
}
|
14
|
+
|
15
|
+
// Default to a GET request
|
16
|
+
var type = "GET";
|
17
|
+
|
18
|
+
// If the second parameter was provided
|
19
|
+
if ( params )
|
20
|
+
// If it's a function
|
21
|
+
if ( jQuery.isFunction( params ) ) {
|
22
|
+
// We assume that it's the callback
|
23
|
+
callback = params;
|
24
|
+
params = null;
|
25
|
+
|
26
|
+
// Otherwise, build a param string
|
27
|
+
} else if( typeof params === "object" ) {
|
28
|
+
params = jQuery.param( params );
|
29
|
+
type = "POST";
|
30
|
+
}
|
31
|
+
|
32
|
+
var self = this;
|
33
|
+
|
34
|
+
// Request the remote document
|
35
|
+
jQuery.ajax({
|
36
|
+
url: url,
|
37
|
+
type: type,
|
38
|
+
dataType: "html",
|
39
|
+
data: params,
|
40
|
+
complete: function(res, status){
|
41
|
+
// If successful, inject the HTML into all the matched elements
|
42
|
+
if ( status == "success" || status == "notmodified" )
|
43
|
+
// See if a selector was specified
|
44
|
+
self.html( selector ?
|
45
|
+
// Create a dummy div to hold the results
|
46
|
+
jQuery("<div/>")
|
47
|
+
// inject the contents of the document in, removing the scripts
|
48
|
+
// to avoid any 'Permission Denied' errors in IE
|
49
|
+
.append(res.responseText.replace(/<script(.|\s)*?\/script>/g, ""))
|
50
|
+
|
51
|
+
// Locate the specified elements
|
52
|
+
.find(selector) :
|
53
|
+
|
54
|
+
// If not, just inject the full result
|
55
|
+
res.responseText );
|
56
|
+
|
57
|
+
if( callback )
|
58
|
+
self.each( callback, [res.responseText, status, res] );
|
59
|
+
}
|
60
|
+
});
|
61
|
+
return this;
|
62
|
+
},
|
63
|
+
|
64
|
+
serialize: function() {
|
65
|
+
return jQuery.param(this.serializeArray());
|
66
|
+
},
|
67
|
+
serializeArray: function() {
|
68
|
+
return this.map(function(){
|
69
|
+
return this.elements ? jQuery.makeArray(this.elements) : this;
|
70
|
+
})
|
71
|
+
.filter(function(){
|
72
|
+
return this.name && !this.disabled &&
|
73
|
+
(this.checked || /select|textarea/i.test(this.nodeName) ||
|
74
|
+
/text|hidden|password|search/i.test(this.type));
|
75
|
+
})
|
76
|
+
.map(function(i, elem){
|
77
|
+
var val = jQuery(this).val();
|
78
|
+
return val == null ? null :
|
79
|
+
jQuery.isArray(val) ?
|
80
|
+
jQuery.map( val, function(val, i){
|
81
|
+
return {name: elem.name, value: val};
|
82
|
+
}) :
|
83
|
+
{name: elem.name, value: val};
|
84
|
+
}).get();
|
85
|
+
}
|
86
|
+
});
|
87
|
+
|
88
|
+
// Attach a bunch of functions for handling common AJAX events
|
89
|
+
jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","), function(i,o){
|
90
|
+
jQuery.fn[o] = function(f){
|
91
|
+
return this.bind(o, f);
|
92
|
+
};
|
93
|
+
});
|
94
|
+
|
95
|
+
var jsc = now();
|
96
|
+
|
97
|
+
jQuery.extend({
|
98
|
+
|
99
|
+
get: function( url, data, callback, type ) {
|
100
|
+
// shift arguments if data argument was ommited
|
101
|
+
if ( jQuery.isFunction( data ) ) {
|
102
|
+
callback = data;
|
103
|
+
data = null;
|
104
|
+
}
|
105
|
+
|
106
|
+
return jQuery.ajax({
|
107
|
+
type: "GET",
|
108
|
+
url: url,
|
109
|
+
data: data,
|
110
|
+
success: callback,
|
111
|
+
dataType: type
|
112
|
+
});
|
113
|
+
},
|
114
|
+
|
115
|
+
getScript: function( url, callback ) {
|
116
|
+
return jQuery.get(url, null, callback, "script");
|
117
|
+
},
|
118
|
+
|
119
|
+
getJSON: function( url, data, callback ) {
|
120
|
+
return jQuery.get(url, data, callback, "json");
|
121
|
+
},
|
122
|
+
|
123
|
+
post: function( url, data, callback, type ) {
|
124
|
+
if ( jQuery.isFunction( data ) ) {
|
125
|
+
callback = data;
|
126
|
+
data = {};
|
127
|
+
}
|
128
|
+
|
129
|
+
return jQuery.ajax({
|
130
|
+
type: "POST",
|
131
|
+
url: url,
|
132
|
+
data: data,
|
133
|
+
success: callback,
|
134
|
+
dataType: type
|
135
|
+
});
|
136
|
+
},
|
137
|
+
|
138
|
+
ajaxSetup: function( settings ) {
|
139
|
+
jQuery.extend( jQuery.ajaxSettings, settings );
|
140
|
+
},
|
141
|
+
|
142
|
+
ajaxSettings: {
|
143
|
+
url: location.href,
|
144
|
+
global: true,
|
145
|
+
type: "GET",
|
146
|
+
contentType: "application/x-www-form-urlencoded",
|
147
|
+
processData: true,
|
148
|
+
async: true,
|
149
|
+
/*
|
150
|
+
timeout: 0,
|
151
|
+
data: null,
|
152
|
+
username: null,
|
153
|
+
password: null,
|
154
|
+
*/
|
155
|
+
// Create the request object; Microsoft failed to properly
|
156
|
+
// implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available
|
157
|
+
// This function can be overriden by calling jQuery.ajaxSetup
|
158
|
+
xhr:function(){
|
159
|
+
return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
|
160
|
+
},
|
161
|
+
accepts: {
|
162
|
+
xml: "application/xml, text/xml",
|
163
|
+
html: "text/html",
|
164
|
+
script: "text/javascript, application/javascript",
|
165
|
+
json: "application/json, text/javascript",
|
166
|
+
text: "text/plain",
|
167
|
+
_default: "*/*"
|
168
|
+
}
|
169
|
+
},
|
170
|
+
|
171
|
+
// Last-Modified header cache for next request
|
172
|
+
lastModified: {},
|
173
|
+
|
174
|
+
ajax: function( s ) {
|
175
|
+
// Extend the settings, but re-extend 's' so that it can be
|
176
|
+
// checked again later (in the test suite, specifically)
|
177
|
+
s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));
|
178
|
+
|
179
|
+
var jsonp, jsre = /=\?(&|$)/g, status, data,
|
180
|
+
type = s.type.toUpperCase();
|
181
|
+
|
182
|
+
// convert data if not already a string
|
183
|
+
if ( s.data && s.processData && typeof s.data !== "string" )
|
184
|
+
s.data = jQuery.param(s.data);
|
185
|
+
|
186
|
+
// Handle JSONP Parameter Callbacks
|
187
|
+
if ( s.dataType == "jsonp" ) {
|
188
|
+
if ( type == "GET" ) {
|
189
|
+
if ( !s.url.match(jsre) )
|
190
|
+
s.url += (s.url.match(/\?/) ? "&" : "?") + (s.jsonp || "callback") + "=?";
|
191
|
+
} else if ( !s.data || !s.data.match(jsre) )
|
192
|
+
s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
|
193
|
+
s.dataType = "json";
|
194
|
+
}
|
195
|
+
|
196
|
+
// Build temporary JSONP function
|
197
|
+
if ( s.dataType == "json" && (s.data && s.data.match(jsre) || s.url.match(jsre)) ) {
|
198
|
+
jsonp = "jsonp" + jsc++;
|
199
|
+
|
200
|
+
// Replace the =? sequence both in the query string and the data
|
201
|
+
if ( s.data )
|
202
|
+
s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
|
203
|
+
s.url = s.url.replace(jsre, "=" + jsonp + "$1");
|
204
|
+
|
205
|
+
// We need to make sure
|
206
|
+
// that a JSONP style response is executed properly
|
207
|
+
s.dataType = "script";
|
208
|
+
|
209
|
+
// Handle JSONP-style loading
|
210
|
+
window[ jsonp ] = function(tmp){
|
211
|
+
data = tmp;
|
212
|
+
success();
|
213
|
+
complete();
|
214
|
+
// Garbage collect
|
215
|
+
window[ jsonp ] = undefined;
|
216
|
+
try{ delete window[ jsonp ]; } catch(e){}
|
217
|
+
if ( head )
|
218
|
+
head.removeChild( script );
|
219
|
+
};
|
220
|
+
}
|
221
|
+
|
222
|
+
if ( s.dataType == "script" && s.cache == null )
|
223
|
+
s.cache = false;
|
224
|
+
|
225
|
+
if ( s.cache === false && type == "GET" ) {
|
226
|
+
var ts = now();
|
227
|
+
// try replacing _= if it is there
|
228
|
+
var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
|
229
|
+
// if nothing was replaced, add timestamp to the end
|
230
|
+
s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") + "_=" + ts : "");
|
231
|
+
}
|
232
|
+
|
233
|
+
// If data is available, append data to url for get requests
|
234
|
+
if ( s.data && type == "GET" ) {
|
235
|
+
s.url += (s.url.match(/\?/) ? "&" : "?") + s.data;
|
236
|
+
|
237
|
+
// IE likes to send both get and post data, prevent this
|
238
|
+
s.data = null;
|
239
|
+
}
|
240
|
+
|
241
|
+
// Watch for a new set of requests
|
242
|
+
if ( s.global && ! jQuery.active++ )
|
243
|
+
jQuery.event.trigger( "ajaxStart" );
|
244
|
+
|
245
|
+
// Matches an absolute URL, and saves the domain
|
246
|
+
var parts = /^(\w+:)?\/\/([^\/?#]+)/.exec( s.url );
|
247
|
+
|
248
|
+
// If we're requesting a remote document
|
249
|
+
// and trying to load JSON or Script with a GET
|
250
|
+
if ( s.dataType == "script" && type == "GET" && parts
|
251
|
+
&& ( parts[1] && parts[1] != location.protocol || parts[2] != location.host )){
|
252
|
+
|
253
|
+
var head = document.getElementsByTagName("head")[0];
|
254
|
+
var script = document.createElement("script");
|
255
|
+
script.src = s.url;
|
256
|
+
if (s.scriptCharset)
|
257
|
+
script.charset = s.scriptCharset;
|
258
|
+
|
259
|
+
// Handle Script loading
|
260
|
+
if ( !jsonp ) {
|
261
|
+
var done = false;
|
262
|
+
|
263
|
+
// Attach handlers for all browsers
|
264
|
+
script.onload = script.onreadystatechange = function(){
|
265
|
+
if ( !done && (!this.readyState ||
|
266
|
+
this.readyState == "loaded" || this.readyState == "complete") ) {
|
267
|
+
done = true;
|
268
|
+
success();
|
269
|
+
complete();
|
270
|
+
|
271
|
+
// Handle memory leak in IE
|
272
|
+
script.onload = script.onreadystatechange = null;
|
273
|
+
head.removeChild( script );
|
274
|
+
}
|
275
|
+
};
|
276
|
+
}
|
277
|
+
|
278
|
+
head.appendChild(script);
|
279
|
+
|
280
|
+
// We handle everything using the script element injection
|
281
|
+
return undefined;
|
282
|
+
}
|
283
|
+
|
284
|
+
var requestDone = false;
|
285
|
+
|
286
|
+
// Create the request object
|
287
|
+
var xhr = s.xhr();
|
288
|
+
|
289
|
+
// Open the socket
|
290
|
+
// Passing null username, generates a login popup on Opera (#2865)
|
291
|
+
if( s.username )
|
292
|
+
xhr.open(type, s.url, s.async, s.username, s.password);
|
293
|
+
else
|
294
|
+
xhr.open(type, s.url, s.async);
|
295
|
+
|
296
|
+
// Need an extra try/catch for cross domain requests in Firefox 3
|
297
|
+
try {
|
298
|
+
// Set the correct header, if data is being sent
|
299
|
+
if ( s.data )
|
300
|
+
xhr.setRequestHeader("Content-Type", s.contentType);
|
301
|
+
|
302
|
+
// Set the If-Modified-Since header, if ifModified mode.
|
303
|
+
if ( s.ifModified )
|
304
|
+
xhr.setRequestHeader("If-Modified-Since",
|
305
|
+
jQuery.lastModified[s.url] || "Thu, 01 Jan 1970 00:00:00 GMT" );
|
306
|
+
|
307
|
+
// Set header so the called script knows that it's an XMLHttpRequest
|
308
|
+
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
309
|
+
|
310
|
+
// Set the Accepts header for the server, depending on the dataType
|
311
|
+
xhr.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ?
|
312
|
+
s.accepts[ s.dataType ] + ", */*" :
|
313
|
+
s.accepts._default );
|
314
|
+
} catch(e){}
|
315
|
+
|
316
|
+
// Allow custom headers/mimetypes and early abort
|
317
|
+
if ( s.beforeSend && s.beforeSend(xhr, s) === false ) {
|
318
|
+
// Handle the global AJAX counter
|
319
|
+
if ( s.global && ! --jQuery.active )
|
320
|
+
jQuery.event.trigger( "ajaxStop" );
|
321
|
+
// close opended socket
|
322
|
+
xhr.abort();
|
323
|
+
return false;
|
324
|
+
}
|
325
|
+
|
326
|
+
if ( s.global )
|
327
|
+
jQuery.event.trigger("ajaxSend", [xhr, s]);
|
328
|
+
|
329
|
+
// Wait for a response to come back
|
330
|
+
var onreadystatechange = function(isTimeout){
|
331
|
+
// The request was aborted, clear the interval and decrement jQuery.active
|
332
|
+
if (xhr.readyState == 0) {
|
333
|
+
if (ival) {
|
334
|
+
// clear poll interval
|
335
|
+
clearInterval(ival);
|
336
|
+
ival = null;
|
337
|
+
// Handle the global AJAX counter
|
338
|
+
if ( s.global && ! --jQuery.active )
|
339
|
+
jQuery.event.trigger( "ajaxStop" );
|
340
|
+
}
|
341
|
+
// The transfer is complete and the data is available, or the request timed out
|
342
|
+
} else if ( !requestDone && xhr && (xhr.readyState == 4 || isTimeout == "timeout") ) {
|
343
|
+
requestDone = true;
|
344
|
+
|
345
|
+
// clear poll interval
|
346
|
+
if (ival) {
|
347
|
+
clearInterval(ival);
|
348
|
+
ival = null;
|
349
|
+
}
|
350
|
+
|
351
|
+
status = isTimeout == "timeout" ? "timeout" :
|
352
|
+
!jQuery.httpSuccess( xhr ) ? "error" :
|
353
|
+
s.ifModified && jQuery.httpNotModified( xhr, s.url ) ? "notmodified" :
|
354
|
+
"success";
|
355
|
+
|
356
|
+
if ( status == "success" ) {
|
357
|
+
// Watch for, and catch, XML document parse errors
|
358
|
+
try {
|
359
|
+
// process the data (runs the xml through httpData regardless of callback)
|
360
|
+
data = jQuery.httpData( xhr, s.dataType, s );
|
361
|
+
} catch(e) {
|
362
|
+
status = "parsererror";
|
363
|
+
}
|
364
|
+
}
|
365
|
+
|
366
|
+
// Make sure that the request was successful or notmodified
|
367
|
+
if ( status == "success" ) {
|
368
|
+
// Cache Last-Modified header, if ifModified mode.
|
369
|
+
var modRes;
|
370
|
+
try {
|
371
|
+
modRes = xhr.getResponseHeader("Last-Modified");
|
372
|
+
} catch(e) {} // swallow exception thrown by FF if header is not available
|
373
|
+
|
374
|
+
if ( s.ifModified && modRes )
|
375
|
+
jQuery.lastModified[s.url] = modRes;
|
376
|
+
|
377
|
+
// JSONP handles its own success callback
|
378
|
+
if ( !jsonp )
|
379
|
+
success();
|
380
|
+
} else
|
381
|
+
jQuery.handleError(s, xhr, status);
|
382
|
+
|
383
|
+
// Fire the complete handlers
|
384
|
+
complete();
|
385
|
+
|
386
|
+
if ( isTimeout )
|
387
|
+
xhr.abort();
|
388
|
+
|
389
|
+
// Stop memory leaks
|
390
|
+
if ( s.async )
|
391
|
+
xhr = null;
|
392
|
+
}
|
393
|
+
};
|
394
|
+
|
395
|
+
if ( s.async ) {
|
396
|
+
// don't attach the handler to the request, just poll it instead
|
397
|
+
var ival = setInterval(onreadystatechange, 13);
|
398
|
+
|
399
|
+
// Timeout checker
|
400
|
+
if ( s.timeout > 0 )
|
401
|
+
setTimeout(function(){
|
402
|
+
// Check to see if the request is still happening
|
403
|
+
if ( xhr && !requestDone )
|
404
|
+
onreadystatechange( "timeout" );
|
405
|
+
}, s.timeout);
|
406
|
+
}
|
407
|
+
|
408
|
+
// Send the data
|
409
|
+
try {
|
410
|
+
xhr.send(s.data);
|
411
|
+
} catch(e) {
|
412
|
+
jQuery.handleError(s, xhr, null, e);
|
413
|
+
}
|
414
|
+
|
415
|
+
// firefox 1.5 doesn't fire statechange for sync requests
|
416
|
+
if ( !s.async )
|
417
|
+
onreadystatechange();
|
418
|
+
|
419
|
+
function success(){
|
420
|
+
// If a local callback was specified, fire it and pass it the data
|
421
|
+
if ( s.success )
|
422
|
+
s.success( data, status );
|
423
|
+
|
424
|
+
// Fire the global callback
|
425
|
+
if ( s.global )
|
426
|
+
jQuery.event.trigger( "ajaxSuccess", [xhr, s] );
|
427
|
+
}
|
428
|
+
|
429
|
+
function complete(){
|
430
|
+
// Process result
|
431
|
+
if ( s.complete )
|
432
|
+
s.complete(xhr, status);
|
433
|
+
|
434
|
+
// The request was completed
|
435
|
+
if ( s.global )
|
436
|
+
jQuery.event.trigger( "ajaxComplete", [xhr, s] );
|
437
|
+
|
438
|
+
// Handle the global AJAX counter
|
439
|
+
if ( s.global && ! --jQuery.active )
|
440
|
+
jQuery.event.trigger( "ajaxStop" );
|
441
|
+
}
|
442
|
+
|
443
|
+
// return XMLHttpRequest to allow aborting the request etc.
|
444
|
+
return xhr;
|
445
|
+
},
|
446
|
+
|
447
|
+
handleError: function( s, xhr, status, e ) {
|
448
|
+
// If a local callback was specified, fire it
|
449
|
+
if ( s.error ) s.error( xhr, status, e );
|
450
|
+
|
451
|
+
// Fire the global callback
|
452
|
+
if ( s.global )
|
453
|
+
jQuery.event.trigger( "ajaxError", [xhr, s, e] );
|
454
|
+
},
|
455
|
+
|
456
|
+
// Counter for holding the number of active queries
|
457
|
+
active: 0,
|
458
|
+
|
459
|
+
// Determines if an XMLHttpRequest was successful or not
|
460
|
+
httpSuccess: function( xhr ) {
|
461
|
+
try {
|
462
|
+
// IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
|
463
|
+
return !xhr.status && location.protocol == "file:" ||
|
464
|
+
( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223;
|
465
|
+
} catch(e){}
|
466
|
+
return false;
|
467
|
+
},
|
468
|
+
|
469
|
+
// Determines if an XMLHttpRequest returns NotModified
|
470
|
+
httpNotModified: function( xhr, url ) {
|
471
|
+
try {
|
472
|
+
var xhrRes = xhr.getResponseHeader("Last-Modified");
|
473
|
+
|
474
|
+
// Firefox always returns 200. check Last-Modified date
|
475
|
+
return xhr.status == 304 || xhrRes == jQuery.lastModified[url];
|
476
|
+
} catch(e){}
|
477
|
+
return false;
|
478
|
+
},
|
479
|
+
|
480
|
+
httpData: function( xhr, type, s ) {
|
481
|
+
var ct = xhr.getResponseHeader("content-type"),
|
482
|
+
xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0,
|
483
|
+
data = xml ? xhr.responseXML : xhr.responseText;
|
484
|
+
|
485
|
+
if ( xml && data.documentElement.tagName == "parsererror" )
|
486
|
+
throw "parsererror";
|
487
|
+
|
488
|
+
// Allow a pre-filtering function to sanitize the response
|
489
|
+
// s != null is checked to keep backwards compatibility
|
490
|
+
if( s && s.dataFilter )
|
491
|
+
data = s.dataFilter( data, type );
|
492
|
+
|
493
|
+
// The filter can actually parse the response
|
494
|
+
if( typeof data === "string" ){
|
495
|
+
|
496
|
+
// If the type is "script", eval it in global context
|
497
|
+
if ( type == "script" )
|
498
|
+
jQuery.globalEval( data );
|
499
|
+
|
500
|
+
// Get the JavaScript object, if JSON is used.
|
501
|
+
if ( type == "json" )
|
502
|
+
data = window["eval"]("(" + data + ")");
|
503
|
+
}
|
504
|
+
|
505
|
+
return data;
|
506
|
+
},
|
507
|
+
|
508
|
+
// Serialize an array of form elements or a set of
|
509
|
+
// key/values into a query string
|
510
|
+
param: function( a ) {
|
511
|
+
var s = [ ];
|
512
|
+
|
513
|
+
function add( key, value ){
|
514
|
+
s[ s.length ] = encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
515
|
+
};
|
516
|
+
|
517
|
+
// If an array was passed in, assume that it is an array
|
518
|
+
// of form elements
|
519
|
+
if ( jQuery.isArray(a) || a.jquery )
|
520
|
+
// Serialize the form elements
|
521
|
+
jQuery.each( a, function(){
|
522
|
+
add( this.name, this.value );
|
523
|
+
});
|
524
|
+
|
525
|
+
// Otherwise, assume that it's an object of key/value pairs
|
526
|
+
else
|
527
|
+
// Serialize the key/values
|
528
|
+
for ( var j in a )
|
529
|
+
// If the value is an array then the key names need to be repeated
|
530
|
+
if ( jQuery.isArray(a[j]) )
|
531
|
+
jQuery.each( a[j], function(){
|
532
|
+
add( j, this );
|
533
|
+
});
|
534
|
+
else
|
535
|
+
add( j, jQuery.isFunction(a[j]) ? a[j]() : a[j] );
|
536
|
+
|
537
|
+
// Return the resulting serialization
|
538
|
+
return s.join("&").replace(/%20/g, "+");
|
539
|
+
}
|
540
|
+
|
541
|
+
});
|