guff-compass 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +21 -0
- data/.gitignore +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/demo/bower_components/jquery/.bower.json +21 -0
- data/demo/bower_components/jquery/.editorconfig +43 -0
- data/demo/bower_components/jquery/.gitattributes +2 -0
- data/demo/bower_components/jquery/.gitignore +14 -0
- data/demo/bower_components/jquery/.gitmodules +6 -0
- data/demo/bower_components/jquery/.jshintrc +17 -0
- data/demo/bower_components/jquery/.mailmap +94 -0
- data/demo/bower_components/jquery/AUTHORS.txt +170 -0
- data/demo/bower_components/jquery/CONTRIBUTING.md +216 -0
- data/demo/bower_components/jquery/Gruntfile.js +594 -0
- data/demo/bower_components/jquery/MIT-LICENSE.txt +21 -0
- data/demo/bower_components/jquery/README.md +398 -0
- data/demo/bower_components/jquery/bower.json +11 -0
- data/demo/bower_components/jquery/build/release-notes.js +59 -0
- data/demo/bower_components/jquery/build/release.js +316 -0
- data/demo/bower_components/jquery/component.json +15 -0
- data/demo/bower_components/jquery/composer.json +35 -0
- data/demo/bower_components/jquery/jquery-migrate.js +511 -0
- data/demo/bower_components/jquery/jquery-migrate.min.js +3 -0
- data/demo/bower_components/jquery/jquery.js +9789 -0
- data/demo/bower_components/jquery/jquery.min.js +6 -0
- data/demo/bower_components/jquery/jquery.min.map +1 -0
- data/demo/bower_components/jquery/package.json +38 -0
- data/demo/bower_components/jquery/speed/benchmark.js +15 -0
- data/demo/bower_components/jquery/speed/benchmarker.css +65 -0
- data/demo/bower_components/jquery/speed/benchmarker.js +181 -0
- data/demo/bower_components/jquery/speed/closest.html +39 -0
- data/demo/bower_components/jquery/speed/css.html +82 -0
- data/demo/bower_components/jquery/speed/event.html +58 -0
- data/demo/bower_components/jquery/speed/filter.html +183 -0
- data/demo/bower_components/jquery/speed/find.html +179 -0
- data/demo/bower_components/jquery/speed/index.html +72 -0
- data/demo/bower_components/jquery/speed/jquery-basis.js +6238 -0
- data/demo/bower_components/jquery/speed/slice.vs.concat.html +47 -0
- data/demo/bower_components/jquery/src/.jshintrc +27 -0
- data/demo/bower_components/jquery/src/ajax.js +855 -0
- data/demo/bower_components/jquery/src/ajax/jsonp.js +80 -0
- data/demo/bower_components/jquery/src/ajax/script.js +86 -0
- data/demo/bower_components/jquery/src/ajax/xhr.js +207 -0
- data/demo/bower_components/jquery/src/attributes.js +659 -0
- data/demo/bower_components/jquery/src/callbacks.js +197 -0
- data/demo/bower_components/jquery/src/core.js +981 -0
- data/demo/bower_components/jquery/src/css.js +661 -0
- data/demo/bower_components/jquery/src/data.js +336 -0
- data/demo/bower_components/jquery/src/deferred.js +141 -0
- data/demo/bower_components/jquery/src/deprecated.js +11 -0
- data/demo/bower_components/jquery/src/dimensions.js +41 -0
- data/demo/bower_components/jquery/src/effects.js +732 -0
- data/demo/bower_components/jquery/src/event-alias.js +32 -0
- data/demo/bower_components/jquery/src/event.js +995 -0
- data/demo/bower_components/jquery/src/exports.js +21 -0
- data/demo/bower_components/jquery/src/intro.js +20 -0
- data/demo/bower_components/jquery/src/manipulation.js +744 -0
- data/demo/bower_components/jquery/src/offset.js +169 -0
- data/demo/bower_components/jquery/src/outro.js +2 -0
- data/demo/bower_components/jquery/src/queue.js +146 -0
- data/demo/bower_components/jquery/src/serialize.js +99 -0
- data/demo/bower_components/jquery/src/sizzle-jquery.js +7 -0
- data/demo/bower_components/jquery/src/support.js +246 -0
- data/demo/bower_components/jquery/src/traversing.js +283 -0
- data/demo/bower_components/jquery/src/wrap.js +66 -0
- data/demo/bower_components/jquery/test/.jshintignore +3 -0
- data/demo/bower_components/jquery/test/.jshintrc +60 -0
- data/demo/bower_components/jquery/test/data/1x1.jpg +0 -0
- data/demo/bower_components/jquery/test/data/ajax/unreleasedXHR.html +25 -0
- data/demo/bower_components/jquery/test/data/atom+xml.php +4 -0
- data/demo/bower_components/jquery/test/data/badcall.js +1 -0
- data/demo/bower_components/jquery/test/data/badjson.js +1 -0
- data/demo/bower_components/jquery/test/data/cleanScript.html +10 -0
- data/demo/bower_components/jquery/test/data/core/cc_on.html +22 -0
- data/demo/bower_components/jquery/test/data/dashboard.xml +11 -0
- data/demo/bower_components/jquery/test/data/dimensions/documentLarge.html +17 -0
- data/demo/bower_components/jquery/test/data/dimensions/documentSmall.html +21 -0
- data/demo/bower_components/jquery/test/data/echoData.php +1 -0
- data/demo/bower_components/jquery/test/data/echoQuery.php +1 -0
- data/demo/bower_components/jquery/test/data/errorWithJSON.php +6 -0
- data/demo/bower_components/jquery/test/data/errorWithText.php +5 -0
- data/demo/bower_components/jquery/test/data/etag.php +21 -0
- data/demo/bower_components/jquery/test/data/evalScript.php +1 -0
- data/demo/bower_components/jquery/test/data/event/focusElem.html +16 -0
- data/demo/bower_components/jquery/test/data/event/longLoadScript.php +4 -0
- data/demo/bower_components/jquery/test/data/event/promiseReady.html +17 -0
- data/demo/bower_components/jquery/test/data/event/syncReady.html +23 -0
- data/demo/bower_components/jquery/test/data/headers.php +18 -0
- data/demo/bower_components/jquery/test/data/if_modified_since.php +20 -0
- data/demo/bower_components/jquery/test/data/iframe.html +8 -0
- data/demo/bower_components/jquery/test/data/jquery-1.9.1.ajax_xhr.min.js +5 -0
- data/demo/bower_components/jquery/test/data/json.php +13 -0
- data/demo/bower_components/jquery/test/data/json_obj.js +1 -0
- data/demo/bower_components/jquery/test/data/jsonp.php +14 -0
- data/demo/bower_components/jquery/test/data/manipulation/iframe-denied.html +36 -0
- data/demo/bower_components/jquery/test/data/name.html +1 -0
- data/demo/bower_components/jquery/test/data/name.php +24 -0
- data/demo/bower_components/jquery/test/data/nocontent.php +5 -0
- data/demo/bower_components/jquery/test/data/offset/absolute.html +41 -0
- data/demo/bower_components/jquery/test/data/offset/body.html +26 -0
- data/demo/bower_components/jquery/test/data/offset/fixed.html +34 -0
- data/demo/bower_components/jquery/test/data/offset/relative.html +31 -0
- data/demo/bower_components/jquery/test/data/offset/scroll.html +39 -0
- data/demo/bower_components/jquery/test/data/offset/static.html +31 -0
- data/demo/bower_components/jquery/test/data/offset/table.html +43 -0
- data/demo/bower_components/jquery/test/data/params_html.php +12 -0
- data/demo/bower_components/jquery/test/data/readywaitasset.js +1 -0
- data/demo/bower_components/jquery/test/data/readywaitloader.js +25 -0
- data/demo/bower_components/jquery/test/data/script.php +11 -0
- data/demo/bower_components/jquery/test/data/selector/html5_selector.html +114 -0
- data/demo/bower_components/jquery/test/data/selector/sizzle_cache.html +21 -0
- data/demo/bower_components/jquery/test/data/statusText.php +5 -0
- data/demo/bower_components/jquery/test/data/support/bodyBackground.html +28 -0
- data/demo/bower_components/jquery/test/data/support/boxSizing.html +19 -0
- data/demo/bower_components/jquery/test/data/support/csp.js +3 -0
- data/demo/bower_components/jquery/test/data/support/csp.php +22 -0
- data/demo/bower_components/jquery/test/data/support/shrinkWrapBlocks.html +23 -0
- data/demo/bower_components/jquery/test/data/support/testElementCrash.html +17 -0
- data/demo/bower_components/jquery/test/data/test.html +7 -0
- data/demo/bower_components/jquery/test/data/test.js +3 -0
- data/demo/bower_components/jquery/test/data/test.php +7 -0
- data/demo/bower_components/jquery/test/data/test2.html +5 -0
- data/demo/bower_components/jquery/test/data/test3.html +3 -0
- data/demo/bower_components/jquery/test/data/testinit.js +264 -0
- data/demo/bower_components/jquery/test/data/testrunner.js +371 -0
- data/demo/bower_components/jquery/test/data/testsuite.css +155 -0
- data/demo/bower_components/jquery/test/data/text.php +12 -0
- data/demo/bower_components/jquery/test/data/ua.txt +272 -0
- data/demo/bower_components/jquery/test/data/with_fries.xml +25 -0
- data/demo/bower_components/jquery/test/data/with_fries_over_jsonp.php +7 -0
- data/demo/bower_components/jquery/test/delegatetest.html +228 -0
- data/demo/bower_components/jquery/test/hovertest.html +158 -0
- data/demo/bower_components/jquery/test/index.html +337 -0
- data/demo/bower_components/jquery/test/jquery.js +5 -0
- data/demo/bower_components/jquery/test/localfile.html +75 -0
- data/demo/bower_components/jquery/test/networkerror.html +84 -0
- data/demo/bower_components/jquery/test/readywait.html +70 -0
- data/demo/bower_components/jquery/test/unit/ajax.js +2016 -0
- data/demo/bower_components/jquery/test/unit/attributes.js +1388 -0
- data/demo/bower_components/jquery/test/unit/callbacks.js +342 -0
- data/demo/bower_components/jquery/test/unit/core.js +1360 -0
- data/demo/bower_components/jquery/test/unit/css.js +1056 -0
- data/demo/bower_components/jquery/test/unit/data.js +645 -0
- data/demo/bower_components/jquery/test/unit/deferred.js +436 -0
- data/demo/bower_components/jquery/test/unit/deprecated.js +8 -0
- data/demo/bower_components/jquery/test/unit/dimensions.js +472 -0
- data/demo/bower_components/jquery/test/unit/effects.js +2242 -0
- data/demo/bower_components/jquery/test/unit/event.js +2755 -0
- data/demo/bower_components/jquery/test/unit/exports.js +7 -0
- data/demo/bower_components/jquery/test/unit/manipulation.js +2120 -0
- data/demo/bower_components/jquery/test/unit/offset.js +559 -0
- data/demo/bower_components/jquery/test/unit/queue.js +314 -0
- data/demo/bower_components/jquery/test/unit/selector.js +172 -0
- data/demo/bower_components/jquery/test/unit/serialize.js +148 -0
- data/demo/bower_components/jquery/test/unit/support.js +370 -0
- data/demo/bower_components/jquery/test/unit/traversing.js +797 -0
- data/demo/bower_components/jquery/test/unit/wrap.js +265 -0
- data/demo/bower_components/jquery/test/xhtml.php +5 -0
- data/demo/index.html +347 -0
- data/demo/styles/main.css +208 -0
- data/demo/styles/main.scss +138 -0
- data/docs/docco.css +506 -0
- data/docs/guff.html +1127 -0
- data/docs/public/fonts/aller-bold.eot +0 -0
- data/docs/public/fonts/aller-bold.ttf +0 -0
- data/docs/public/fonts/aller-bold.woff +0 -0
- data/docs/public/fonts/aller-light.eot +0 -0
- data/docs/public/fonts/aller-light.ttf +0 -0
- data/docs/public/fonts/aller-light.woff +0 -0
- data/docs/public/fonts/novecento-bold.eot +0 -0
- data/docs/public/fonts/novecento-bold.ttf +0 -0
- data/docs/public/fonts/novecento-bold.woff +0 -0
- data/docs/public/stylesheets/normalize.css +375 -0
- data/guff.gemspec +16 -0
- data/guff.scss +514 -0
- data/gulpfile.js +67 -0
- data/lib/guff.rb +4 -0
- data/lib/stylesheets/_guff.scss +514 -0
- data/package.json +19 -0
- data/src/_functions.scss +57 -0
- data/src/_mixins.scss +301 -0
- data/src/_reset.scss +67 -0
- data/src/_settings.scss +22 -0
- data/src/_typography.scss +67 -0
- metadata +259 -0
@@ -0,0 +1,342 @@
|
|
1
|
+
module( "callbacks", {
|
2
|
+
teardown: moduleTeardown
|
3
|
+
});
|
4
|
+
|
5
|
+
(function() {
|
6
|
+
|
7
|
+
var output,
|
8
|
+
addToOutput = function( string ) {
|
9
|
+
return function() {
|
10
|
+
output += string;
|
11
|
+
};
|
12
|
+
},
|
13
|
+
outputA = addToOutput("A"),
|
14
|
+
outputB = addToOutput("B"),
|
15
|
+
outputC = addToOutput("C"),
|
16
|
+
tests = {
|
17
|
+
"": "XABC X XABCABCC X XBB X XABA X XX",
|
18
|
+
"once": "XABC X X X X X XABA X XX",
|
19
|
+
"memory": "XABC XABC XABCABCCC XA XBB XB XABA XC XX",
|
20
|
+
"unique": "XABC X XABCA X XBB X XAB X X",
|
21
|
+
"stopOnFalse": "XABC X XABCABCC X XBB X XA X XX",
|
22
|
+
"once memory": "XABC XABC X XA X XA XABA XC XX",
|
23
|
+
"once unique": "XABC X X X X X XAB X X",
|
24
|
+
"once stopOnFalse": "XABC X X X X X XA X XX",
|
25
|
+
"memory unique": "XABC XA XABCA XA XBB XB XAB XC X",
|
26
|
+
"memory stopOnFalse": "XABC XABC XABCABCCC XA XBB XB XA X XX",
|
27
|
+
"unique stopOnFalse": "XABC X XABCA X XBB X XA X X"
|
28
|
+
},
|
29
|
+
filters = {
|
30
|
+
"no filter": undefined,
|
31
|
+
"filter": function( fn ) {
|
32
|
+
return function() {
|
33
|
+
return fn.apply( this, arguments );
|
34
|
+
};
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
38
|
+
function showFlags( flags ) {
|
39
|
+
if ( typeof flags === "string" ) {
|
40
|
+
return "'" + flags + "'";
|
41
|
+
}
|
42
|
+
var output = [], key;
|
43
|
+
for ( key in flags ) {
|
44
|
+
output.push( "'" + key + "': " + flags[ key ] );
|
45
|
+
}
|
46
|
+
return "{ " + output.join( ", " ) + " }";
|
47
|
+
}
|
48
|
+
|
49
|
+
jQuery.each( tests, function( strFlags, resultString ) {
|
50
|
+
|
51
|
+
var objectFlags = {};
|
52
|
+
|
53
|
+
jQuery.each( strFlags.split( " " ), function() {
|
54
|
+
if ( this.length ) {
|
55
|
+
objectFlags[ this ] = true;
|
56
|
+
}
|
57
|
+
});
|
58
|
+
|
59
|
+
jQuery.each( filters, function( filterLabel ) {
|
60
|
+
|
61
|
+
jQuery.each({
|
62
|
+
"string": strFlags,
|
63
|
+
"object": objectFlags
|
64
|
+
}, function( flagsTypes, flags ) {
|
65
|
+
|
66
|
+
test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function() {
|
67
|
+
|
68
|
+
expect( 21 );
|
69
|
+
|
70
|
+
// Give qunit a little breathing room
|
71
|
+
stop();
|
72
|
+
setTimeout( start, 0 );
|
73
|
+
|
74
|
+
var cblist,
|
75
|
+
results = resultString.split( /\s+/ );
|
76
|
+
|
77
|
+
// Basic binding and firing
|
78
|
+
output = "X";
|
79
|
+
cblist = jQuery.Callbacks( flags );
|
80
|
+
cblist.add(function( str ) {
|
81
|
+
output += str;
|
82
|
+
});
|
83
|
+
cblist.fire("A");
|
84
|
+
strictEqual( output, "XA", "Basic binding and firing" );
|
85
|
+
strictEqual( cblist.fired(), true, ".fired() detects firing" );
|
86
|
+
output = "X";
|
87
|
+
cblist.disable();
|
88
|
+
cblist.add(function( str ) {
|
89
|
+
output += str;
|
90
|
+
});
|
91
|
+
strictEqual( output, "X", "Adding a callback after disabling" );
|
92
|
+
cblist.fire("A");
|
93
|
+
strictEqual( output, "X", "Firing after disabling" );
|
94
|
+
|
95
|
+
// #13517 - Emptying while firing
|
96
|
+
cblist = jQuery.Callbacks( flags );
|
97
|
+
cblist.add( cblist.empty );
|
98
|
+
cblist.add( function() {
|
99
|
+
ok( false, "not emptied" );
|
100
|
+
} );
|
101
|
+
cblist.fire();
|
102
|
+
|
103
|
+
// Disabling while firing
|
104
|
+
cblist = jQuery.Callbacks( flags );
|
105
|
+
cblist.add( cblist.disable );
|
106
|
+
cblist.add( function() {
|
107
|
+
ok( false, "not disabled" );
|
108
|
+
} );
|
109
|
+
cblist.fire();
|
110
|
+
|
111
|
+
// Basic binding and firing (context, arguments)
|
112
|
+
output = "X";
|
113
|
+
cblist = jQuery.Callbacks( flags );
|
114
|
+
cblist.add(function() {
|
115
|
+
equal( this, window, "Basic binding and firing (context)" );
|
116
|
+
output += Array.prototype.join.call( arguments, "" );
|
117
|
+
});
|
118
|
+
cblist.fireWith( window, [ "A", "B" ] );
|
119
|
+
strictEqual( output, "XAB", "Basic binding and firing (arguments)" );
|
120
|
+
|
121
|
+
// fireWith with no arguments
|
122
|
+
output = "";
|
123
|
+
cblist = jQuery.Callbacks( flags );
|
124
|
+
cblist.add(function() {
|
125
|
+
equal( this, window, "fireWith with no arguments (context is window)" );
|
126
|
+
strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" );
|
127
|
+
});
|
128
|
+
cblist.fireWith();
|
129
|
+
|
130
|
+
// Basic binding, removing and firing
|
131
|
+
output = "X";
|
132
|
+
cblist = jQuery.Callbacks( flags );
|
133
|
+
cblist.add( outputA, outputB, outputC );
|
134
|
+
cblist.remove( outputB, outputC );
|
135
|
+
cblist.fire();
|
136
|
+
strictEqual( output, "XA", "Basic binding, removing and firing" );
|
137
|
+
|
138
|
+
// Empty
|
139
|
+
output = "X";
|
140
|
+
cblist = jQuery.Callbacks( flags );
|
141
|
+
cblist.add( outputA );
|
142
|
+
cblist.add( outputB );
|
143
|
+
cblist.add( outputC );
|
144
|
+
cblist.empty();
|
145
|
+
cblist.fire();
|
146
|
+
strictEqual( output, "X", "Empty" );
|
147
|
+
|
148
|
+
// Locking
|
149
|
+
output = "X";
|
150
|
+
cblist = jQuery.Callbacks( flags );
|
151
|
+
cblist.add(function( str ) {
|
152
|
+
output += str;
|
153
|
+
});
|
154
|
+
cblist.lock();
|
155
|
+
cblist.add(function( str ) {
|
156
|
+
output += str;
|
157
|
+
});
|
158
|
+
cblist.fire("A");
|
159
|
+
cblist.add(function( str ) {
|
160
|
+
output += str;
|
161
|
+
});
|
162
|
+
strictEqual( output, "X", "Lock early" );
|
163
|
+
|
164
|
+
// Ordering
|
165
|
+
output = "X";
|
166
|
+
cblist = jQuery.Callbacks( flags );
|
167
|
+
cblist.add(function() {
|
168
|
+
cblist.add( outputC );
|
169
|
+
outputA();
|
170
|
+
}, outputB );
|
171
|
+
cblist.fire();
|
172
|
+
strictEqual( output, results.shift(), "Proper ordering" );
|
173
|
+
|
174
|
+
// Add and fire again
|
175
|
+
output = "X";
|
176
|
+
cblist.add(function() {
|
177
|
+
cblist.add( outputC );
|
178
|
+
outputA();
|
179
|
+
}, outputB );
|
180
|
+
strictEqual( output, results.shift(), "Add after fire" );
|
181
|
+
|
182
|
+
output = "X";
|
183
|
+
cblist.fire();
|
184
|
+
strictEqual( output, results.shift(), "Fire again" );
|
185
|
+
|
186
|
+
// Multiple fire
|
187
|
+
output = "X";
|
188
|
+
cblist = jQuery.Callbacks( flags );
|
189
|
+
cblist.add(function( str ) {
|
190
|
+
output += str;
|
191
|
+
});
|
192
|
+
cblist.fire("A");
|
193
|
+
strictEqual( output, "XA", "Multiple fire (first fire)" );
|
194
|
+
output = "X";
|
195
|
+
cblist.add(function( str ) {
|
196
|
+
output += str;
|
197
|
+
});
|
198
|
+
strictEqual( output, results.shift(), "Multiple fire (first new callback)" );
|
199
|
+
output = "X";
|
200
|
+
cblist.fire("B");
|
201
|
+
strictEqual( output, results.shift(), "Multiple fire (second fire)" );
|
202
|
+
output = "X";
|
203
|
+
cblist.add(function( str ) {
|
204
|
+
output += str;
|
205
|
+
});
|
206
|
+
strictEqual( output, results.shift(), "Multiple fire (second new callback)" );
|
207
|
+
|
208
|
+
// Return false
|
209
|
+
output = "X";
|
210
|
+
cblist = jQuery.Callbacks( flags );
|
211
|
+
cblist.add( outputA, function() { return false; }, outputB );
|
212
|
+
cblist.add( outputA );
|
213
|
+
cblist.fire();
|
214
|
+
strictEqual( output, results.shift(), "Callback returning false" );
|
215
|
+
|
216
|
+
// Add another callback (to control lists with memory do not fire anymore)
|
217
|
+
output = "X";
|
218
|
+
cblist.add( outputC );
|
219
|
+
strictEqual( output, results.shift(), "Adding a callback after one returned false" );
|
220
|
+
|
221
|
+
// Callbacks are not iterated
|
222
|
+
output = "";
|
223
|
+
function handler() {
|
224
|
+
output += "X";
|
225
|
+
}
|
226
|
+
handler.method = function() {
|
227
|
+
output += "!";
|
228
|
+
};
|
229
|
+
cblist = jQuery.Callbacks( flags );
|
230
|
+
cblist.add( handler );
|
231
|
+
cblist.add( handler );
|
232
|
+
cblist.fire();
|
233
|
+
strictEqual( output, results.shift(), "No callback iteration" );
|
234
|
+
});
|
235
|
+
});
|
236
|
+
});
|
237
|
+
});
|
238
|
+
|
239
|
+
})();
|
240
|
+
|
241
|
+
test( "jQuery.Callbacks( options ) - options are copied", function() {
|
242
|
+
|
243
|
+
expect( 1 );
|
244
|
+
|
245
|
+
var options = {
|
246
|
+
"unique": true
|
247
|
+
},
|
248
|
+
cb = jQuery.Callbacks( options ),
|
249
|
+
count = 0,
|
250
|
+
fn = function() {
|
251
|
+
ok( !( count++ ), "called once" );
|
252
|
+
};
|
253
|
+
options["unique"] = false;
|
254
|
+
cb.add( fn, fn );
|
255
|
+
cb.fire();
|
256
|
+
});
|
257
|
+
|
258
|
+
test( "jQuery.Callbacks.fireWith - arguments are copied", function() {
|
259
|
+
|
260
|
+
expect( 1 );
|
261
|
+
|
262
|
+
var cb = jQuery.Callbacks("memory"),
|
263
|
+
args = ["hello"];
|
264
|
+
|
265
|
+
cb.fireWith( null, args );
|
266
|
+
args[ 0 ] = "world";
|
267
|
+
|
268
|
+
cb.add(function( hello ) {
|
269
|
+
strictEqual( hello, "hello", "arguments are copied internally" );
|
270
|
+
});
|
271
|
+
});
|
272
|
+
|
273
|
+
test( "jQuery.Callbacks.remove - should remove all instances", function() {
|
274
|
+
|
275
|
+
expect( 1 );
|
276
|
+
|
277
|
+
var cb = jQuery.Callbacks();
|
278
|
+
|
279
|
+
function fn() {
|
280
|
+
ok( false, "function wasn't removed" );
|
281
|
+
}
|
282
|
+
|
283
|
+
cb.add( fn, fn, function() {
|
284
|
+
ok( true, "end of test" );
|
285
|
+
}).remove( fn ).fire();
|
286
|
+
});
|
287
|
+
|
288
|
+
test( "jQuery.Callbacks.has", function() {
|
289
|
+
|
290
|
+
expect( 13 );
|
291
|
+
|
292
|
+
var cb = jQuery.Callbacks();
|
293
|
+
function getA() {
|
294
|
+
return "A";
|
295
|
+
}
|
296
|
+
function getB() {
|
297
|
+
return "B";
|
298
|
+
}
|
299
|
+
function getC() {
|
300
|
+
return "C";
|
301
|
+
}
|
302
|
+
cb.add(getA, getB, getC);
|
303
|
+
strictEqual( cb.has(), true, "No arguments to .has() returns whether callback function(s) are attached or not" );
|
304
|
+
strictEqual( cb.has(getA), true, "Check if a specific callback function is in the Callbacks list" );
|
305
|
+
|
306
|
+
cb.remove(getB);
|
307
|
+
strictEqual( cb.has(getB), false, "Remove a specific callback function and make sure its no longer there" );
|
308
|
+
strictEqual( cb.has(getA), true, "Remove a specific callback function and make sure other callback function is still there" );
|
309
|
+
|
310
|
+
cb.empty();
|
311
|
+
strictEqual( cb.has(), false, "Empty list and make sure there are no callback function(s)" );
|
312
|
+
strictEqual( cb.has(getA), false, "Check for a specific function in an empty() list" );
|
313
|
+
|
314
|
+
cb.add(getA, getB, function(){
|
315
|
+
strictEqual( cb.has(), true, "Check if list has callback function(s) from within a callback function" );
|
316
|
+
strictEqual( cb.has(getA), true, "Check if list has a specific callback from within a callback function" );
|
317
|
+
}).fire();
|
318
|
+
|
319
|
+
strictEqual( cb.has(), true, "Callbacks list has callback function(s) after firing" );
|
320
|
+
|
321
|
+
cb.disable();
|
322
|
+
strictEqual( cb.has(), false, "disabled() list has no callback functions (returns false)" );
|
323
|
+
strictEqual( cb.has(getA), false, "Check for a specific function in a disabled() list" );
|
324
|
+
|
325
|
+
cb = jQuery.Callbacks("unique");
|
326
|
+
cb.add(getA);
|
327
|
+
cb.add(getA);
|
328
|
+
strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" );
|
329
|
+
cb.lock();
|
330
|
+
strictEqual( cb.has(), false, "locked() list is empty and returns false" );
|
331
|
+
|
332
|
+
|
333
|
+
});
|
334
|
+
|
335
|
+
test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function() {
|
336
|
+
|
337
|
+
expect( 1 );
|
338
|
+
|
339
|
+
jQuery.Callbacks().add( "hello world" );
|
340
|
+
|
341
|
+
ok( true, "no stack overflow" );
|
342
|
+
});
|
@@ -0,0 +1,1360 @@
|
|
1
|
+
module("core", { teardown: moduleTeardown });
|
2
|
+
|
3
|
+
test("Unit Testing Environment", function () {
|
4
|
+
expect(2);
|
5
|
+
ok( hasPHP, "Running in an environment with PHP support. The AJAX tests only run if the environment supports PHP!" );
|
6
|
+
ok( !isLocal, "Unit tests are not ran from file:// (especially in Chrome. If you must test from file:// with Chrome, run it with the --allow-file-access-from-files flag!)" );
|
7
|
+
});
|
8
|
+
|
9
|
+
test("Basic requirements", function() {
|
10
|
+
expect(7);
|
11
|
+
ok( Array.prototype.push, "Array.push()" );
|
12
|
+
ok( Function.prototype.apply, "Function.apply()" );
|
13
|
+
ok( document.getElementById, "getElementById" );
|
14
|
+
ok( document.getElementsByTagName, "getElementsByTagName" );
|
15
|
+
ok( RegExp, "RegExp" );
|
16
|
+
ok( jQuery, "jQuery" );
|
17
|
+
ok( $, "$" );
|
18
|
+
});
|
19
|
+
|
20
|
+
testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/cc_on.html", function( cc_on, errors, $ ) {
|
21
|
+
expect( 3 );
|
22
|
+
ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) );
|
23
|
+
deepEqual( errors, [], "No errors" );
|
24
|
+
ok( $(), "jQuery executes" );
|
25
|
+
});
|
26
|
+
|
27
|
+
test("jQuery()", function() {
|
28
|
+
|
29
|
+
var elem, i,
|
30
|
+
obj = jQuery("div"),
|
31
|
+
code = jQuery("<code/>"),
|
32
|
+
img = jQuery("<img/>"),
|
33
|
+
div = jQuery("<div/><hr/><code/><b/>"),
|
34
|
+
exec = false,
|
35
|
+
lng = "",
|
36
|
+
expected = 22,
|
37
|
+
attrObj = {
|
38
|
+
"text": "test",
|
39
|
+
"class": "test2",
|
40
|
+
"id": "test3"
|
41
|
+
};
|
42
|
+
|
43
|
+
// The $(html, props) signature can stealth-call any $.fn method, check for a
|
44
|
+
// few here but beware of modular builds where these methods may be excluded.
|
45
|
+
if ( jQuery.fn.click ) {
|
46
|
+
expected++;
|
47
|
+
attrObj["click"] = function() { ok( exec, "Click executed." ); };
|
48
|
+
}
|
49
|
+
if ( jQuery.fn.width ) {
|
50
|
+
expected++;
|
51
|
+
attrObj["width"] = 10;
|
52
|
+
}
|
53
|
+
if ( jQuery.fn.offset ) {
|
54
|
+
expected++;
|
55
|
+
attrObj["offset"] = { "top": 1, "left": 1 };
|
56
|
+
}
|
57
|
+
if ( jQuery.fn.css ) {
|
58
|
+
expected += 2;
|
59
|
+
attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 };
|
60
|
+
}
|
61
|
+
if ( jQuery.fn.attr ) {
|
62
|
+
expected++;
|
63
|
+
attrObj.attr = { "desired": "very" };
|
64
|
+
}
|
65
|
+
|
66
|
+
expect( expected );
|
67
|
+
|
68
|
+
// Basic constructor's behavior
|
69
|
+
equal( jQuery().length, 0, "jQuery() === jQuery([])" );
|
70
|
+
equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
|
71
|
+
equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
|
72
|
+
equal( jQuery("").length, 0, "jQuery('') === jQuery([])" );
|
73
|
+
equal( jQuery("#").length, 0, "jQuery('#') === jQuery([])" );
|
74
|
+
|
75
|
+
equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
|
76
|
+
|
77
|
+
// can actually yield more than one, when iframes are included, the window is an array as well
|
78
|
+
equal( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" );
|
79
|
+
|
80
|
+
/*
|
81
|
+
// disabled since this test was doing nothing. i tried to fix it but i'm not sure
|
82
|
+
// what the expected behavior should even be. FF returns "\n" for the text node
|
83
|
+
// make sure this is handled
|
84
|
+
var crlfContainer = jQuery('<p>\r\n</p>');
|
85
|
+
var x = crlfContainer.contents().get(0).nodeValue;
|
86
|
+
equal( x, what???, "Check for \\r and \\n in jQuery()" );
|
87
|
+
*/
|
88
|
+
|
89
|
+
/* // Disabled until we add this functionality in
|
90
|
+
var pass = true;
|
91
|
+
try {
|
92
|
+
jQuery("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
|
93
|
+
} catch(e){
|
94
|
+
pass = false;
|
95
|
+
}
|
96
|
+
ok( pass, "jQuery('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
|
97
|
+
|
98
|
+
equal( code.length, 1, "Correct number of elements generated for code" );
|
99
|
+
equal( code.parent().length, 0, "Make sure that the generated HTML has no parent." );
|
100
|
+
|
101
|
+
equal( img.length, 1, "Correct number of elements generated for img" );
|
102
|
+
equal( img.parent().length, 0, "Make sure that the generated HTML has no parent." );
|
103
|
+
|
104
|
+
equal( div.length, 4, "Correct number of elements generated for div hr code b" );
|
105
|
+
equal( div.parent().length, 0, "Make sure that the generated HTML has no parent." );
|
106
|
+
|
107
|
+
equal( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
|
108
|
+
|
109
|
+
equal( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" );
|
110
|
+
|
111
|
+
elem = jQuery(" <em>hello</em>")[0];
|
112
|
+
equal( elem.nodeName.toLowerCase(), "em", "leading space" );
|
113
|
+
|
114
|
+
elem = jQuery("\n\n<em>world</em>")[0];
|
115
|
+
equal( elem.nodeName.toLowerCase(), "em", "leading newlines" );
|
116
|
+
|
117
|
+
elem = jQuery("<div/>", attrObj );
|
118
|
+
|
119
|
+
if ( jQuery.fn.width ) {
|
120
|
+
equal( elem[0].style.width, "10px", "jQuery() quick setter width");
|
121
|
+
}
|
122
|
+
|
123
|
+
if ( jQuery.fn.offset ) {
|
124
|
+
equal( elem[0].style.top, "1px", "jQuery() quick setter offset");
|
125
|
+
}
|
126
|
+
|
127
|
+
if ( jQuery.fn.css ) {
|
128
|
+
equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
|
129
|
+
equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
|
130
|
+
}
|
131
|
+
|
132
|
+
if ( jQuery.fn.attr ) {
|
133
|
+
equal( elem[0].getAttribute("desired"), "very", "jQuery quick setter attr");
|
134
|
+
}
|
135
|
+
|
136
|
+
equal( elem[0].childNodes.length, 1, "jQuery quick setter text");
|
137
|
+
equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
|
138
|
+
equal( elem[0].className, "test2", "jQuery() quick setter class");
|
139
|
+
equal( elem[0].id, "test3", "jQuery() quick setter id");
|
140
|
+
|
141
|
+
exec = true;
|
142
|
+
elem.trigger("click");
|
143
|
+
|
144
|
+
// manually clean up detached elements
|
145
|
+
elem.remove();
|
146
|
+
|
147
|
+
for ( i = 0; i < 3; ++i ) {
|
148
|
+
elem = jQuery("<input type='text' value='TEST' />");
|
149
|
+
}
|
150
|
+
equal( elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" );
|
151
|
+
|
152
|
+
// manually clean up detached elements
|
153
|
+
elem.remove();
|
154
|
+
|
155
|
+
for ( i = 0; i < 128; i++ ) {
|
156
|
+
lng += "12345678";
|
157
|
+
}
|
158
|
+
});
|
159
|
+
|
160
|
+
test("jQuery(selector, context)", function() {
|
161
|
+
expect(3);
|
162
|
+
deepEqual( jQuery("div p", "#qunit-fixture").get(), q("sndp", "en", "sap"), "Basic selector with string as context" );
|
163
|
+
deepEqual( jQuery("div p", q("qunit-fixture")[0]).get(), q("sndp", "en", "sap"), "Basic selector with element as context" );
|
164
|
+
deepEqual( jQuery("div p", jQuery("#qunit-fixture")).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
|
165
|
+
});
|
166
|
+
|
167
|
+
test( "selector state", function() {
|
168
|
+
expect( 18 );
|
169
|
+
|
170
|
+
var test;
|
171
|
+
|
172
|
+
test = jQuery( undefined );
|
173
|
+
equal( test.selector, "", "Empty jQuery Selector" );
|
174
|
+
equal( test.context, undefined, "Empty jQuery Context" );
|
175
|
+
|
176
|
+
test = jQuery( document );
|
177
|
+
equal( test.selector, "", "Document Selector" );
|
178
|
+
equal( test.context, document, "Document Context" );
|
179
|
+
|
180
|
+
test = jQuery( document.body );
|
181
|
+
equal( test.selector, "", "Body Selector" );
|
182
|
+
equal( test.context, document.body, "Body Context" );
|
183
|
+
|
184
|
+
test = jQuery("#qunit-fixture");
|
185
|
+
equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
|
186
|
+
equal( test.context, document, "#qunit-fixture Context" );
|
187
|
+
|
188
|
+
test = jQuery("#notfoundnono");
|
189
|
+
equal( test.selector, "#notfoundnono", "#notfoundnono Selector" );
|
190
|
+
equal( test.context, document, "#notfoundnono Context" );
|
191
|
+
|
192
|
+
test = jQuery( "#qunit-fixture", document );
|
193
|
+
equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
|
194
|
+
equal( test.context, document, "#qunit-fixture Context" );
|
195
|
+
|
196
|
+
test = jQuery( "#qunit-fixture", document.body );
|
197
|
+
equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
|
198
|
+
equal( test.context, document.body, "#qunit-fixture Context" );
|
199
|
+
|
200
|
+
// Test cloning
|
201
|
+
test = jQuery( test );
|
202
|
+
equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
|
203
|
+
equal( test.context, document.body, "#qunit-fixture Context" );
|
204
|
+
|
205
|
+
test = jQuery( document.body ).find("#qunit-fixture");
|
206
|
+
equal( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" );
|
207
|
+
equal( test.context, document.body, "#qunit-fixture find Context" );
|
208
|
+
});
|
209
|
+
|
210
|
+
test( "globalEval", function() {
|
211
|
+
expect( 3 );
|
212
|
+
Globals.register("globalEvalTest");
|
213
|
+
|
214
|
+
jQuery.globalEval("globalEvalTest = 1;");
|
215
|
+
equal( window.globalEvalTest, 1, "Test variable assignments are global" );
|
216
|
+
|
217
|
+
jQuery.globalEval("var globalEvalTest = 2;");
|
218
|
+
equal( window.globalEvalTest, 2, "Test variable declarations are global" );
|
219
|
+
|
220
|
+
jQuery.globalEval("this.globalEvalTest = 3;");
|
221
|
+
equal( window.globalEvalTest, 3, "Test context (this) is the window object" );
|
222
|
+
});
|
223
|
+
|
224
|
+
test("noConflict", function() {
|
225
|
+
expect(7);
|
226
|
+
|
227
|
+
var $$ = jQuery;
|
228
|
+
|
229
|
+
strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
|
230
|
+
strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." );
|
231
|
+
strictEqual( window["$"], original$, "Make sure $ was reverted." );
|
232
|
+
|
233
|
+
jQuery = $ = $$;
|
234
|
+
|
235
|
+
strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
|
236
|
+
strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." );
|
237
|
+
strictEqual( window["$"], original$, "Make sure $ was reverted." );
|
238
|
+
ok( $$().pushStack([]), "Make sure that jQuery still works." );
|
239
|
+
|
240
|
+
window["jQuery"] = jQuery = $$;
|
241
|
+
});
|
242
|
+
|
243
|
+
test("trim", function() {
|
244
|
+
expect(13);
|
245
|
+
|
246
|
+
var nbsp = String.fromCharCode(160);
|
247
|
+
|
248
|
+
equal( jQuery.trim("hello "), "hello", "trailing space" );
|
249
|
+
equal( jQuery.trim(" hello"), "hello", "leading space" );
|
250
|
+
equal( jQuery.trim(" hello "), "hello", "space on both sides" );
|
251
|
+
equal( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", " " );
|
252
|
+
|
253
|
+
equal( jQuery.trim(), "", "Nothing in." );
|
254
|
+
equal( jQuery.trim( undefined ), "", "Undefined" );
|
255
|
+
equal( jQuery.trim( null ), "", "Null" );
|
256
|
+
equal( jQuery.trim( 5 ), "5", "Number" );
|
257
|
+
equal( jQuery.trim( false ), "false", "Boolean" );
|
258
|
+
|
259
|
+
equal( jQuery.trim(" "), "", "space should be trimmed" );
|
260
|
+
equal( jQuery.trim("ipad\xA0"), "ipad", "nbsp should be trimmed" );
|
261
|
+
equal( jQuery.trim("\uFEFF"), "", "zwsp should be trimmed" );
|
262
|
+
equal( jQuery.trim("\uFEFF \xA0! | \uFEFF"), "! |", "leading/trailing should be trimmed" );
|
263
|
+
});
|
264
|
+
|
265
|
+
test("type", function() {
|
266
|
+
expect( 28 );
|
267
|
+
|
268
|
+
equal( jQuery.type(null), "null", "null" );
|
269
|
+
equal( jQuery.type(undefined), "undefined", "undefined" );
|
270
|
+
equal( jQuery.type(true), "boolean", "Boolean" );
|
271
|
+
equal( jQuery.type(false), "boolean", "Boolean" );
|
272
|
+
equal( jQuery.type(Boolean(true)), "boolean", "Boolean" );
|
273
|
+
equal( jQuery.type(0), "number", "Number" );
|
274
|
+
equal( jQuery.type(1), "number", "Number" );
|
275
|
+
equal( jQuery.type(Number(1)), "number", "Number" );
|
276
|
+
equal( jQuery.type(""), "string", "String" );
|
277
|
+
equal( jQuery.type("a"), "string", "String" );
|
278
|
+
equal( jQuery.type(String("a")), "string", "String" );
|
279
|
+
equal( jQuery.type({}), "object", "Object" );
|
280
|
+
equal( jQuery.type(/foo/), "regexp", "RegExp" );
|
281
|
+
equal( jQuery.type(new RegExp("asdf")), "regexp", "RegExp" );
|
282
|
+
equal( jQuery.type([1]), "array", "Array" );
|
283
|
+
equal( jQuery.type(new Date()), "date", "Date" );
|
284
|
+
equal( jQuery.type(new Function("return;")), "function", "Function" );
|
285
|
+
equal( jQuery.type(function(){}), "function", "Function" );
|
286
|
+
equal( jQuery.type(new Error()), "error", "Error" );
|
287
|
+
equal( jQuery.type(window), "object", "Window" );
|
288
|
+
equal( jQuery.type(document), "object", "Document" );
|
289
|
+
equal( jQuery.type(document.body), "object", "Element" );
|
290
|
+
equal( jQuery.type(document.createTextNode("foo")), "object", "TextNode" );
|
291
|
+
equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" );
|
292
|
+
|
293
|
+
// Avoid Lint complaints
|
294
|
+
var MyString = String,
|
295
|
+
MyNumber = Number,
|
296
|
+
MyBoolean = Boolean,
|
297
|
+
MyObject = Object;
|
298
|
+
equal( jQuery.type(new MyBoolean(true)), "boolean", "Boolean" );
|
299
|
+
equal( jQuery.type(new MyNumber(1)), "number", "Number" );
|
300
|
+
equal( jQuery.type(new MyString("a")), "string", "String" );
|
301
|
+
equal( jQuery.type(new MyObject()), "object", "Object" );
|
302
|
+
});
|
303
|
+
|
304
|
+
asyncTest("isPlainObject", function() {
|
305
|
+
expect(16);
|
306
|
+
|
307
|
+
var pass, iframe, doc,
|
308
|
+
fn = function() {};
|
309
|
+
|
310
|
+
// The use case that we want to match
|
311
|
+
ok( jQuery.isPlainObject({}), "{}" );
|
312
|
+
|
313
|
+
// Not objects shouldn't be matched
|
314
|
+
ok( !jQuery.isPlainObject(""), "string" );
|
315
|
+
ok( !jQuery.isPlainObject(0) && !jQuery.isPlainObject(1), "number" );
|
316
|
+
ok( !jQuery.isPlainObject(true) && !jQuery.isPlainObject(false), "boolean" );
|
317
|
+
ok( !jQuery.isPlainObject(null), "null" );
|
318
|
+
ok( !jQuery.isPlainObject(undefined), "undefined" );
|
319
|
+
|
320
|
+
// Arrays shouldn't be matched
|
321
|
+
ok( !jQuery.isPlainObject([]), "array" );
|
322
|
+
|
323
|
+
// Instantiated objects shouldn't be matched
|
324
|
+
ok( !jQuery.isPlainObject(new Date()), "new Date" );
|
325
|
+
|
326
|
+
// Functions shouldn't be matched
|
327
|
+
ok( !jQuery.isPlainObject(fn), "fn" );
|
328
|
+
|
329
|
+
// Again, instantiated objects shouldn't be matched
|
330
|
+
ok( !jQuery.isPlainObject(new fn()), "new fn (no methods)" );
|
331
|
+
|
332
|
+
// Makes the function a little more realistic
|
333
|
+
// (and harder to detect, incidentally)
|
334
|
+
fn.prototype["someMethod"] = function(){};
|
335
|
+
|
336
|
+
// Again, instantiated objects shouldn't be matched
|
337
|
+
ok( !jQuery.isPlainObject(new fn()), "new fn" );
|
338
|
+
|
339
|
+
// Make it even harder to detect in IE < 9
|
340
|
+
fn = function() {
|
341
|
+
this.a = "a";
|
342
|
+
};
|
343
|
+
fn.prototype = {
|
344
|
+
b: "b"
|
345
|
+
};
|
346
|
+
|
347
|
+
ok( !jQuery.isPlainObject(new fn()), "fn (inherited and own properties)");
|
348
|
+
|
349
|
+
// DOM Element
|
350
|
+
ok( !jQuery.isPlainObject( document.createElement("div") ), "DOM Element" );
|
351
|
+
|
352
|
+
// Window
|
353
|
+
ok( !jQuery.isPlainObject( window ), "window" );
|
354
|
+
|
355
|
+
pass = false;
|
356
|
+
try {
|
357
|
+
jQuery.isPlainObject( window.location );
|
358
|
+
pass = true;
|
359
|
+
} catch ( e ) {}
|
360
|
+
ok( pass, "Does not throw exceptions on host objects" );
|
361
|
+
|
362
|
+
// Objects from other windows should be matched
|
363
|
+
window.iframeCallback = function( otherObject, detail ) {
|
364
|
+
window.iframeCallback = undefined;
|
365
|
+
iframe.parentNode.removeChild( iframe );
|
366
|
+
ok( jQuery.isPlainObject(new otherObject()), "new otherObject" + ( detail ? " - " + detail : "" ) );
|
367
|
+
start();
|
368
|
+
};
|
369
|
+
|
370
|
+
try {
|
371
|
+
iframe = jQuery("#qunit-fixture")[0].appendChild( document.createElement("iframe") );
|
372
|
+
doc = iframe.contentDocument || iframe.contentWindow.document;
|
373
|
+
doc.open();
|
374
|
+
doc.write("<body onload='window.parent.iframeCallback(Object);'>");
|
375
|
+
doc.close();
|
376
|
+
} catch(e) {
|
377
|
+
window.iframeDone( Object, "iframes not supported" );
|
378
|
+
}
|
379
|
+
});
|
380
|
+
|
381
|
+
test("isFunction", function() {
|
382
|
+
expect(19);
|
383
|
+
|
384
|
+
var mystr, myarr, myfunction, fn, obj, nodes, first, input, a;
|
385
|
+
|
386
|
+
// Make sure that false values return false
|
387
|
+
ok( !jQuery.isFunction(), "No Value" );
|
388
|
+
ok( !jQuery.isFunction( null ), "null Value" );
|
389
|
+
ok( !jQuery.isFunction( undefined ), "undefined Value" );
|
390
|
+
ok( !jQuery.isFunction( "" ), "Empty String Value" );
|
391
|
+
ok( !jQuery.isFunction( 0 ), "0 Value" );
|
392
|
+
|
393
|
+
// Check built-ins
|
394
|
+
// Safari uses "(Internal Function)"
|
395
|
+
ok( jQuery.isFunction(String), "String Function("+String+")" );
|
396
|
+
ok( jQuery.isFunction(Array), "Array Function("+Array+")" );
|
397
|
+
ok( jQuery.isFunction(Object), "Object Function("+Object+")" );
|
398
|
+
ok( jQuery.isFunction(Function), "Function Function("+Function+")" );
|
399
|
+
|
400
|
+
// When stringified, this could be misinterpreted
|
401
|
+
mystr = "function";
|
402
|
+
ok( !jQuery.isFunction(mystr), "Function String" );
|
403
|
+
|
404
|
+
// When stringified, this could be misinterpreted
|
405
|
+
myarr = [ "function" ];
|
406
|
+
ok( !jQuery.isFunction(myarr), "Function Array" );
|
407
|
+
|
408
|
+
// When stringified, this could be misinterpreted
|
409
|
+
myfunction = { "function": "test" };
|
410
|
+
ok( !jQuery.isFunction(myfunction), "Function Object" );
|
411
|
+
|
412
|
+
// Make sure normal functions still work
|
413
|
+
fn = function(){};
|
414
|
+
ok( jQuery.isFunction(fn), "Normal Function" );
|
415
|
+
|
416
|
+
obj = document.createElement("object");
|
417
|
+
|
418
|
+
// Firefox says this is a function
|
419
|
+
ok( !jQuery.isFunction(obj), "Object Element" );
|
420
|
+
|
421
|
+
// IE says this is an object
|
422
|
+
// Since 1.3, this isn't supported (#2968)
|
423
|
+
//ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
|
424
|
+
|
425
|
+
nodes = document.body.childNodes;
|
426
|
+
|
427
|
+
// Safari says this is a function
|
428
|
+
ok( !jQuery.isFunction(nodes), "childNodes Property" );
|
429
|
+
|
430
|
+
first = document.body.firstChild;
|
431
|
+
|
432
|
+
// Normal elements are reported ok everywhere
|
433
|
+
ok( !jQuery.isFunction(first), "A normal DOM Element" );
|
434
|
+
|
435
|
+
input = document.createElement("input");
|
436
|
+
input.type = "text";
|
437
|
+
document.body.appendChild( input );
|
438
|
+
|
439
|
+
// IE says this is an object
|
440
|
+
// Since 1.3, this isn't supported (#2968)
|
441
|
+
//ok( jQuery.isFunction(input.focus), "A default function property" );
|
442
|
+
|
443
|
+
document.body.removeChild( input );
|
444
|
+
|
445
|
+
a = document.createElement("a");
|
446
|
+
a.href = "some-function";
|
447
|
+
document.body.appendChild( a );
|
448
|
+
|
449
|
+
// This serializes with the word 'function' in it
|
450
|
+
ok( !jQuery.isFunction(a), "Anchor Element" );
|
451
|
+
|
452
|
+
document.body.removeChild( a );
|
453
|
+
|
454
|
+
// Recursive function calls have lengths and array-like properties
|
455
|
+
function callme(callback){
|
456
|
+
function fn(response){
|
457
|
+
callback(response);
|
458
|
+
}
|
459
|
+
|
460
|
+
ok( jQuery.isFunction(fn), "Recursive Function Call" );
|
461
|
+
|
462
|
+
fn({ some: "data" });
|
463
|
+
}
|
464
|
+
|
465
|
+
callme(function(){
|
466
|
+
callme(function(){});
|
467
|
+
});
|
468
|
+
});
|
469
|
+
|
470
|
+
test( "isNumeric", function() {
|
471
|
+
expect( 36 );
|
472
|
+
|
473
|
+
var t = jQuery.isNumeric,
|
474
|
+
Traditionalists = /** @constructor */ function(n) {
|
475
|
+
this.value = n;
|
476
|
+
this.toString = function(){
|
477
|
+
return String(this.value);
|
478
|
+
};
|
479
|
+
},
|
480
|
+
answer = new Traditionalists( "42" ),
|
481
|
+
rong = new Traditionalists( "Devo" );
|
482
|
+
|
483
|
+
ok( t("-10"), "Negative integer string");
|
484
|
+
ok( t("0"), "Zero string");
|
485
|
+
ok( t("5"), "Positive integer string");
|
486
|
+
ok( t(-16), "Negative integer number");
|
487
|
+
ok( t(0), "Zero integer number");
|
488
|
+
ok( t(32), "Positive integer number");
|
489
|
+
ok( t("040"), "Octal integer literal string");
|
490
|
+
// OctalIntegerLiteral has been deprecated since ES3/1999
|
491
|
+
// It doesn't pass lint, so disabling until a solution can be found
|
492
|
+
//ok( t(0144), "Octal integer literal");
|
493
|
+
ok( t("0xFF"), "Hexadecimal integer literal string");
|
494
|
+
ok( t(0xFFF), "Hexadecimal integer literal");
|
495
|
+
ok( t("-1.6"), "Negative floating point string");
|
496
|
+
ok( t("4.536"), "Positive floating point string");
|
497
|
+
ok( t(-2.6), "Negative floating point number");
|
498
|
+
ok( t(3.1415), "Positive floating point number");
|
499
|
+
ok( t(8e5), "Exponential notation");
|
500
|
+
ok( t("123e-2"), "Exponential notation string");
|
501
|
+
ok( t(answer), "Custom .toString returning number");
|
502
|
+
equal( t(""), false, "Empty string");
|
503
|
+
equal( t(" "), false, "Whitespace characters string");
|
504
|
+
equal( t("\t\t"), false, "Tab characters string");
|
505
|
+
equal( t("abcdefghijklm1234567890"), false, "Alphanumeric character string");
|
506
|
+
equal( t("xabcdefx"), false, "Non-numeric character string");
|
507
|
+
equal( t(true), false, "Boolean true literal");
|
508
|
+
equal( t(false), false, "Boolean false literal");
|
509
|
+
equal( t("bcfed5.2"), false, "Number with preceding non-numeric characters");
|
510
|
+
equal( t("7.2acdgs"), false, "Number with trailling non-numeric characters");
|
511
|
+
equal( t(undefined), false, "Undefined value");
|
512
|
+
equal( t(null), false, "Null value");
|
513
|
+
equal( t(NaN), false, "NaN value");
|
514
|
+
equal( t(Infinity), false, "Infinity primitive");
|
515
|
+
equal( t(Number.POSITIVE_INFINITY), false, "Positive Infinity");
|
516
|
+
equal( t(Number.NEGATIVE_INFINITY), false, "Negative Infinity");
|
517
|
+
equal( t(rong), false, "Custom .toString returning non-number");
|
518
|
+
equal( t({}), false, "Empty object");
|
519
|
+
equal( t(function(){} ), false, "Instance of a function");
|
520
|
+
equal( t( new Date() ), false, "Instance of a Date");
|
521
|
+
equal( t(function(){} ), false, "Instance of a function");
|
522
|
+
});
|
523
|
+
|
524
|
+
test("isXMLDoc - HTML", function() {
|
525
|
+
expect(4);
|
526
|
+
|
527
|
+
ok( !jQuery.isXMLDoc( document ), "HTML document" );
|
528
|
+
ok( !jQuery.isXMLDoc( document.documentElement ), "HTML documentElement" );
|
529
|
+
ok( !jQuery.isXMLDoc( document.body ), "HTML Body Element" );
|
530
|
+
|
531
|
+
var body,
|
532
|
+
iframe = document.createElement("iframe");
|
533
|
+
document.body.appendChild( iframe );
|
534
|
+
|
535
|
+
try {
|
536
|
+
body = jQuery(iframe).contents()[0];
|
537
|
+
|
538
|
+
try {
|
539
|
+
ok( !jQuery.isXMLDoc( body ), "Iframe body element" );
|
540
|
+
} catch(e) {
|
541
|
+
ok( false, "Iframe body element exception" );
|
542
|
+
}
|
543
|
+
|
544
|
+
} catch(e) {
|
545
|
+
ok( true, "Iframe body element - iframe not working correctly" );
|
546
|
+
}
|
547
|
+
|
548
|
+
document.body.removeChild( iframe );
|
549
|
+
});
|
550
|
+
|
551
|
+
test("XSS via location.hash", function() {
|
552
|
+
expect(1);
|
553
|
+
|
554
|
+
stop();
|
555
|
+
jQuery["_check9521"] = function(x){
|
556
|
+
ok( x, "script called from #id-like selector with inline handler" );
|
557
|
+
jQuery("#check9521").remove();
|
558
|
+
delete jQuery["_check9521"];
|
559
|
+
start();
|
560
|
+
};
|
561
|
+
try {
|
562
|
+
// This throws an error because it's processed like an id
|
563
|
+
jQuery( "#<img id='check9521' src='no-such-.gif' onerror='jQuery._check9521(false)'>" ).appendTo("#qunit-fixture");
|
564
|
+
} catch (err) {
|
565
|
+
jQuery["_check9521"](true);
|
566
|
+
}
|
567
|
+
});
|
568
|
+
|
569
|
+
test("isXMLDoc - XML", function() {
|
570
|
+
expect(3);
|
571
|
+
var xml = createDashboardXML();
|
572
|
+
ok( jQuery.isXMLDoc( xml ), "XML document" );
|
573
|
+
ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" );
|
574
|
+
ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" );
|
575
|
+
});
|
576
|
+
|
577
|
+
test("isWindow", function() {
|
578
|
+
expect( 14 );
|
579
|
+
|
580
|
+
ok( jQuery.isWindow(window), "window" );
|
581
|
+
ok( jQuery.isWindow(document.getElementsByTagName("iframe")[0].contentWindow), "iframe.contentWindow" );
|
582
|
+
ok( !jQuery.isWindow(), "empty" );
|
583
|
+
ok( !jQuery.isWindow(null), "null" );
|
584
|
+
ok( !jQuery.isWindow(undefined), "undefined" );
|
585
|
+
ok( !jQuery.isWindow(document), "document" );
|
586
|
+
ok( !jQuery.isWindow(document.documentElement), "documentElement" );
|
587
|
+
ok( !jQuery.isWindow(""), "string" );
|
588
|
+
ok( !jQuery.isWindow(1), "number" );
|
589
|
+
ok( !jQuery.isWindow(true), "boolean" );
|
590
|
+
ok( !jQuery.isWindow({}), "object" );
|
591
|
+
ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" );
|
592
|
+
ok( !jQuery.isWindow(/window/), "regexp" );
|
593
|
+
ok( !jQuery.isWindow(function(){}), "function" );
|
594
|
+
});
|
595
|
+
|
596
|
+
test("jQuery('html')", function() {
|
597
|
+
expect( 15 );
|
598
|
+
|
599
|
+
var s, div, j;
|
600
|
+
|
601
|
+
QUnit.reset();
|
602
|
+
jQuery["foo"] = false;
|
603
|
+
s = jQuery("<script>jQuery.foo='test';</script>")[0];
|
604
|
+
ok( s, "Creating a script" );
|
605
|
+
ok( !jQuery["foo"], "Make sure the script wasn't executed prematurely" );
|
606
|
+
jQuery("body").append("<script>jQuery.foo='test';</script>");
|
607
|
+
ok( jQuery["foo"], "Executing a scripts contents in the right context" );
|
608
|
+
|
609
|
+
// Test multi-line HTML
|
610
|
+
div = jQuery("<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>")[0];
|
611
|
+
equal( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." );
|
612
|
+
equal( div.firstChild.nodeType, 3, "Text node." );
|
613
|
+
equal( div.lastChild.nodeType, 3, "Text node." );
|
614
|
+
equal( div.childNodes[1].nodeType, 1, "Paragraph." );
|
615
|
+
equal( div.childNodes[1].firstChild.nodeType, 3, "Paragraph text." );
|
616
|
+
|
617
|
+
QUnit.reset();
|
618
|
+
ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" );
|
619
|
+
|
620
|
+
ok( !jQuery("<script/>")[0].parentNode, "Create a script" );
|
621
|
+
|
622
|
+
ok( jQuery("<input/>").attr("type", "hidden"), "Create an input and set the type." );
|
623
|
+
|
624
|
+
j = jQuery("<span>hi</span> there <!-- mon ami -->");
|
625
|
+
ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
|
626
|
+
|
627
|
+
ok( !jQuery("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
|
628
|
+
|
629
|
+
ok( jQuery("<div></div>")[0], "Create a div with closing tag." );
|
630
|
+
ok( jQuery("<table></table>")[0], "Create a table with closing tag." );
|
631
|
+
|
632
|
+
// equal( jQuery("element[attribute='<div></div>']").length, 0, "When html is within brackets, do not recognize as html." );
|
633
|
+
// equal( jQuery("element[attribute=<div></div>]").length, 0, "When html is within brackets, do not recognize as html." );
|
634
|
+
// equal( jQuery("element:not(<div></div>)").length, 0, "When html is within parens, do not recognize as html." );
|
635
|
+
// equal( jQuery("\\<div\\>").length, 0, "Ignore escaped html characters" );
|
636
|
+
});
|
637
|
+
|
638
|
+
test("jQuery('massive html #7990')", function() {
|
639
|
+
expect( 3 );
|
640
|
+
|
641
|
+
var i,
|
642
|
+
li = "<li>very very very very large html string</li>",
|
643
|
+
html = ["<ul>"];
|
644
|
+
|
645
|
+
for ( i = 0; i < 30000; i += 1 ) {
|
646
|
+
html[html.length] = li;
|
647
|
+
}
|
648
|
+
html[html.length] = "</ul>";
|
649
|
+
html = jQuery(html.join(""))[0];
|
650
|
+
equal( html.nodeName.toLowerCase(), "ul");
|
651
|
+
equal( html.firstChild.nodeName.toLowerCase(), "li");
|
652
|
+
equal( html.childNodes.length, 30000 );
|
653
|
+
});
|
654
|
+
|
655
|
+
test("jQuery('html', context)", function() {
|
656
|
+
expect(1);
|
657
|
+
|
658
|
+
var $div = jQuery("<div/>")[0],
|
659
|
+
$span = jQuery("<span/>", $div);
|
660
|
+
equal($span.length, 1, "verify a span created with a div context works, #1763");
|
661
|
+
});
|
662
|
+
|
663
|
+
test("jQuery(selector, xml).text(str) - loaded via xml document", function() {
|
664
|
+
expect(2);
|
665
|
+
|
666
|
+
var xml = createDashboardXML(),
|
667
|
+
// tests for #1419 where ie was a problem
|
668
|
+
tab = jQuery("tab", xml).eq(0);
|
669
|
+
equal( tab.text(), "blabla", "verify initial text correct" );
|
670
|
+
tab.text("newtext");
|
671
|
+
equal( tab.text(), "newtext", "verify new text correct" );
|
672
|
+
});
|
673
|
+
|
674
|
+
test("end()", function() {
|
675
|
+
expect(3);
|
676
|
+
equal( "Yahoo", jQuery("#yahoo").parent().end().text(), "check for end" );
|
677
|
+
ok( jQuery("#yahoo").end(), "check for end with nothing to end" );
|
678
|
+
|
679
|
+
var x = jQuery("#yahoo");
|
680
|
+
x.parent();
|
681
|
+
equal( "Yahoo", jQuery("#yahoo").text(), "check for non-destructive behaviour" );
|
682
|
+
});
|
683
|
+
|
684
|
+
test("length", function() {
|
685
|
+
expect(1);
|
686
|
+
equal( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" );
|
687
|
+
});
|
688
|
+
|
689
|
+
test("get()", function() {
|
690
|
+
expect(1);
|
691
|
+
deepEqual( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
|
692
|
+
});
|
693
|
+
|
694
|
+
test("toArray()", function() {
|
695
|
+
expect(1);
|
696
|
+
deepEqual( jQuery("#qunit-fixture p").toArray(),
|
697
|
+
q("firstp","ap","sndp","en","sap","first"),
|
698
|
+
"Convert jQuery object to an Array" );
|
699
|
+
});
|
700
|
+
|
701
|
+
test("inArray()", function() {
|
702
|
+
expect(19);
|
703
|
+
|
704
|
+
var selections = {
|
705
|
+
p: q("firstp", "sap", "ap", "first"),
|
706
|
+
em: q("siblingnext", "siblingfirst"),
|
707
|
+
div: q("qunit-testrunner-toolbar", "nothiddendiv", "nothiddendivchild", "foo"),
|
708
|
+
a: q("mark", "groups", "google", "simon1"),
|
709
|
+
empty: []
|
710
|
+
},
|
711
|
+
tests = {
|
712
|
+
p: { elem: jQuery("#ap")[0], index: 2 },
|
713
|
+
em: { elem: jQuery("#siblingfirst")[0], index: 1 },
|
714
|
+
div: { elem: jQuery("#nothiddendiv")[0], index: 1 },
|
715
|
+
a: { elem: jQuery("#simon1")[0], index: 3 }
|
716
|
+
},
|
717
|
+
falseTests = {
|
718
|
+
p: jQuery("#liveSpan1")[0],
|
719
|
+
em: jQuery("#nothiddendiv")[0],
|
720
|
+
empty: ""
|
721
|
+
};
|
722
|
+
|
723
|
+
jQuery.each( tests, function( key, obj ) {
|
724
|
+
equal( jQuery.inArray( obj.elem, selections[ key ] ), obj.index, "elem is in the array of selections of its tag" );
|
725
|
+
// Third argument (fromIndex)
|
726
|
+
equal( !!~jQuery.inArray( obj.elem, selections[ key ], 5 ), false, "elem is NOT in the array of selections given a starting index greater than its position" );
|
727
|
+
equal( !!~jQuery.inArray( obj.elem, selections[ key ], 1 ), true, "elem is in the array of selections given a starting index less than or equal to its position" );
|
728
|
+
equal( !!~jQuery.inArray( obj.elem, selections[ key ], -3 ), true, "elem is in the array of selections given a negative index" );
|
729
|
+
});
|
730
|
+
|
731
|
+
jQuery.each( falseTests, function( key, elem ) {
|
732
|
+
equal( !!~jQuery.inArray( elem, selections[ key ] ), false, "elem is NOT in the array of selections" );
|
733
|
+
});
|
734
|
+
|
735
|
+
});
|
736
|
+
|
737
|
+
test("get(Number)", function() {
|
738
|
+
expect(2);
|
739
|
+
equal( jQuery("#qunit-fixture p").get(0), document.getElementById("firstp"), "Get A Single Element" );
|
740
|
+
strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
|
741
|
+
});
|
742
|
+
|
743
|
+
test("get(-Number)",function() {
|
744
|
+
expect(2);
|
745
|
+
equal( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" );
|
746
|
+
strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" );
|
747
|
+
});
|
748
|
+
|
749
|
+
test("each(Function)", function() {
|
750
|
+
expect(1);
|
751
|
+
var div, pass, i;
|
752
|
+
|
753
|
+
div = jQuery("div");
|
754
|
+
div.each(function(){this.foo = "zoo";});
|
755
|
+
pass = true;
|
756
|
+
for ( i = 0; i < div.length; i++ ) {
|
757
|
+
if ( div.get(i).foo !== "zoo" ) {
|
758
|
+
pass = false;
|
759
|
+
}
|
760
|
+
}
|
761
|
+
ok( pass, "Execute a function, Relative" );
|
762
|
+
});
|
763
|
+
|
764
|
+
test("slice()", function() {
|
765
|
+
expect(7);
|
766
|
+
|
767
|
+
var $links = jQuery("#ap a");
|
768
|
+
|
769
|
+
deepEqual( $links.slice(1,2).get(), q("groups"), "slice(1,2)" );
|
770
|
+
deepEqual( $links.slice(1).get(), q("groups", "anchor1", "mark"), "slice(1)" );
|
771
|
+
deepEqual( $links.slice(0,3).get(), q("google", "groups", "anchor1"), "slice(0,3)" );
|
772
|
+
deepEqual( $links.slice(-1).get(), q("mark"), "slice(-1)" );
|
773
|
+
|
774
|
+
deepEqual( $links.eq(1).get(), q("groups"), "eq(1)" );
|
775
|
+
deepEqual( $links.eq("2").get(), q("anchor1"), "eq('2')" );
|
776
|
+
deepEqual( $links.eq(-1).get(), q("mark"), "eq(-1)" );
|
777
|
+
});
|
778
|
+
|
779
|
+
test("first()/last()", function() {
|
780
|
+
expect(4);
|
781
|
+
|
782
|
+
var $links = jQuery("#ap a"), $none = jQuery("asdf");
|
783
|
+
|
784
|
+
deepEqual( $links.first().get(), q("google"), "first()" );
|
785
|
+
deepEqual( $links.last().get(), q("mark"), "last()" );
|
786
|
+
|
787
|
+
deepEqual( $none.first().get(), [], "first() none" );
|
788
|
+
deepEqual( $none.last().get(), [], "last() none" );
|
789
|
+
});
|
790
|
+
|
791
|
+
test("map()", function() {
|
792
|
+
expect( 2 );
|
793
|
+
|
794
|
+
deepEqual(
|
795
|
+
jQuery("#ap").map(function() {
|
796
|
+
return jQuery( this ).find("a").get();
|
797
|
+
}).get(),
|
798
|
+
q( "google", "groups", "anchor1", "mark" ),
|
799
|
+
"Array Map"
|
800
|
+
);
|
801
|
+
|
802
|
+
deepEqual(
|
803
|
+
jQuery("#ap > a").map(function() {
|
804
|
+
return this.parentNode;
|
805
|
+
}).get(),
|
806
|
+
q( "ap","ap","ap" ),
|
807
|
+
"Single Map"
|
808
|
+
);
|
809
|
+
});
|
810
|
+
|
811
|
+
test("jQuery.map", function() {
|
812
|
+
expect( 25 );
|
813
|
+
|
814
|
+
var i, label, result, callback;
|
815
|
+
|
816
|
+
result = jQuery.map( [ 3, 4, 5 ], function( v, k ) {
|
817
|
+
return k;
|
818
|
+
});
|
819
|
+
equal( result.join(""), "012", "Map the keys from an array" );
|
820
|
+
|
821
|
+
result = jQuery.map( [ 3, 4, 5 ], function( v ) {
|
822
|
+
return v;
|
823
|
+
});
|
824
|
+
equal( result.join(""), "345", "Map the values from an array" );
|
825
|
+
|
826
|
+
result = jQuery.map( { a: 1, b: 2 }, function( v, k ) {
|
827
|
+
return k;
|
828
|
+
});
|
829
|
+
equal( result.join(""), "ab", "Map the keys from an object" );
|
830
|
+
|
831
|
+
result = jQuery.map( { a: 1, b: 2 }, function( v ) {
|
832
|
+
return v;
|
833
|
+
});
|
834
|
+
equal( result.join(""), "12", "Map the values from an object" );
|
835
|
+
|
836
|
+
result = jQuery.map( [ "a", undefined, null, "b" ], function( v ) {
|
837
|
+
return v;
|
838
|
+
});
|
839
|
+
equal( result.join(""), "ab", "Array iteration does not include undefined/null results" );
|
840
|
+
|
841
|
+
result = jQuery.map( { a: "a", b: undefined, c: null, d: "b" }, function( v ) {
|
842
|
+
return v;
|
843
|
+
});
|
844
|
+
equal( result.join(""), "ab", "Object iteration does not include undefined/null results" );
|
845
|
+
|
846
|
+
result = {
|
847
|
+
Zero: function() {},
|
848
|
+
One: function( a ) { a = a; },
|
849
|
+
Two: function( a, b ) { a = a; b = b; }
|
850
|
+
};
|
851
|
+
callback = function( v, k ) {
|
852
|
+
equal( k, "foo", label + "-argument function treated like object" );
|
853
|
+
};
|
854
|
+
for ( i in result ) {
|
855
|
+
label = i;
|
856
|
+
result[ i ].foo = "bar";
|
857
|
+
jQuery.map( result[ i ], callback );
|
858
|
+
}
|
859
|
+
|
860
|
+
result = {
|
861
|
+
"undefined": undefined,
|
862
|
+
"null": null,
|
863
|
+
"false": false,
|
864
|
+
"true": true,
|
865
|
+
"empty string": "",
|
866
|
+
"nonempty string": "string",
|
867
|
+
"string \"0\"": "0",
|
868
|
+
"negative": -1,
|
869
|
+
"excess": 1
|
870
|
+
};
|
871
|
+
callback = function( v, k ) {
|
872
|
+
equal( k, "length", "Object with " + label + " length treated like object" );
|
873
|
+
};
|
874
|
+
for ( i in result ) {
|
875
|
+
label = i;
|
876
|
+
jQuery.map( { length: result[ i ] }, callback );
|
877
|
+
}
|
878
|
+
|
879
|
+
result = {
|
880
|
+
"sparse Array": Array( 4 ),
|
881
|
+
"length: 1 plain object": { length: 1, "0": true },
|
882
|
+
"length: 2 plain object": { length: 2, "0": true, "1": true },
|
883
|
+
NodeList: document.getElementsByTagName("html")
|
884
|
+
};
|
885
|
+
callback = function( v, k ) {
|
886
|
+
if ( result[ label ] ) {
|
887
|
+
delete result[ label ];
|
888
|
+
equal( k, "0", label + " treated like array" );
|
889
|
+
}
|
890
|
+
};
|
891
|
+
for ( i in result ) {
|
892
|
+
label = i;
|
893
|
+
jQuery.map( result[ i ], callback );
|
894
|
+
}
|
895
|
+
|
896
|
+
result = false;
|
897
|
+
jQuery.map( { length: 0 }, function() {
|
898
|
+
result = true;
|
899
|
+
});
|
900
|
+
ok( !result, "length: 0 plain object treated like array" );
|
901
|
+
|
902
|
+
result = false;
|
903
|
+
jQuery.map( document.getElementsByTagName("asdf"), function() {
|
904
|
+
result = true;
|
905
|
+
});
|
906
|
+
ok( !result, "empty NodeList treated like array" );
|
907
|
+
|
908
|
+
result = jQuery.map( Array(4), function( v, k ){
|
909
|
+
return k % 2 ? k : [k,k,k];
|
910
|
+
});
|
911
|
+
equal( result.join(""), "00012223", "Array results flattened (#2616)" );
|
912
|
+
});
|
913
|
+
|
914
|
+
test("jQuery.merge()", function() {
|
915
|
+
expect(8);
|
916
|
+
|
917
|
+
deepEqual( jQuery.merge([],[]), [], "Empty arrays" );
|
918
|
+
|
919
|
+
deepEqual( jQuery.merge([ 1 ],[ 2 ]), [ 1, 2 ], "Basic" );
|
920
|
+
deepEqual( jQuery.merge([ 1, 2 ], [ 3, 4 ]), [ 1, 2, 3, 4 ], "Basic" );
|
921
|
+
|
922
|
+
deepEqual( jQuery.merge([ 1, 2 ],[]), [ 1, 2 ], "Second empty" );
|
923
|
+
deepEqual( jQuery.merge([],[ 1, 2 ]), [ 1, 2 ], "First empty" );
|
924
|
+
|
925
|
+
// Fixed at [5998], #3641
|
926
|
+
deepEqual( jQuery.merge([ -2, -1 ], [ 0, 1, 2 ]), [ -2, -1 , 0, 1, 2 ],
|
927
|
+
"Second array including a zero (falsy)");
|
928
|
+
|
929
|
+
// After fixing #5527
|
930
|
+
deepEqual( jQuery.merge([], [ null, undefined ]), [ null, undefined ],
|
931
|
+
"Second array including null and undefined values");
|
932
|
+
deepEqual( jQuery.merge({ length: 0 }, [ 1, 2 ] ), { length: 2, 0: 1, 1: 2},
|
933
|
+
"First array like");
|
934
|
+
});
|
935
|
+
|
936
|
+
test("jQuery.extend(Object, Object)", function() {
|
937
|
+
expect(28);
|
938
|
+
|
939
|
+
var empty, optionsWithLength, optionsWithDate, myKlass,
|
940
|
+
customObject, optionsWithCustomObject, MyNumber, ret,
|
941
|
+
nullUndef, target, recursive, obj,
|
942
|
+
defaults, defaultsCopy, options1, options1Copy, options2, options2Copy, merged2,
|
943
|
+
settings = { "xnumber1": 5, "xnumber2": 7, "xstring1": "peter", "xstring2": "pan" },
|
944
|
+
options = { "xnumber2": 1, "xstring2": "x", "xxx": "newstring" },
|
945
|
+
optionsCopy = { "xnumber2": 1, "xstring2": "x", "xxx": "newstring" },
|
946
|
+
merged = { "xnumber1": 5, "xnumber2": 1, "xstring1": "peter", "xstring2": "x", "xxx": "newstring" },
|
947
|
+
deep1 = { "foo": { "bar": true } },
|
948
|
+
deep2 = { "foo": { "baz": true }, "foo2": document },
|
949
|
+
deep2copy = { "foo": { "baz": true }, "foo2": document },
|
950
|
+
deepmerged = { "foo": { "bar": true, "baz": true }, "foo2": document },
|
951
|
+
arr = [1, 2, 3],
|
952
|
+
nestedarray = { "arr": arr };
|
953
|
+
|
954
|
+
jQuery.extend(settings, options);
|
955
|
+
deepEqual( settings, merged, "Check if extended: settings must be extended" );
|
956
|
+
deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
|
957
|
+
|
958
|
+
jQuery.extend(settings, null, options);
|
959
|
+
deepEqual( settings, merged, "Check if extended: settings must be extended" );
|
960
|
+
deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
|
961
|
+
|
962
|
+
jQuery.extend(true, deep1, deep2);
|
963
|
+
deepEqual( deep1["foo"], deepmerged["foo"], "Check if foo: settings must be extended" );
|
964
|
+
deepEqual( deep2["foo"], deep2copy["foo"], "Check if not deep2: options must not be modified" );
|
965
|
+
equal( deep1["foo2"], document, "Make sure that a deep clone was not attempted on the document" );
|
966
|
+
|
967
|
+
ok( jQuery.extend(true, {}, nestedarray)["arr"] !== arr, "Deep extend of object must clone child array" );
|
968
|
+
|
969
|
+
// #5991
|
970
|
+
ok( jQuery.isArray( jQuery.extend(true, { "arr": {} }, nestedarray)["arr"] ), "Cloned array have to be an Array" );
|
971
|
+
ok( jQuery.isPlainObject( jQuery.extend(true, { "arr": arr }, { "arr": {} })["arr"] ), "Cloned object have to be an plain object" );
|
972
|
+
|
973
|
+
empty = {};
|
974
|
+
optionsWithLength = { "foo": { "length": -1 } };
|
975
|
+
jQuery.extend(true, empty, optionsWithLength);
|
976
|
+
deepEqual( empty["foo"], optionsWithLength["foo"], "The length property must copy correctly" );
|
977
|
+
|
978
|
+
empty = {};
|
979
|
+
optionsWithDate = { "foo": { "date": new Date() } };
|
980
|
+
jQuery.extend(true, empty, optionsWithDate);
|
981
|
+
deepEqual( empty["foo"], optionsWithDate["foo"], "Dates copy correctly" );
|
982
|
+
|
983
|
+
/** @constructor */
|
984
|
+
myKlass = function() {};
|
985
|
+
customObject = new myKlass();
|
986
|
+
optionsWithCustomObject = { "foo": { "date": customObject } };
|
987
|
+
empty = {};
|
988
|
+
jQuery.extend(true, empty, optionsWithCustomObject);
|
989
|
+
ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly (no methods)" );
|
990
|
+
|
991
|
+
// Makes the class a little more realistic
|
992
|
+
myKlass.prototype = { "someMethod": function(){} };
|
993
|
+
empty = {};
|
994
|
+
jQuery.extend(true, empty, optionsWithCustomObject);
|
995
|
+
ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly" );
|
996
|
+
|
997
|
+
MyNumber = Number;
|
998
|
+
|
999
|
+
ret = jQuery.extend(true, { "foo": 4 }, { "foo": new MyNumber(5) } );
|
1000
|
+
ok( parseInt(ret.foo, 10) === 5, "Wrapped numbers copy correctly" );
|
1001
|
+
|
1002
|
+
nullUndef;
|
1003
|
+
nullUndef = jQuery.extend({}, options, { "xnumber2": null });
|
1004
|
+
ok( nullUndef["xnumber2"] === null, "Check to make sure null values are copied");
|
1005
|
+
|
1006
|
+
nullUndef = jQuery.extend({}, options, { "xnumber2": undefined });
|
1007
|
+
ok( nullUndef["xnumber2"] === options["xnumber2"], "Check to make sure undefined values are not copied");
|
1008
|
+
|
1009
|
+
nullUndef = jQuery.extend({}, options, { "xnumber0": null });
|
1010
|
+
ok( nullUndef["xnumber0"] === null, "Check to make sure null values are inserted");
|
1011
|
+
|
1012
|
+
target = {};
|
1013
|
+
recursive = { foo:target, bar:5 };
|
1014
|
+
jQuery.extend(true, target, recursive);
|
1015
|
+
deepEqual( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
|
1016
|
+
|
1017
|
+
ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
|
1018
|
+
equal( ret.foo.length, 1, "Check to make sure a value with coercion 'false' copies over when necessary to fix #1907" );
|
1019
|
+
|
1020
|
+
ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
|
1021
|
+
ok( typeof ret.foo !== "string", "Check to make sure values equal with coercion (but not actually equal) overwrite correctly" );
|
1022
|
+
|
1023
|
+
ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
|
1024
|
+
ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" );
|
1025
|
+
|
1026
|
+
obj = { foo:null };
|
1027
|
+
jQuery.extend(true, obj, { foo:"notnull" } );
|
1028
|
+
equal( obj.foo, "notnull", "Make sure a null value can be overwritten" );
|
1029
|
+
|
1030
|
+
function func() {}
|
1031
|
+
jQuery.extend(func, { key: "value" } );
|
1032
|
+
equal( func.key, "value", "Verify a function can be extended" );
|
1033
|
+
|
1034
|
+
defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
|
1035
|
+
defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
|
1036
|
+
options1 = { xnumber2: 1, xstring2: "x" };
|
1037
|
+
options1Copy = { xnumber2: 1, xstring2: "x" };
|
1038
|
+
options2 = { xstring2: "xx", xxx: "newstringx" };
|
1039
|
+
options2Copy = { xstring2: "xx", xxx: "newstringx" };
|
1040
|
+
merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
|
1041
|
+
|
1042
|
+
settings = jQuery.extend({}, defaults, options1, options2);
|
1043
|
+
deepEqual( settings, merged2, "Check if extended: settings must be extended" );
|
1044
|
+
deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
|
1045
|
+
deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" );
|
1046
|
+
deepEqual( options2, options2Copy, "Check if not modified: options2 must not be modified" );
|
1047
|
+
});
|
1048
|
+
|
1049
|
+
test("jQuery.each(Object,Function)", function() {
|
1050
|
+
expect( 23 );
|
1051
|
+
|
1052
|
+
var i, label, seen, callback;
|
1053
|
+
|
1054
|
+
seen = {};
|
1055
|
+
jQuery.each( [ 3, 4, 5 ], function( k, v ) {
|
1056
|
+
seen[ k ] = v;
|
1057
|
+
});
|
1058
|
+
deepEqual( seen, { "0": 3, "1": 4, "2": 5 }, "Array iteration" );
|
1059
|
+
|
1060
|
+
seen = {};
|
1061
|
+
jQuery.each( { name: "name", lang: "lang" }, function( k, v ) {
|
1062
|
+
seen[ k ] = v;
|
1063
|
+
});
|
1064
|
+
deepEqual( seen, { name: "name", lang: "lang" }, "Object iteration" );
|
1065
|
+
|
1066
|
+
seen = [];
|
1067
|
+
jQuery.each( [ 1, 2, 3 ], function( k, v ) {
|
1068
|
+
seen.push( v );
|
1069
|
+
if ( k === 1 ) {
|
1070
|
+
return false;
|
1071
|
+
}
|
1072
|
+
});
|
1073
|
+
deepEqual( seen, [ 1, 2 ] , "Broken array iteration" );
|
1074
|
+
|
1075
|
+
seen = [];
|
1076
|
+
jQuery.each( {"a": 1, "b": 2,"c": 3 }, function( k, v ) {
|
1077
|
+
seen.push( v );
|
1078
|
+
return false;
|
1079
|
+
});
|
1080
|
+
deepEqual( seen, [ 1 ], "Broken object iteration" );
|
1081
|
+
|
1082
|
+
seen = {
|
1083
|
+
Zero: function() {},
|
1084
|
+
One: function( a ) { a = a; },
|
1085
|
+
Two: function( a, b ) { a = a; b = b; }
|
1086
|
+
};
|
1087
|
+
callback = function( k ) {
|
1088
|
+
equal( k, "foo", label + "-argument function treated like object" );
|
1089
|
+
};
|
1090
|
+
for ( i in seen ) {
|
1091
|
+
label = i;
|
1092
|
+
seen[ i ].foo = "bar";
|
1093
|
+
jQuery.each( seen[ i ], callback );
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
seen = {
|
1097
|
+
"undefined": undefined,
|
1098
|
+
"null": null,
|
1099
|
+
"false": false,
|
1100
|
+
"true": true,
|
1101
|
+
"empty string": "",
|
1102
|
+
"nonempty string": "string",
|
1103
|
+
"string \"0\"": "0",
|
1104
|
+
"negative": -1,
|
1105
|
+
"excess": 1
|
1106
|
+
};
|
1107
|
+
callback = function( k ) {
|
1108
|
+
equal( k, "length", "Object with " + label + " length treated like object" );
|
1109
|
+
};
|
1110
|
+
for ( i in seen ) {
|
1111
|
+
label = i;
|
1112
|
+
jQuery.each( { length: seen[ i ] }, callback );
|
1113
|
+
}
|
1114
|
+
|
1115
|
+
seen = {
|
1116
|
+
"sparse Array": Array( 4 ),
|
1117
|
+
"length: 1 plain object": { length: 1, "0": true },
|
1118
|
+
"length: 2 plain object": { length: 2, "0": true, "1": true },
|
1119
|
+
NodeList: document.getElementsByTagName("html")
|
1120
|
+
};
|
1121
|
+
callback = function( k ) {
|
1122
|
+
if ( seen[ label ] ) {
|
1123
|
+
delete seen[ label ];
|
1124
|
+
equal( k, "0", label + " treated like array" );
|
1125
|
+
return false;
|
1126
|
+
}
|
1127
|
+
};
|
1128
|
+
for ( i in seen ) {
|
1129
|
+
label = i;
|
1130
|
+
jQuery.each( seen[ i ], callback );
|
1131
|
+
}
|
1132
|
+
|
1133
|
+
seen = false;
|
1134
|
+
jQuery.each( { length: 0 }, function() {
|
1135
|
+
seen = true;
|
1136
|
+
});
|
1137
|
+
ok( !seen, "length: 0 plain object treated like array" );
|
1138
|
+
|
1139
|
+
seen = false;
|
1140
|
+
jQuery.each( document.getElementsByTagName("asdf"), function() {
|
1141
|
+
seen = true;
|
1142
|
+
});
|
1143
|
+
ok( !seen, "empty NodeList treated like array" );
|
1144
|
+
|
1145
|
+
i = 0;
|
1146
|
+
jQuery.each( document.styleSheets, function() {
|
1147
|
+
i++;
|
1148
|
+
});
|
1149
|
+
equal( i, 2, "Iteration over document.styleSheets" );
|
1150
|
+
});
|
1151
|
+
|
1152
|
+
test("jQuery.makeArray", function(){
|
1153
|
+
expect(15);
|
1154
|
+
|
1155
|
+
equal( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
|
1156
|
+
|
1157
|
+
equal( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
|
1158
|
+
|
1159
|
+
equal( (function() { return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
|
1160
|
+
|
1161
|
+
equal( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
|
1162
|
+
|
1163
|
+
equal( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
|
1164
|
+
|
1165
|
+
equal( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
|
1166
|
+
|
1167
|
+
equal( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
|
1168
|
+
|
1169
|
+
equal( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
|
1170
|
+
|
1171
|
+
equal( jQuery.makeArray( document.createElement("div") )[0].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" );
|
1172
|
+
|
1173
|
+
equal( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
|
1174
|
+
|
1175
|
+
ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" );
|
1176
|
+
|
1177
|
+
// function, is tricky as it has length
|
1178
|
+
equal( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
|
1179
|
+
|
1180
|
+
//window, also has length
|
1181
|
+
equal( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );
|
1182
|
+
|
1183
|
+
equal( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
|
1184
|
+
|
1185
|
+
// Some nodes inherit traits of nodelists
|
1186
|
+
ok( jQuery.makeArray(document.getElementById("form")).length >= 13,
|
1187
|
+
"Pass makeArray a form (treat as elements)" );
|
1188
|
+
});
|
1189
|
+
|
1190
|
+
test("jQuery.inArray", function(){
|
1191
|
+
expect(3);
|
1192
|
+
|
1193
|
+
equal( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" );
|
1194
|
+
|
1195
|
+
equal( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" );
|
1196
|
+
|
1197
|
+
equal( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" );
|
1198
|
+
});
|
1199
|
+
|
1200
|
+
test("jQuery.isEmptyObject", function(){
|
1201
|
+
expect(2);
|
1202
|
+
|
1203
|
+
equal(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" );
|
1204
|
+
equal(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" );
|
1205
|
+
|
1206
|
+
// What about this ?
|
1207
|
+
// equal(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
|
1208
|
+
});
|
1209
|
+
|
1210
|
+
test("jQuery.proxy", function(){
|
1211
|
+
expect( 9 );
|
1212
|
+
|
1213
|
+
var test2, test3, test4, fn, cb,
|
1214
|
+
test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); },
|
1215
|
+
thisObject = { foo: "bar", method: test };
|
1216
|
+
|
1217
|
+
// Make sure normal works
|
1218
|
+
test.call( thisObject );
|
1219
|
+
|
1220
|
+
// Basic scoping
|
1221
|
+
jQuery.proxy( test, thisObject )();
|
1222
|
+
|
1223
|
+
// Another take on it
|
1224
|
+
jQuery.proxy( thisObject, "method" )();
|
1225
|
+
|
1226
|
+
// Make sure it doesn't freak out
|
1227
|
+
equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." );
|
1228
|
+
|
1229
|
+
// Partial application
|
1230
|
+
test2 = function( a ){ equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); };
|
1231
|
+
jQuery.proxy( test2, null, "pre-applied" )();
|
1232
|
+
|
1233
|
+
// Partial application w/ normal arguments
|
1234
|
+
test3 = function( a, b ){ equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); };
|
1235
|
+
jQuery.proxy( test3, null, "pre-applied" )( "normal" );
|
1236
|
+
|
1237
|
+
// Test old syntax
|
1238
|
+
test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } };
|
1239
|
+
jQuery.proxy( test4, "meth" )( "boom" );
|
1240
|
+
|
1241
|
+
// jQuery 1.9 improved currying with `this` object
|
1242
|
+
fn = function() {
|
1243
|
+
equal( Array.prototype.join.call( arguments, "," ), "arg1,arg2,arg3", "args passed" );
|
1244
|
+
equal( this.foo, "bar", "this-object passed" );
|
1245
|
+
};
|
1246
|
+
cb = jQuery.proxy( fn, null, "arg1", "arg2" );
|
1247
|
+
cb.call( thisObject, "arg3" );
|
1248
|
+
});
|
1249
|
+
|
1250
|
+
test("jQuery.parseHTML", function() {
|
1251
|
+
expect( 17 );
|
1252
|
+
|
1253
|
+
var html, nodes;
|
1254
|
+
|
1255
|
+
equal( jQuery.parseHTML(), null, "Nothing in, null out." );
|
1256
|
+
equal( jQuery.parseHTML( null ), null, "Null in, null out." );
|
1257
|
+
equal( jQuery.parseHTML( "" ), null, "Empty string in, null out." );
|
1258
|
+
raises(function() {
|
1259
|
+
jQuery.parseHTML( "<div></div>", document.getElementById("form") );
|
1260
|
+
}, "Passing an element as the context raises an exception (context should be a document)");
|
1261
|
+
|
1262
|
+
nodes = jQuery.parseHTML( jQuery("body")[0].innerHTML );
|
1263
|
+
ok( nodes.length > 4, "Parse a large html string" );
|
1264
|
+
equal( jQuery.type( nodes ), "array", "parseHTML returns an array rather than a nodelist" );
|
1265
|
+
|
1266
|
+
html = "<script>undefined()</script>";
|
1267
|
+
equal( jQuery.parseHTML( html ).length, 0, "Ignore scripts by default" );
|
1268
|
+
equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve scripts when requested" );
|
1269
|
+
|
1270
|
+
html += "<div></div>";
|
1271
|
+
equal( jQuery.parseHTML( html )[0].nodeName.toLowerCase(), "div", "Preserve non-script nodes" );
|
1272
|
+
equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve script position");
|
1273
|
+
|
1274
|
+
equal( jQuery.parseHTML("text")[0].nodeType, 3, "Parsing text returns a text node" );
|
1275
|
+
equal( jQuery.parseHTML( "\t<div></div>" )[0].nodeValue, "\t", "Preserve leading whitespace" );
|
1276
|
+
|
1277
|
+
equal( jQuery.parseHTML(" <div/> ")[0].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" );
|
1278
|
+
|
1279
|
+
html = jQuery.parseHTML( "<div>test div</div>" );
|
1280
|
+
equal( html[ 0 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
|
1281
|
+
equal( html[ 0 ].innerHTML, "test div", "Content should be preserved" );
|
1282
|
+
|
1283
|
+
equal( jQuery.parseHTML("<span><span>").length, 1, "Incorrect html-strings should not break anything" );
|
1284
|
+
equal( jQuery.parseHTML("<td><td>")[ 1 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
|
1285
|
+
});
|
1286
|
+
|
1287
|
+
test("jQuery.parseJSON", function(){
|
1288
|
+
expect( 9 );
|
1289
|
+
|
1290
|
+
equal( jQuery.parseJSON( null ), null, "Actual null returns null" );
|
1291
|
+
equal( jQuery.isEmptyObject( jQuery.parseJSON("{}") ), true, "Empty object returns empty object" );
|
1292
|
+
deepEqual( jQuery.parseJSON("{\"test\":1}"), { "test": 1 }, "Plain object parses" );
|
1293
|
+
deepEqual( jQuery.parseJSON("\n{\"test\":1}"), { "test": 1 }, "Leading whitespaces are ignored." );
|
1294
|
+
raises(function() {
|
1295
|
+
jQuery.parseJSON();
|
1296
|
+
}, null, "Undefined raises an error" );
|
1297
|
+
raises( function() {
|
1298
|
+
jQuery.parseJSON( "" );
|
1299
|
+
}, null, "Empty string raises an error" );
|
1300
|
+
raises(function() {
|
1301
|
+
jQuery.parseJSON("''");
|
1302
|
+
}, null, "Single-quoted string raises an error" );
|
1303
|
+
raises(function() {
|
1304
|
+
jQuery.parseJSON("{a:1}");
|
1305
|
+
}, null, "Unquoted property raises an error" );
|
1306
|
+
raises(function() {
|
1307
|
+
jQuery.parseJSON("{'a':1}");
|
1308
|
+
}, null, "Single-quoted property raises an error" );
|
1309
|
+
});
|
1310
|
+
|
1311
|
+
test("jQuery.parseXML", 8, function(){
|
1312
|
+
var xml, tmp;
|
1313
|
+
try {
|
1314
|
+
xml = jQuery.parseXML( "<p>A <b>well-formed</b> xml string</p>" );
|
1315
|
+
tmp = xml.getElementsByTagName( "p" )[ 0 ];
|
1316
|
+
ok( !!tmp, "<p> present in document" );
|
1317
|
+
tmp = tmp.getElementsByTagName( "b" )[ 0 ];
|
1318
|
+
ok( !!tmp, "<b> present in document" );
|
1319
|
+
strictEqual( tmp.childNodes[ 0 ].nodeValue, "well-formed", "<b> text is as expected" );
|
1320
|
+
} catch (e) {
|
1321
|
+
strictEqual( e, undefined, "unexpected error" );
|
1322
|
+
}
|
1323
|
+
try {
|
1324
|
+
xml = jQuery.parseXML( "<p>Not a <<b>well-formed</b> xml string</p>" );
|
1325
|
+
ok( false, "invalid xml not detected" );
|
1326
|
+
} catch( e ) {
|
1327
|
+
strictEqual( e.message, "Invalid XML: <p>Not a <<b>well-formed</b> xml string</p>", "invalid xml detected" );
|
1328
|
+
}
|
1329
|
+
try {
|
1330
|
+
xml = jQuery.parseXML( "" );
|
1331
|
+
strictEqual( xml, null, "empty string => null document" );
|
1332
|
+
xml = jQuery.parseXML();
|
1333
|
+
strictEqual( xml, null, "undefined string => null document" );
|
1334
|
+
xml = jQuery.parseXML( null );
|
1335
|
+
strictEqual( xml, null, "null string => null document" );
|
1336
|
+
xml = jQuery.parseXML( true );
|
1337
|
+
strictEqual( xml, null, "non-string => null document" );
|
1338
|
+
} catch( e ) {
|
1339
|
+
ok( false, "empty input throws exception" );
|
1340
|
+
}
|
1341
|
+
});
|
1342
|
+
|
1343
|
+
test("jQuery.camelCase()", function() {
|
1344
|
+
|
1345
|
+
var tests = {
|
1346
|
+
"foo-bar": "fooBar",
|
1347
|
+
"foo-bar-baz": "fooBarBaz",
|
1348
|
+
"girl-u-want": "girlUWant",
|
1349
|
+
"the-4th-dimension": "the4thDimension",
|
1350
|
+
"-o-tannenbaum": "OTannenbaum",
|
1351
|
+
"-moz-illa": "MozIlla",
|
1352
|
+
"-ms-take": "msTake"
|
1353
|
+
};
|
1354
|
+
|
1355
|
+
expect(7);
|
1356
|
+
|
1357
|
+
jQuery.each( tests, function( key, val ) {
|
1358
|
+
equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
|
1359
|
+
});
|
1360
|
+
});
|