tuev 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,382 @@
1
+ /*!
2
+ * MockJax - jQuery Plugin to Mock Ajax requests
3
+ *
4
+ * Version: 1.4.0
5
+ * Released: 2011-02-04
6
+ * Source: http://github.com/appendto/jquery-mockjax
7
+ * Docs: http://enterprisejquery.com/2010/07/mock-your-ajax-requests-with-mockjax-for-rapid-development
8
+ * Plugin: mockjax
9
+ * Author: Jonathan Sharp (http://jdsharp.com)
10
+ * License: MIT,GPL
11
+ *
12
+ * Copyright (c) 2010 appendTo LLC.
13
+ * Dual licensed under the MIT or GPL licenses.
14
+ * http://appendto.com/open-source-licenses
15
+ */
16
+ (function($) {
17
+ var _ajax = $.ajax,
18
+ mockHandlers = [];
19
+
20
+ function parseXML(xml) {
21
+ if ( window['DOMParser'] == undefined && window.ActiveXObject ) {
22
+ DOMParser = function() { };
23
+ DOMParser.prototype.parseFromString = function( xmlString ) {
24
+ var doc = new ActiveXObject('Microsoft.XMLDOM');
25
+ doc.async = 'false';
26
+ doc.loadXML( xmlString );
27
+ return doc;
28
+ };
29
+ }
30
+
31
+ try {
32
+ var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' );
33
+ if ( $.isXMLDoc( xmlDoc ) ) {
34
+ var err = $('parsererror', xmlDoc);
35
+ if ( err.length == 1 ) {
36
+ throw('Error: ' + $(xmlDoc).text() );
37
+ }
38
+ } else {
39
+ throw('Unable to parse XML');
40
+ }
41
+ } catch( e ) {
42
+ var msg = ( e.name == undefined ? e : e.name + ': ' + e.message );
43
+ $(document).trigger('xmlParseError', [ msg ]);
44
+ return undefined;
45
+ }
46
+ return xmlDoc;
47
+ }
48
+
49
+ $.extend({
50
+ ajax: function(origSettings) {
51
+ var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings),
52
+ mock = false;
53
+ // Iterate over our mock handlers (in registration order) until we find
54
+ // one that is willing to intercept the request
55
+ $.each(mockHandlers, function(k, v) {
56
+ if ( !mockHandlers[k] ) {
57
+ return;
58
+ }
59
+ var m = null;
60
+ // If the mock was registered with a function, let the function decide if we
61
+ // want to mock this request
62
+ if ( $.isFunction(mockHandlers[k]) ) {
63
+ m = mockHandlers[k](s);
64
+ } else {
65
+ m = mockHandlers[k];
66
+ // Inspect the URL of the request and check if the mock handler's url
67
+ // matches the url for this ajax request
68
+ if ( $.isFunction(m.url.test) ) {
69
+ // The user provided a regex for the url, test it
70
+ if ( !m.url.test( s.url ) ) {
71
+ m = null;
72
+ }
73
+ } else {
74
+ // Look for a simple wildcard '*' or a direct URL match
75
+ var star = m.url.indexOf('*');
76
+ if ( ( m.url != '*' && m.url != s.url && star == -1 ) ||
77
+ ( star > -1 && m.url.substr(0, star) != s.url.substr(0, star) ) ) {
78
+ // The url we tested did not match the wildcard *
79
+ m = null;
80
+ }
81
+ }
82
+ if ( m ) {
83
+ // Inspect the data submitted in the request (either POST body or GET query string)
84
+ if ( m.data && s.data ) {
85
+ var identical = false;
86
+ // Deep inspect the identity of the objects
87
+ (function ident(mock, live) {
88
+ // Test for situations where the data is a querystring (not an object)
89
+ if (typeof live === 'string') {
90
+ // Querystring may be a regex
91
+ identical = $.isFunction( mock.test ) ? mock.test(live) : mock == live;
92
+ return identical;
93
+ }
94
+ $.each(mock, function(k, v) {
95
+ if ( live[k] === undefined ) {
96
+ identical = false;
97
+ return false;
98
+ } else {
99
+ identical = true;
100
+ if ( typeof live[k] == 'object' ) {
101
+ return ident(mock[k], live[k]);
102
+ } else {
103
+ if ( $.isFunction( mock[k].test ) ) {
104
+ identical = mock[k].test(live[k]);
105
+ } else {
106
+ identical = ( mock[k] == live[k] );
107
+ }
108
+ return identical;
109
+ }
110
+ }
111
+ });
112
+ })(m.data, s.data);
113
+ // They're not identical, do not mock this request
114
+ if ( identical == false ) {
115
+ m = null;
116
+ }
117
+ }
118
+ // Inspect the request type
119
+ if ( m && m.type && m.type != s.type ) {
120
+ // The request type doesn't match (GET vs. POST)
121
+ m = null;
122
+ }
123
+ }
124
+ }
125
+ if ( m ) {
126
+ mock = true;
127
+
128
+ // Handle console logging
129
+ var c = $.extend({}, $.mockjaxSettings, m);
130
+ if ( c.log && $.isFunction(c.log) ) {
131
+ c.log('MOCK ' + s.type.toUpperCase() + ': ' + s.url, $.extend({}, s));
132
+ }
133
+
134
+ var jsre = /=\?(&|$)/, jsc = (new Date()).getTime();
135
+
136
+ // Handle JSONP Parameter Callbacks, we need to replicate some of the jQuery core here
137
+ // because there isn't an easy hook for the cross domain script tag of jsonp
138
+ if ( s.dataType === "jsonp" ) {
139
+ if ( s.type.toUpperCase() === "GET" ) {
140
+ if ( !jsre.test( s.url ) ) {
141
+ s.url += (rquery.test( s.url ) ? "&" : "?") + (s.jsonp || "callback") + "=?";
142
+ }
143
+ } else if ( !s.data || !jsre.test(s.data) ) {
144
+ s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
145
+ }
146
+ s.dataType = "json";
147
+ }
148
+
149
+ // Build temporary JSONP function
150
+ if ( s.dataType === "json" && (s.data && jsre.test(s.data) || jsre.test(s.url)) ) {
151
+ jsonp = s.jsonpCallback || ("jsonp" + jsc++);
152
+
153
+ // Replace the =? sequence both in the query string and the data
154
+ if ( s.data ) {
155
+ s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
156
+ }
157
+
158
+ s.url = s.url.replace(jsre, "=" + jsonp + "$1");
159
+
160
+ // We need to make sure
161
+ // that a JSONP style response is executed properly
162
+ s.dataType = "script";
163
+
164
+ // Handle JSONP-style loading
165
+ window[ jsonp ] = window[ jsonp ] || function( tmp ) {
166
+ data = tmp;
167
+ success();
168
+ complete();
169
+ // Garbage collect
170
+ window[ jsonp ] = undefined;
171
+
172
+ try {
173
+ delete window[ jsonp ];
174
+ } catch(e) {}
175
+
176
+ if ( head ) {
177
+ head.removeChild( script );
178
+ }
179
+ };
180
+ }
181
+
182
+ var rurl = /^(\w+:)?\/\/([^\/?#]+)/,
183
+ parts = rurl.exec( s.url ),
184
+ remote = parts && (parts[1] && parts[1] !== location.protocol || parts[2] !== location.host);
185
+
186
+ // Test if we are going to create a script tag (if so, intercept & mock)
187
+ if ( s.dataType === "script" && s.type.toUpperCase() === "GET" && remote ) {
188
+ // Synthesize the mock request for adding a script tag
189
+ var callbackContext = origSettings && origSettings.context || s;
190
+
191
+ function success() {
192
+ // If a local callback was specified, fire it and pass it the data
193
+ if ( s.success ) {
194
+ s.success.call( callbackContext, ( m.response ? m.response.toString() : m.responseText || ''), status, {} );
195
+ }
196
+
197
+ // Fire the global callback
198
+ if ( s.global ) {
199
+ trigger( "ajaxSuccess", [{}, s] );
200
+ }
201
+ }
202
+
203
+ function complete() {
204
+ // Process result
205
+ if ( s.complete ) {
206
+ s.complete.call( callbackContext, {} , status );
207
+ }
208
+
209
+ // The request was completed
210
+ if ( s.global ) {
211
+ trigger( "ajaxComplete", [{}, s] );
212
+ }
213
+
214
+ // Handle the global AJAX counter
215
+ if ( s.global && ! --jQuery.active ) {
216
+ jQuery.event.trigger( "ajaxStop" );
217
+ }
218
+ }
219
+
220
+ function trigger(type, args) {
221
+ (s.context ? jQuery(s.context) : jQuery.event).trigger(type, args);
222
+ }
223
+
224
+ if ( m.response && $.isFunction(m.response) ) {
225
+ m.response(origSettings);
226
+ } else {
227
+ $.globalEval(m.responseText);
228
+ }
229
+ success();
230
+ complete();
231
+ return false;
232
+ }
233
+ mock = _ajax.call($, $.extend(true, {}, origSettings, {
234
+ // Mock the XHR object
235
+ xhr: function() {
236
+ // Extend with our default mockjax settings
237
+ m = $.extend({}, $.mockjaxSettings, m);
238
+
239
+ if ( m.contentType ) {
240
+ m.headers['content-type'] = m.contentType;
241
+ }
242
+
243
+ // Return our mock xhr object
244
+ return {
245
+ status: m.status,
246
+ readyState: 1,
247
+ open: function() { },
248
+ send: function() {
249
+ // This is a substitute for < 1.4 which lacks $.proxy
250
+ var process = (function(that) {
251
+ return function() {
252
+ return (function() {
253
+ // The request has returned
254
+ this.status = m.status;
255
+ this.readyState = 4;
256
+
257
+ // We have an executable function, call it to give
258
+ // the mock handler a chance to update it's data
259
+ if ( $.isFunction(m.response) ) {
260
+ m.response(origSettings);
261
+ }
262
+ // Copy over our mock to our xhr object before passing control back to
263
+ // jQuery's onreadystatechange callback
264
+ if ( s.dataType == 'json' && ( typeof m.responseText == 'object' ) ) {
265
+ this.responseText = JSON.stringify(m.responseText);
266
+ } else if ( s.dataType == 'xml' ) {
267
+ if ( typeof m.responseXML == 'string' ) {
268
+ this.responseXML = parseXML(m.responseXML);
269
+ } else {
270
+ this.responseXML = m.responseXML;
271
+ }
272
+ } else {
273
+ this.responseText = m.responseText;
274
+ }
275
+ // jQuery < 1.4 doesn't have onreadystate change for xhr
276
+ if ( $.isFunction(this.onreadystatechange) ) {
277
+ this.onreadystatechange( m.isTimeout ? 'timeout' : undefined );
278
+ }
279
+ }).apply(that);
280
+ };
281
+ })(this);
282
+
283
+ if ( m.proxy ) {
284
+ // We're proxying this request and loading in an external file instead
285
+ _ajax({
286
+ global: false,
287
+ url: m.proxy,
288
+ type: m.proxyType,
289
+ data: m.data,
290
+ dataType: s.dataType,
291
+ complete: function(xhr, txt) {
292
+ m.responseXML = xhr.responseXML;
293
+ m.responseText = xhr.responseText;
294
+ this.responseTimer = setTimeout(process, m.responseTime || 0);
295
+ }
296
+ });
297
+ } else {
298
+ // type == 'POST' || 'GET' || 'DELETE'
299
+ if ( s.async === false ) {
300
+ // TODO: Blocking delay
301
+ process();
302
+ } else {
303
+ this.responseTimer = setTimeout(process, m.responseTime || 50);
304
+ }
305
+ }
306
+ },
307
+ abort: function() {
308
+ clearTimeout(this.responseTimer);
309
+ },
310
+ setRequestHeader: function() { },
311
+ getResponseHeader: function(header) {
312
+ // 'Last-modified', 'Etag', 'content-type' are all checked by jQuery
313
+ if ( m.headers && m.headers[header] ) {
314
+ // Return arbitrary headers
315
+ return m.headers[header];
316
+ } else if ( header.toLowerCase() == 'last-modified' ) {
317
+ return m.lastModified || (new Date()).toString();
318
+ } else if ( header.toLowerCase() == 'etag' ) {
319
+ return m.etag || '';
320
+ } else if ( header.toLowerCase() == 'content-type' ) {
321
+ return m.contentType || 'text/plain';
322
+ }
323
+ },
324
+ getAllResponseHeaders: function() {
325
+ var headers = '';
326
+ $.each(m.headers, function(k, v) {
327
+ headers += k + ': ' + v + "\n";
328
+ });
329
+ return headers;
330
+ }
331
+ };
332
+ }
333
+ }));
334
+ return false;
335
+ }
336
+ });
337
+ // We don't have a mock request, trigger a normal request
338
+ if ( !mock ) {
339
+ return _ajax.apply($, arguments);
340
+ } else {
341
+ return mock;
342
+ }
343
+ }
344
+ });
345
+
346
+ $.mockjaxSettings = {
347
+ //url: null,
348
+ //type: 'GET',
349
+ log: function(msg) {
350
+ window['console'] && window.console.log && window.console.log(msg);
351
+ },
352
+ status: 200,
353
+ responseTime: 500,
354
+ isTimeout: false,
355
+ contentType: 'text/plain',
356
+ response: '',
357
+ responseText: '',
358
+ responseXML: '',
359
+ proxy: '',
360
+ proxyType: 'GET',
361
+
362
+ lastModified: null,
363
+ etag: '',
364
+ headers: {
365
+ etag: 'IJF@H#@923uf8023hFO@I#H#',
366
+ 'content-type' : 'text/plain'
367
+ }
368
+ };
369
+
370
+ $.mockjax = function(settings) {
371
+ var i = mockHandlers.length;
372
+ mockHandlers[i] = settings;
373
+ return i;
374
+ };
375
+ $.mockjaxClear = function(i) {
376
+ if ( arguments.length == 1 ) {
377
+ mockHandlers[i] = null;
378
+ } else {
379
+ mockHandlers = [];
380
+ }
381
+ };
382
+ })(jQuery);
@@ -0,0 +1,215 @@
1
+ /** Font Family and Sizes */
2
+
3
+ #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
4
+ font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
5
+ }
6
+
7
+ #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
8
+ #qunit-tests { font-size: smaller; }
9
+
10
+
11
+ /** Resets */
12
+
13
+ #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult {
14
+ margin: 0;
15
+ padding: 0;
16
+ }
17
+
18
+
19
+ /** Header */
20
+
21
+ #qunit-header {
22
+ padding: 0.5em 0 0.5em 1em;
23
+
24
+ color: #8699a4;
25
+ background-color: #0d3349;
26
+
27
+ font-size: 1.5em;
28
+ line-height: 1em;
29
+ font-weight: normal;
30
+
31
+ border-radius: 15px 15px 0 0;
32
+ -moz-border-radius: 15px 15px 0 0;
33
+ -webkit-border-top-right-radius: 15px;
34
+ -webkit-border-top-left-radius: 15px;
35
+ }
36
+
37
+ #qunit-header a {
38
+ text-decoration: none;
39
+ color: #c2ccd1;
40
+ }
41
+
42
+ #qunit-header a:hover,
43
+ #qunit-header a:focus {
44
+ color: #fff;
45
+ }
46
+
47
+ #qunit-banner {
48
+ height: 5px;
49
+ }
50
+
51
+ #qunit-testrunner-toolbar {
52
+ padding: 0.5em 0 0.5em 2em;
53
+ color: #5E740B;
54
+ background-color: #eee;
55
+ }
56
+
57
+ #qunit-userAgent {
58
+ padding: 0.5em 0 0.5em 2.5em;
59
+ background-color: #2b81af;
60
+ color: #fff;
61
+ text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
62
+ }
63
+
64
+
65
+ /** Tests: Pass/Fail */
66
+
67
+ #qunit-tests {
68
+ list-style-position: inside;
69
+ }
70
+
71
+ #qunit-tests li {
72
+ padding: 0.4em 0.5em 0.4em 2.5em;
73
+ border-bottom: 1px solid #fff;
74
+ list-style-position: inside;
75
+ }
76
+
77
+ #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
78
+ display: none;
79
+ }
80
+
81
+ #qunit-tests li strong {
82
+ cursor: pointer;
83
+ }
84
+
85
+ #qunit-tests li a {
86
+ padding: 0.5em;
87
+ color: #c2ccd1;
88
+ text-decoration: none;
89
+ }
90
+ #qunit-tests li a:hover,
91
+ #qunit-tests li a:focus {
92
+ color: #000;
93
+ }
94
+
95
+ #qunit-tests ol {
96
+ margin-top: 0.5em;
97
+ padding: 0.5em;
98
+
99
+ background-color: #fff;
100
+
101
+ border-radius: 15px;
102
+ -moz-border-radius: 15px;
103
+ -webkit-border-radius: 15px;
104
+
105
+ box-shadow: inset 0px 2px 13px #999;
106
+ -moz-box-shadow: inset 0px 2px 13px #999;
107
+ -webkit-box-shadow: inset 0px 2px 13px #999;
108
+ }
109
+
110
+ #qunit-tests table {
111
+ border-collapse: collapse;
112
+ margin-top: .2em;
113
+ }
114
+
115
+ #qunit-tests th {
116
+ text-align: right;
117
+ vertical-align: top;
118
+ padding: 0 .5em 0 0;
119
+ }
120
+
121
+ #qunit-tests td {
122
+ vertical-align: top;
123
+ }
124
+
125
+ #qunit-tests pre {
126
+ margin: 0;
127
+ white-space: pre-wrap;
128
+ word-wrap: break-word;
129
+ }
130
+
131
+ #qunit-tests del {
132
+ background-color: #e0f2be;
133
+ color: #374e0c;
134
+ text-decoration: none;
135
+ }
136
+
137
+ #qunit-tests ins {
138
+ background-color: #ffcaca;
139
+ color: #500;
140
+ text-decoration: none;
141
+ }
142
+
143
+ /*** Test Counts */
144
+
145
+ #qunit-tests b.counts { color: black; }
146
+ #qunit-tests b.passed { color: #5E740B; }
147
+ #qunit-tests b.failed { color: #710909; }
148
+
149
+ #qunit-tests li li {
150
+ margin: 0.5em;
151
+ padding: 0.4em 0.5em 0.4em 0.5em;
152
+ background-color: #fff;
153
+ border-bottom: none;
154
+ list-style-position: inside;
155
+ }
156
+
157
+ /*** Passing Styles */
158
+
159
+ #qunit-tests li li.pass {
160
+ color: #5E740B;
161
+ background-color: #fff;
162
+ border-left: 26px solid #C6E746;
163
+ }
164
+
165
+ #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
166
+ #qunit-tests .pass .test-name { color: #366097; }
167
+
168
+ #qunit-tests .pass .test-actual,
169
+ #qunit-tests .pass .test-expected { color: #999999; }
170
+
171
+ #qunit-banner.qunit-pass { background-color: #C6E746; }
172
+
173
+ /*** Failing Styles */
174
+
175
+ #qunit-tests li li.fail {
176
+ color: #710909;
177
+ background-color: #fff;
178
+ border-left: 26px solid #EE5757;
179
+ }
180
+
181
+ #qunit-tests > li:last-child {
182
+ border-radius: 0 0 15px 15px;
183
+ -moz-border-radius: 0 0 15px 15px;
184
+ -webkit-border-bottom-right-radius: 15px;
185
+ -webkit-border-bottom-left-radius: 15px;
186
+ }
187
+
188
+ #qunit-tests .fail { color: #000000; background-color: #EE5757; }
189
+ #qunit-tests .fail .test-name,
190
+ #qunit-tests .fail .module-name { color: #000000; }
191
+
192
+ #qunit-tests .fail .test-actual { color: #EE5757; }
193
+ #qunit-tests .fail .test-expected { color: green; }
194
+
195
+ #qunit-banner.qunit-fail { background-color: #EE5757; }
196
+
197
+
198
+ /** Result */
199
+
200
+ #qunit-testresult {
201
+ padding: 0.5em 0.5em 0.5em 2.5em;
202
+
203
+ color: #2b81af;
204
+ background-color: #D2E0E6;
205
+
206
+ border-bottom: 1px solid white;
207
+ }
208
+
209
+ /** Fixture */
210
+
211
+ #qunit-fixture {
212
+ position: absolute;
213
+ top: -10000px;
214
+ left: -10000px;
215
+ }