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,2120 @@
|
|
1
|
+
module( "manipulation", {
|
2
|
+
teardown: moduleTeardown
|
3
|
+
});
|
4
|
+
|
5
|
+
// Ensure that an extended Array prototype doesn't break jQuery
|
6
|
+
Array.prototype.arrayProtoFn = function() {
|
7
|
+
throw("arrayProtoFn should not be called");
|
8
|
+
};
|
9
|
+
|
10
|
+
function manipulationBareObj( value ) {
|
11
|
+
return value;
|
12
|
+
}
|
13
|
+
|
14
|
+
function manipulationFunctionReturningObj( value ) {
|
15
|
+
return function() {
|
16
|
+
return value;
|
17
|
+
};
|
18
|
+
}
|
19
|
+
|
20
|
+
/*
|
21
|
+
======== local reference =======
|
22
|
+
manipulationBareObj and manipulationFunctionReturningObj can be used to test passing functions to setters
|
23
|
+
See testVal below for an example
|
24
|
+
|
25
|
+
bareObj( value );
|
26
|
+
This function returns whatever value is passed in
|
27
|
+
|
28
|
+
functionReturningObj( value );
|
29
|
+
Returns a function that returns the value
|
30
|
+
*/
|
31
|
+
|
32
|
+
test( "text()", function() {
|
33
|
+
|
34
|
+
expect( 5 );
|
35
|
+
|
36
|
+
var expected, frag, $newLineTest;
|
37
|
+
|
38
|
+
expected = "This link has class=\"blog\": Simon Willison's Weblog";
|
39
|
+
equal( jQuery("#sap").text(), expected, "Check for merged text of more then one element." );
|
40
|
+
|
41
|
+
// Check serialization of text values
|
42
|
+
equal( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retrieved from .text()." );
|
43
|
+
notEqual( jQuery(document).text(), "", "Retrieving text for the document retrieves all text (#10724)." );
|
44
|
+
|
45
|
+
// Retrieve from document fragments #10864
|
46
|
+
frag = document.createDocumentFragment();
|
47
|
+
frag.appendChild( document.createTextNode("foo") );
|
48
|
+
|
49
|
+
equal( jQuery(frag).text(), "foo", "Document Fragment Text node was retrieved from .text()." );
|
50
|
+
|
51
|
+
$newLineTest = jQuery("<div>test<br/>testy</div>").appendTo("#moretests");
|
52
|
+
$newLineTest.find("br").replaceWith("\n");
|
53
|
+
equal( $newLineTest.text(), "test\ntesty", "text() does not remove new lines (#11153)" );
|
54
|
+
|
55
|
+
$newLineTest.remove();
|
56
|
+
});
|
57
|
+
|
58
|
+
test( "text(undefined)", function() {
|
59
|
+
|
60
|
+
expect( 1 );
|
61
|
+
|
62
|
+
equal( jQuery("#foo").text("<div").text(undefined)[ 0 ].innerHTML, "<div", ".text(undefined) is chainable (#5571)" );
|
63
|
+
});
|
64
|
+
|
65
|
+
function testText( valueObj ) {
|
66
|
+
|
67
|
+
expect( 4 );
|
68
|
+
|
69
|
+
var val, j;
|
70
|
+
|
71
|
+
val = valueObj("<div><b>Hello</b> cruel world!</div>");
|
72
|
+
equal( jQuery("#foo").text(val)[ 0 ].innerHTML.replace(/>/g, ">"), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
|
73
|
+
|
74
|
+
// using contents will get comments regular, text, and comment nodes
|
75
|
+
j = jQuery("#nonnodes").contents();
|
76
|
+
j.text( valueObj("hi!") );
|
77
|
+
equal( jQuery( j[ 0 ] ).text(), "hi!", "Check node,textnode,comment with text()" );
|
78
|
+
equal( j[ 1 ].nodeValue, " there ", "Check node,textnode,comment with text()" );
|
79
|
+
|
80
|
+
// Blackberry 4.6 doesn't maintain comments in the DOM
|
81
|
+
equal( jQuery("#nonnodes")[ 0 ].childNodes.length < 3 ? 8 : j[ 2 ].nodeType, 8, "Check node,textnode,comment with text()" );
|
82
|
+
}
|
83
|
+
|
84
|
+
test( "text(String)", function() {
|
85
|
+
testText( manipulationBareObj );
|
86
|
+
});
|
87
|
+
|
88
|
+
test( "text(Function)", function() {
|
89
|
+
testText( manipulationFunctionReturningObj );
|
90
|
+
});
|
91
|
+
|
92
|
+
test( "text(Function) with incoming value", function() {
|
93
|
+
|
94
|
+
expect( 2 );
|
95
|
+
|
96
|
+
var old = "This link has class=\"blog\": Simon Willison's Weblog";
|
97
|
+
|
98
|
+
jQuery("#sap").text(function( i, val ) {
|
99
|
+
equal( val, old, "Make sure the incoming value is correct." );
|
100
|
+
return "foobar";
|
101
|
+
});
|
102
|
+
|
103
|
+
equal( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." );
|
104
|
+
});
|
105
|
+
|
106
|
+
function testAppendForObject( valueObj, isFragment ) {
|
107
|
+
var $base,
|
108
|
+
type = isFragment ? " (DocumentFragment)" : " (Element)",
|
109
|
+
text = "This link has class=\"blog\": Simon Willison's Weblog",
|
110
|
+
el = document.getElementById("sap").cloneNode( true ),
|
111
|
+
first = document.getElementById("first"),
|
112
|
+
yahoo = document.getElementById("yahoo");
|
113
|
+
|
114
|
+
if ( isFragment ) {
|
115
|
+
$base = document.createDocumentFragment();
|
116
|
+
jQuery( el ).contents().each(function() {
|
117
|
+
$base.appendChild( this );
|
118
|
+
});
|
119
|
+
$base = jQuery( $base );
|
120
|
+
} else {
|
121
|
+
$base = jQuery( el );
|
122
|
+
}
|
123
|
+
|
124
|
+
equal( $base.clone().append( valueObj(first.cloneNode(true)) ).text(),
|
125
|
+
text + "Try them out:",
|
126
|
+
"Check for appending of element" + type
|
127
|
+
);
|
128
|
+
|
129
|
+
equal( $base.clone().append( valueObj([ first.cloneNode(true), yahoo.cloneNode(true) ]) ).text(),
|
130
|
+
text + "Try them out:Yahoo",
|
131
|
+
"Check for appending of array of elements" + type
|
132
|
+
);
|
133
|
+
|
134
|
+
equal( $base.clone().append( valueObj(jQuery("#yahoo, #first").clone()) ).text(),
|
135
|
+
text + "YahooTry them out:",
|
136
|
+
"Check for appending of jQuery object" + type
|
137
|
+
);
|
138
|
+
|
139
|
+
equal( $base.clone().append( valueObj( 5 ) ).text(),
|
140
|
+
text + "5",
|
141
|
+
"Check for appending a number" + type
|
142
|
+
);
|
143
|
+
|
144
|
+
equal( $base.clone().append( valueObj([ jQuery("#first").clone(), jQuery("#yahoo, #google").clone() ]) ).text(),
|
145
|
+
text + "Try them out:GoogleYahoo",
|
146
|
+
"Check for appending of array of jQuery objects"
|
147
|
+
);
|
148
|
+
|
149
|
+
equal( $base.clone().append( valueObj(" text with spaces ") ).text(),
|
150
|
+
text + " text with spaces ",
|
151
|
+
"Check for appending text with spaces" + type
|
152
|
+
);
|
153
|
+
|
154
|
+
equal( $base.clone().append( valueObj([]) ).text(),
|
155
|
+
text,
|
156
|
+
"Check for appending an empty array" + type
|
157
|
+
);
|
158
|
+
|
159
|
+
equal( $base.clone().append( valueObj("") ).text(),
|
160
|
+
text,
|
161
|
+
"Check for appending an empty string" + type
|
162
|
+
);
|
163
|
+
|
164
|
+
equal( $base.clone().append( valueObj(document.getElementsByTagName("foo")) ).text(),
|
165
|
+
text,
|
166
|
+
"Check for appending an empty nodelist" + type
|
167
|
+
);
|
168
|
+
|
169
|
+
equal( $base.clone().append( "<span></span>", "<span></span>", "<span></span>" ).children().length,
|
170
|
+
$base.children().length + 3,
|
171
|
+
"Make sure that multiple arguments works." + type
|
172
|
+
);
|
173
|
+
|
174
|
+
equal( $base.clone().append( valueObj(document.getElementById("form").cloneNode(true)) ).children("form").length,
|
175
|
+
1,
|
176
|
+
"Check for appending a form (#910)" + type
|
177
|
+
);
|
178
|
+
}
|
179
|
+
|
180
|
+
function testAppend( valueObj ) {
|
181
|
+
|
182
|
+
expect( 78 );
|
183
|
+
|
184
|
+
testAppendForObject( valueObj, false );
|
185
|
+
testAppendForObject( valueObj, true );
|
186
|
+
|
187
|
+
var defaultText, result, message, iframe, iframeDoc, j, d,
|
188
|
+
$input, $radioChecked, $radioUnchecked, $radioParent, $map, $table;
|
189
|
+
|
190
|
+
defaultText = "Try them out:";
|
191
|
+
result = jQuery("#first").append( valueObj("<b>buga</b>") );
|
192
|
+
|
193
|
+
equal( result.text(), defaultText + "buga", "Check if text appending works" );
|
194
|
+
equal( jQuery("#select3").append( valueObj("<option value='appendTest'>Append Test</option>") ).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element" );
|
195
|
+
|
196
|
+
jQuery("form").append( valueObj("<input name='radiotest' type='radio' checked='checked' />") );
|
197
|
+
jQuery("form input[name=radiotest]").each(function() {
|
198
|
+
ok( jQuery(this).is(":checked"), "Append checked radio" );
|
199
|
+
}).remove();
|
200
|
+
|
201
|
+
jQuery("form").append( valueObj("<input name='radiotest2' type='radio' checked = 'checked' />") );
|
202
|
+
jQuery("form input[name=radiotest2]").each(function() {
|
203
|
+
ok( jQuery(this).is(":checked"), "Append alternately formated checked radio" );
|
204
|
+
}).remove();
|
205
|
+
|
206
|
+
jQuery("form").append( valueObj("<input name='radiotest3' type='radio' checked />") );
|
207
|
+
jQuery("form input[name=radiotest3]").each(function() {
|
208
|
+
ok( jQuery(this).is(":checked"), "Append HTML5-formated checked radio" );
|
209
|
+
}).remove();
|
210
|
+
|
211
|
+
jQuery("form").append( valueObj("<input type='radio' checked='checked' name='radiotest4' />") );
|
212
|
+
jQuery("form input[name=radiotest4]").each(function() {
|
213
|
+
ok( jQuery(this).is(":checked"), "Append with name attribute after checked attribute" );
|
214
|
+
}).remove();
|
215
|
+
|
216
|
+
message = "Test for appending a DOM node to the contents of an iframe";
|
217
|
+
iframe = jQuery("#iframe")[ 0 ];
|
218
|
+
iframeDoc = iframe.contentDocument || iframe.contentWindow && iframe.contentWindow.document;
|
219
|
+
|
220
|
+
try {
|
221
|
+
if ( iframeDoc && iframeDoc.body ) {
|
222
|
+
equal( jQuery(iframeDoc.body).append( valueObj("<div id='success'>test</div>") )[ 0 ].lastChild.id, "success", message );
|
223
|
+
} else {
|
224
|
+
ok( true, message + " - can't test" );
|
225
|
+
}
|
226
|
+
} catch( e ) {
|
227
|
+
strictEqual( e.message || e, undefined, message );
|
228
|
+
}
|
229
|
+
|
230
|
+
jQuery("<fieldset/>").appendTo("#form").append( valueObj("<legend id='legend'>test</legend>") );
|
231
|
+
t( "Append legend", "#legend", [ "legend" ] );
|
232
|
+
|
233
|
+
$map = jQuery("<map/>").append( valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>") );
|
234
|
+
|
235
|
+
equal( $map[ 0 ].childNodes.length, 1, "The area was inserted." );
|
236
|
+
equal( $map[ 0 ].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
|
237
|
+
|
238
|
+
jQuery("#select1").append( valueObj("<OPTION>Test</OPTION>") );
|
239
|
+
equal( jQuery("#select1 option:last-child").text(), "Test", "Appending OPTION (all caps)" );
|
240
|
+
|
241
|
+
jQuery("#select1").append( valueObj("<optgroup label='optgroup'><option>optgroup</option></optgroup>") );
|
242
|
+
equal( jQuery("#select1 optgroup").attr("label"), "optgroup", "Label attribute in newly inserted optgroup is correct" );
|
243
|
+
equal( jQuery("#select1 option").last().text(), "optgroup", "Appending optgroup" );
|
244
|
+
|
245
|
+
$table = jQuery("#table").empty();
|
246
|
+
|
247
|
+
jQuery.each( "thead tbody tfoot colgroup caption tr th td".split(" "), function( i, name ) {
|
248
|
+
$table.append( valueObj( "<" + name + "/>" ) );
|
249
|
+
ok( $table.find( name ).length >= 1, "Append " + name );
|
250
|
+
ok( jQuery.parseHTML( "<" + name + "/>" ).length, name + " wrapped correctly" );
|
251
|
+
});
|
252
|
+
|
253
|
+
jQuery("#table colgroup").append( valueObj("<col/>") );
|
254
|
+
equal( jQuery("#table colgroup col").length, 1, "Append col" );
|
255
|
+
|
256
|
+
jQuery("#form")
|
257
|
+
.append( valueObj("<select id='appendSelect1'></select>") )
|
258
|
+
.append( valueObj("<select id='appendSelect2'><option>Test</option></select>") );
|
259
|
+
t( "Append Select", "#appendSelect1, #appendSelect2", [ "appendSelect1", "appendSelect2" ] );
|
260
|
+
|
261
|
+
equal( "Two nodes", jQuery("<div />").append( "Two", " nodes" ).text(), "Appending two text nodes (#4011)" );
|
262
|
+
equal( jQuery("<div />").append( "1", "", 3 ).text(), "13", "If median is false-like value, subsequent arguments should not be ignored" );
|
263
|
+
|
264
|
+
// using contents will get comments regular, text, and comment nodes
|
265
|
+
j = jQuery("#nonnodes").contents();
|
266
|
+
d = jQuery("<div/>").appendTo("#nonnodes").append( j );
|
267
|
+
|
268
|
+
equal( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
|
269
|
+
equal( d.contents().length, 3, "Check node,textnode,comment append works" );
|
270
|
+
d.contents().appendTo("#nonnodes");
|
271
|
+
d.remove();
|
272
|
+
equal( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment append cleanup worked" );
|
273
|
+
|
274
|
+
$input = jQuery("<input type='checkbox'/>").prop( "checked", true ).appendTo("#testForm");
|
275
|
+
equal( $input[ 0 ].checked, true, "A checked checkbox that is appended stays checked" );
|
276
|
+
|
277
|
+
$radioChecked = jQuery("input[type='radio'][name='R1']").eq( 1 );
|
278
|
+
$radioParent = $radioChecked.parent();
|
279
|
+
$radioUnchecked = jQuery("<input type='radio' name='R1' checked='checked'/>").appendTo( $radioParent );
|
280
|
+
$radioChecked.trigger("click");
|
281
|
+
$radioUnchecked[ 0 ].checked = false;
|
282
|
+
|
283
|
+
jQuery("<div/>").insertBefore($radioParent).append($radioParent);
|
284
|
+
|
285
|
+
equal( $radioChecked[ 0 ].checked, true, "Reappending radios uphold which radio is checked" );
|
286
|
+
equal( $radioUnchecked[ 0 ].checked, false, "Reappending radios uphold not being checked" );
|
287
|
+
|
288
|
+
equal( jQuery("<div/>").append( valueObj("option<area/>") )[ 0 ].childNodes.length, 2, "HTML-string with leading text should be processed correctly" );
|
289
|
+
}
|
290
|
+
|
291
|
+
test( "append(String|Element|Array<Element>|jQuery)", function() {
|
292
|
+
testAppend( manipulationBareObj );
|
293
|
+
});
|
294
|
+
|
295
|
+
test( "append(Function)", function() {
|
296
|
+
testAppend( manipulationFunctionReturningObj );
|
297
|
+
});
|
298
|
+
|
299
|
+
test( "append(param) to object, see #11280", function() {
|
300
|
+
|
301
|
+
expect( 5 );
|
302
|
+
|
303
|
+
var object = jQuery( document.createElement("object") ).appendTo( document.body );
|
304
|
+
|
305
|
+
equal( object.children().length, 0, "object does not start with children" );
|
306
|
+
|
307
|
+
object.append( jQuery("<param type='wmode' name='foo'>") );
|
308
|
+
equal( object.children().length, 1, "appended param" );
|
309
|
+
equal( object.children().eq(0).attr("name"), "foo", "param has name=foo" );
|
310
|
+
|
311
|
+
object = jQuery("<object><param type='baz' name='bar'></object>");
|
312
|
+
equal( object.children().length, 1, "object created with child param" );
|
313
|
+
equal( object.children().eq(0).attr("name"), "bar", "param has name=bar" );
|
314
|
+
});
|
315
|
+
|
316
|
+
test( "append(Function) with incoming value", function() {
|
317
|
+
|
318
|
+
expect( 12 );
|
319
|
+
|
320
|
+
var defaultText, result, select, old, expected;
|
321
|
+
|
322
|
+
defaultText = "Try them out:";
|
323
|
+
old = jQuery("#first").html();
|
324
|
+
|
325
|
+
result = jQuery("#first").append(function( i, val ) {
|
326
|
+
equal( val, old, "Make sure the incoming value is correct." );
|
327
|
+
return "<b>buga</b>";
|
328
|
+
});
|
329
|
+
equal( result.text(), defaultText + "buga", "Check if text appending works" );
|
330
|
+
|
331
|
+
select = jQuery("#select3");
|
332
|
+
old = select.html();
|
333
|
+
|
334
|
+
equal( select.append(function( i, val ) {
|
335
|
+
equal( val, old, "Make sure the incoming value is correct." );
|
336
|
+
return "<option value='appendTest'>Append Test</option>";
|
337
|
+
}).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element" );
|
338
|
+
|
339
|
+
QUnit.reset();
|
340
|
+
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
|
341
|
+
old = jQuery("#sap").html();
|
342
|
+
|
343
|
+
jQuery("#sap").append(function( i, val ) {
|
344
|
+
equal( val, old, "Make sure the incoming value is correct." );
|
345
|
+
return document.getElementById("first");
|
346
|
+
});
|
347
|
+
equal( jQuery("#sap").text(), expected, "Check for appending of element" );
|
348
|
+
|
349
|
+
QUnit.reset();
|
350
|
+
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
|
351
|
+
old = jQuery("#sap").html();
|
352
|
+
|
353
|
+
jQuery("#sap").append(function( i, val ) {
|
354
|
+
equal( val, old, "Make sure the incoming value is correct." );
|
355
|
+
return [ document.getElementById("first"), document.getElementById("yahoo") ];
|
356
|
+
});
|
357
|
+
equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" );
|
358
|
+
|
359
|
+
QUnit.reset();
|
360
|
+
expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
|
361
|
+
old = jQuery("#sap").html();
|
362
|
+
|
363
|
+
jQuery("#sap").append(function( i, val ) {
|
364
|
+
equal( val, old, "Make sure the incoming value is correct." );
|
365
|
+
return jQuery("#yahoo, #first");
|
366
|
+
});
|
367
|
+
equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" );
|
368
|
+
|
369
|
+
QUnit.reset();
|
370
|
+
old = jQuery("#sap").html();
|
371
|
+
|
372
|
+
jQuery("#sap").append(function( i, val ) {
|
373
|
+
equal( val, old, "Make sure the incoming value is correct." );
|
374
|
+
return 5;
|
375
|
+
});
|
376
|
+
ok( jQuery("#sap")[ 0 ].innerHTML.match( /5$/ ), "Check for appending a number" );
|
377
|
+
|
378
|
+
QUnit.reset();
|
379
|
+
});
|
380
|
+
|
381
|
+
test( "XML DOM manipulation (#9960)", function() {
|
382
|
+
|
383
|
+
expect( 5 );
|
384
|
+
|
385
|
+
var
|
386
|
+
xmlDoc1 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state x='100' y='100' initial='actions' id='provisioning'></state><state x='100' y='100' id='error'></state><state x='100' y='100' id='finished' final='true'></state></scxml>"),
|
387
|
+
xmlDoc2 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning3'></state></scxml>"),
|
388
|
+
xml1 = jQuery( xmlDoc1 ),
|
389
|
+
xml2 = jQuery( xmlDoc2 ),
|
390
|
+
scxml1 = jQuery( "scxml", xml1 ),
|
391
|
+
scxml2 = jQuery( "scxml", xml2 ),
|
392
|
+
state = scxml2.find("state");
|
393
|
+
|
394
|
+
scxml1.append( state );
|
395
|
+
strictEqual( scxml1[0].lastChild, state[0], "append" );
|
396
|
+
|
397
|
+
scxml1.prepend( state );
|
398
|
+
strictEqual( scxml1[0].firstChild, state[0], "prepend" );
|
399
|
+
|
400
|
+
scxml1.find("#finished").after( state );
|
401
|
+
strictEqual( scxml1[0].lastChild, state[0], "after" );
|
402
|
+
|
403
|
+
scxml1.find("#provisioning").before( state );
|
404
|
+
strictEqual( scxml1[0].firstChild, state[0], "before" );
|
405
|
+
|
406
|
+
scxml2.replaceWith( scxml1 );
|
407
|
+
deepEqual( jQuery( "state", xml2 ).get(), scxml1.find("state").get(), "replaceWith" );
|
408
|
+
});
|
409
|
+
|
410
|
+
test( "append the same fragment with events (Bug #6997, 5566)", function() {
|
411
|
+
|
412
|
+
var element, clone,
|
413
|
+
doExtra = !jQuery.support.noCloneEvent && document["fireEvent"];
|
414
|
+
|
415
|
+
expect( 2 + ( doExtra ? 1 : 0 ) );
|
416
|
+
|
417
|
+
stop();
|
418
|
+
|
419
|
+
// This patch modified the way that cloning occurs in IE; we need to make sure that
|
420
|
+
// native event handlers on the original object don't get disturbed when they are
|
421
|
+
// modified on the clone
|
422
|
+
if ( doExtra ) {
|
423
|
+
element = jQuery("div:first").on( "click", function() {
|
424
|
+
ok( true, "Event exists on original after being unbound on clone" );
|
425
|
+
jQuery( this ).off("click");
|
426
|
+
});
|
427
|
+
clone = element.clone( true ).off("click");
|
428
|
+
clone[ 0 ].fireEvent("onclick");
|
429
|
+
element[ 0 ].fireEvent("onclick");
|
430
|
+
|
431
|
+
// manually clean up detached elements
|
432
|
+
clone.remove();
|
433
|
+
}
|
434
|
+
|
435
|
+
element = jQuery("<a class='test6997'></a>").on( "click", function() {
|
436
|
+
ok( true, "Append second element events work" );
|
437
|
+
});
|
438
|
+
|
439
|
+
jQuery("#listWithTabIndex li").append( element )
|
440
|
+
.find("a.test6997").eq( 1 ).trigger("click");
|
441
|
+
|
442
|
+
element = jQuery("<li class='test6997'></li>").on( "click", function() {
|
443
|
+
ok( true, "Before second element events work" );
|
444
|
+
start();
|
445
|
+
});
|
446
|
+
|
447
|
+
jQuery("#listWithTabIndex li").before( element );
|
448
|
+
jQuery("#listWithTabIndex li.test6997").eq( 1 ).trigger("click");
|
449
|
+
});
|
450
|
+
|
451
|
+
test( "append HTML5 sectioning elements (Bug #6485)", function() {
|
452
|
+
|
453
|
+
expect( 2 );
|
454
|
+
|
455
|
+
var article, aside;
|
456
|
+
|
457
|
+
jQuery("#qunit-fixture").append("<article style='font-size:10px'><section><aside>HTML5 elements</aside></section></article>");
|
458
|
+
|
459
|
+
article = jQuery("article");
|
460
|
+
aside = jQuery("aside");
|
461
|
+
|
462
|
+
equal( article.get( 0 ).style.fontSize, "10px", "HTML5 elements are styleable" );
|
463
|
+
equal( aside.length, 1, "HTML5 elements do not collapse their children" );
|
464
|
+
});
|
465
|
+
|
466
|
+
if ( jQuery.css ) {
|
467
|
+
test( "HTML5 Elements inherit styles from style rules (Bug #10501)", function() {
|
468
|
+
|
469
|
+
expect( 1 );
|
470
|
+
|
471
|
+
jQuery("#qunit-fixture").append("<article id='article'></article>");
|
472
|
+
jQuery("#article").append("<section>This section should have a pink background.</section>");
|
473
|
+
|
474
|
+
// In IE, the missing background color will claim its value is "transparent"
|
475
|
+
notEqual( jQuery("section").css("background-color"), "transparent", "HTML5 elements inherit styles" );
|
476
|
+
});
|
477
|
+
}
|
478
|
+
|
479
|
+
test( "html(String) with HTML5 (Bug #6485)", function() {
|
480
|
+
|
481
|
+
expect( 2 );
|
482
|
+
|
483
|
+
jQuery("#qunit-fixture").html("<article><section><aside>HTML5 elements</aside></section></article>");
|
484
|
+
equal( jQuery("#qunit-fixture").children().children().length, 1, "Make sure HTML5 article elements can hold children. innerHTML shortcut path" );
|
485
|
+
equal( jQuery("#qunit-fixture").children().children().children().length, 1, "Make sure nested HTML5 elements can hold children." );
|
486
|
+
});
|
487
|
+
|
488
|
+
test( "IE8 serialization bug", function() {
|
489
|
+
|
490
|
+
expect( 2 );
|
491
|
+
var wrapper = jQuery("<div></div>");
|
492
|
+
|
493
|
+
wrapper.html("<div></div><article></article>");
|
494
|
+
equal( wrapper.children("article").length, 1, "HTML5 elements are insertable with .html()" );
|
495
|
+
|
496
|
+
wrapper.html("<div></div><link></link>");
|
497
|
+
equal( wrapper.children("link").length, 1, "Link elements are insertable with .html()" );
|
498
|
+
});
|
499
|
+
|
500
|
+
test( "html() object element #10324", function() {
|
501
|
+
|
502
|
+
expect( 1 );
|
503
|
+
|
504
|
+
var object = jQuery("<object id='object2'><param name='object2test' value='test'></param></object>?").appendTo("#qunit-fixture"),
|
505
|
+
clone = object.clone();
|
506
|
+
|
507
|
+
equal( clone.html(), object.html(), "html() returns correct innerhtml of cloned object elements" );
|
508
|
+
});
|
509
|
+
|
510
|
+
test( "append(xml)", function() {
|
511
|
+
|
512
|
+
expect( 1 );
|
513
|
+
|
514
|
+
var xmlDoc, xml1, xml2;
|
515
|
+
|
516
|
+
function createXMLDoc() {
|
517
|
+
// Initialize DOM based upon latest installed MSXML or Netscape
|
518
|
+
var elem, n, len,
|
519
|
+
aActiveX =
|
520
|
+
[ "MSXML6.DomDocument",
|
521
|
+
"MSXML3.DomDocument",
|
522
|
+
"MSXML2.DomDocument",
|
523
|
+
"MSXML.DomDocument",
|
524
|
+
"Microsoft.XmlDom" ];
|
525
|
+
|
526
|
+
if ( document.implementation && "createDocument" in document.implementation ) {
|
527
|
+
return document.implementation.createDocument( "", "", null );
|
528
|
+
} else {
|
529
|
+
// IE
|
530
|
+
for ( n = 0, len = aActiveX.length; n < len; n++ ) {
|
531
|
+
try {
|
532
|
+
elem = new ActiveXObject( aActiveX[ n ] );
|
533
|
+
return elem;
|
534
|
+
} catch(_) {}
|
535
|
+
}
|
536
|
+
}
|
537
|
+
}
|
538
|
+
|
539
|
+
xmlDoc = createXMLDoc();
|
540
|
+
xml1 = xmlDoc.createElement("head");
|
541
|
+
xml2 = xmlDoc.createElement("test");
|
542
|
+
|
543
|
+
ok( jQuery(xml1).append(xml2), "Append an xml element to another without raising an exception." );
|
544
|
+
|
545
|
+
});
|
546
|
+
|
547
|
+
test( "appendTo(String|Element|Array<Element>|jQuery)", function() {
|
548
|
+
|
549
|
+
expect( 16 );
|
550
|
+
|
551
|
+
var defaultText, l, expected, num, div;
|
552
|
+
|
553
|
+
defaultText = "Try them out:";
|
554
|
+
jQuery("<b>buga</b>").appendTo("#first");
|
555
|
+
equal( jQuery("#first").text(), defaultText + "buga", "Check if text appending works" );
|
556
|
+
equal( jQuery("<option value='appendTest'>Append Test</option>").appendTo("#select3").parent().find("option:last-child").attr("value"), "appendTest", "Appending html options to select element" );
|
557
|
+
|
558
|
+
l = jQuery("#first").children().length + 2;
|
559
|
+
jQuery("<strong>test</strong>");
|
560
|
+
jQuery("<strong>test</strong>");
|
561
|
+
jQuery([ jQuery("<strong>test</strong>")[ 0 ], jQuery("<strong>test</strong>")[ 0 ] ])
|
562
|
+
.appendTo("#first");
|
563
|
+
equal( jQuery("#first").children().length, l, "Make sure the elements were inserted." );
|
564
|
+
equal( jQuery("#first").children().last()[ 0 ].nodeName.toLowerCase(), "strong", "Verify the last element." );
|
565
|
+
|
566
|
+
QUnit.reset();
|
567
|
+
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
|
568
|
+
jQuery( document.getElementById("first") ).appendTo("#sap");
|
569
|
+
equal( jQuery("#sap").text(), expected, "Check for appending of element" );
|
570
|
+
|
571
|
+
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
|
572
|
+
jQuery([ document.getElementById("first"), document.getElementById("yahoo") ]).appendTo("#sap");
|
573
|
+
equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" );
|
574
|
+
|
575
|
+
QUnit.reset();
|
576
|
+
ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
|
577
|
+
|
578
|
+
expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
|
579
|
+
jQuery("#yahoo, #first").appendTo("#sap");
|
580
|
+
equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" );
|
581
|
+
|
582
|
+
jQuery("#select1").appendTo("#foo");
|
583
|
+
t( "Append select", "#foo select", [ "select1" ] );
|
584
|
+
|
585
|
+
div = jQuery("<div/>").on( "click", function() {
|
586
|
+
ok( true, "Running a cloned click." );
|
587
|
+
});
|
588
|
+
div.appendTo("#qunit-fixture, #moretests");
|
589
|
+
|
590
|
+
jQuery("#qunit-fixture div").last().trigger("click");
|
591
|
+
jQuery("#moretests div").last().trigger("click");
|
592
|
+
|
593
|
+
div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests");
|
594
|
+
|
595
|
+
equal( div.length, 2, "appendTo returns the inserted elements" );
|
596
|
+
|
597
|
+
div.addClass("test");
|
598
|
+
|
599
|
+
ok( jQuery("#qunit-fixture div").last().hasClass("test"), "appendTo element was modified after the insertion" );
|
600
|
+
ok( jQuery("#moretests div").last().hasClass("test"), "appendTo element was modified after the insertion" );
|
601
|
+
|
602
|
+
div = jQuery("<div/>");
|
603
|
+
jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div );
|
604
|
+
|
605
|
+
equal( div.children().length, 1, "Make sure the right number of children were inserted." );
|
606
|
+
|
607
|
+
div = jQuery("#moretests div");
|
608
|
+
|
609
|
+
num = jQuery("#qunit-fixture div").length;
|
610
|
+
div.remove().appendTo("#qunit-fixture");
|
611
|
+
|
612
|
+
equal( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." );
|
613
|
+
});
|
614
|
+
|
615
|
+
function testPrepend( val ) {
|
616
|
+
|
617
|
+
expect( 6 );
|
618
|
+
|
619
|
+
var defaultText, result, expected;
|
620
|
+
|
621
|
+
defaultText = "Try them out:";
|
622
|
+
result = jQuery("#first").prepend( val("<b>buga</b>") );
|
623
|
+
|
624
|
+
equal( result.text(), "buga" + defaultText, "Check if text prepending works" );
|
625
|
+
equal( jQuery("#select3").prepend( val("<option value='prependTest'>Prepend Test</option>" ) ).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element" );
|
626
|
+
|
627
|
+
QUnit.reset();
|
628
|
+
expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
|
629
|
+
jQuery("#sap").prepend( val(document.getElementById("first")) );
|
630
|
+
equal( jQuery("#sap").text(), expected, "Check for prepending of element" );
|
631
|
+
|
632
|
+
QUnit.reset();
|
633
|
+
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
|
634
|
+
jQuery("#sap").prepend( val([ document.getElementById("first"), document.getElementById("yahoo") ]) );
|
635
|
+
equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" );
|
636
|
+
|
637
|
+
QUnit.reset();
|
638
|
+
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
|
639
|
+
jQuery("#sap").prepend( val(jQuery("#yahoo, #first")) );
|
640
|
+
equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
|
641
|
+
|
642
|
+
QUnit.reset();
|
643
|
+
expected = "Try them out:GoogleYahooThis link has class=\"blog\": Simon Willison's Weblog";
|
644
|
+
jQuery("#sap").prepend( val([ jQuery("#first"), jQuery("#yahoo, #google") ]) );
|
645
|
+
equal( jQuery("#sap").text(), expected, "Check for prepending of array of jQuery objects" );
|
646
|
+
}
|
647
|
+
|
648
|
+
test( "prepend(String|Element|Array<Element>|jQuery)", function() {
|
649
|
+
testPrepend( manipulationBareObj );
|
650
|
+
});
|
651
|
+
|
652
|
+
test( "prepend(Function)", function() {
|
653
|
+
testPrepend( manipulationFunctionReturningObj );
|
654
|
+
});
|
655
|
+
|
656
|
+
test( "prepend(Function) with incoming value", function() {
|
657
|
+
|
658
|
+
expect( 10 );
|
659
|
+
|
660
|
+
var defaultText, old, result, expected;
|
661
|
+
|
662
|
+
defaultText = "Try them out:";
|
663
|
+
old = jQuery("#first").html();
|
664
|
+
result = jQuery("#first").prepend(function( i, val ) {
|
665
|
+
equal( val, old, "Make sure the incoming value is correct." );
|
666
|
+
return "<b>buga</b>";
|
667
|
+
});
|
668
|
+
|
669
|
+
equal( result.text(), "buga" + defaultText, "Check if text prepending works" );
|
670
|
+
|
671
|
+
old = jQuery("#select3").html();
|
672
|
+
|
673
|
+
equal( jQuery("#select3").prepend(function( i, val ) {
|
674
|
+
equal( val, old, "Make sure the incoming value is correct." );
|
675
|
+
return "<option value='prependTest'>Prepend Test</option>";
|
676
|
+
}).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element" );
|
677
|
+
|
678
|
+
QUnit.reset();
|
679
|
+
expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
|
680
|
+
old = jQuery("#sap").html();
|
681
|
+
|
682
|
+
jQuery("#sap").prepend(function( i, val ) {
|
683
|
+
equal( val, old, "Make sure the incoming value is correct." );
|
684
|
+
return document.getElementById("first");
|
685
|
+
});
|
686
|
+
|
687
|
+
equal( jQuery("#sap").text(), expected, "Check for prepending of element" );
|
688
|
+
|
689
|
+
QUnit.reset();
|
690
|
+
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
|
691
|
+
old = jQuery("#sap").html();
|
692
|
+
|
693
|
+
jQuery("#sap").prepend(function( i, val ) {
|
694
|
+
equal( val, old, "Make sure the incoming value is correct." );
|
695
|
+
return [ document.getElementById("first"), document.getElementById("yahoo") ];
|
696
|
+
});
|
697
|
+
|
698
|
+
equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" );
|
699
|
+
|
700
|
+
QUnit.reset();
|
701
|
+
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
|
702
|
+
old = jQuery("#sap").html();
|
703
|
+
|
704
|
+
jQuery("#sap").prepend(function( i, val ) {
|
705
|
+
equal( val, old, "Make sure the incoming value is correct." );
|
706
|
+
return jQuery("#yahoo, #first");
|
707
|
+
});
|
708
|
+
|
709
|
+
equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
|
710
|
+
});
|
711
|
+
|
712
|
+
test( "prependTo(String|Element|Array<Element>|jQuery)", function() {
|
713
|
+
|
714
|
+
expect( 6 );
|
715
|
+
|
716
|
+
var defaultText, expected;
|
717
|
+
|
718
|
+
defaultText = "Try them out:";
|
719
|
+
jQuery("<b>buga</b>").prependTo("#first");
|
720
|
+
equal( jQuery("#first").text(), "buga" + defaultText, "Check if text prepending works" );
|
721
|
+
equal( jQuery("<option value='prependTest'>Prepend Test</option>").prependTo("#select3").parent().find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element" );
|
722
|
+
|
723
|
+
QUnit.reset();
|
724
|
+
expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
|
725
|
+
jQuery( document.getElementById("first") ).prependTo("#sap");
|
726
|
+
equal( jQuery("#sap").text(), expected, "Check for prepending of element" );
|
727
|
+
|
728
|
+
QUnit.reset();
|
729
|
+
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
|
730
|
+
jQuery( [ document.getElementById("first"), document.getElementById("yahoo") ] ).prependTo("#sap");
|
731
|
+
equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" );
|
732
|
+
|
733
|
+
QUnit.reset();
|
734
|
+
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
|
735
|
+
jQuery("#yahoo, #first").prependTo("#sap");
|
736
|
+
equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
|
737
|
+
|
738
|
+
QUnit.reset();
|
739
|
+
jQuery("<select id='prependSelect1'></select>").prependTo("#form");
|
740
|
+
jQuery("<select id='prependSelect2'><option>Test</option></select>").prependTo("#form");
|
741
|
+
|
742
|
+
t( "Prepend Select", "#prependSelect2, #prependSelect1", [ "prependSelect2", "prependSelect1" ] );
|
743
|
+
});
|
744
|
+
|
745
|
+
function testBefore( val ) {
|
746
|
+
|
747
|
+
expect( 7 );
|
748
|
+
|
749
|
+
var expected, set;
|
750
|
+
|
751
|
+
expected = "This is a normal link: bugaYahoo";
|
752
|
+
jQuery("#yahoo").before( val("<b>buga</b>") );
|
753
|
+
equal( jQuery("#en").text(), expected, "Insert String before" );
|
754
|
+
|
755
|
+
QUnit.reset();
|
756
|
+
expected = "This is a normal link: Try them out:Yahoo";
|
757
|
+
jQuery("#yahoo").before( val(document.getElementById("first")) );
|
758
|
+
equal( jQuery("#en").text(), expected, "Insert element before" );
|
759
|
+
|
760
|
+
QUnit.reset();
|
761
|
+
expected = "This is a normal link: Try them out:diveintomarkYahoo";
|
762
|
+
jQuery("#yahoo").before( val([ document.getElementById("first"), document.getElementById("mark") ]) );
|
763
|
+
equal( jQuery("#en").text(), expected, "Insert array of elements before" );
|
764
|
+
|
765
|
+
QUnit.reset();
|
766
|
+
expected = "This is a normal link: diveintomarkTry them out:Yahoo";
|
767
|
+
jQuery("#yahoo").before( val(jQuery("#mark, #first")) );
|
768
|
+
equal( jQuery("#en").text(), expected, "Insert jQuery before" );
|
769
|
+
|
770
|
+
QUnit.reset();
|
771
|
+
expected = "This is a normal link: Try them out:GooglediveintomarkYahoo";
|
772
|
+
jQuery("#yahoo").before( val([ jQuery("#first"), jQuery("#mark, #google") ]) );
|
773
|
+
equal( jQuery("#en").text(), expected, "Insert array of jQuery objects before" );
|
774
|
+
|
775
|
+
set = jQuery("<div/>").before("<span>test</span>");
|
776
|
+
equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert before a disconnected node should be a no-op" );
|
777
|
+
equal( set.length, 1, "Insert the element before the disconnected node. should be a no-op" );
|
778
|
+
}
|
779
|
+
|
780
|
+
test( "before(String|Element|Array<Element>|jQuery)", function() {
|
781
|
+
testBefore( manipulationBareObj );
|
782
|
+
});
|
783
|
+
|
784
|
+
test( "before(Function)", function() {
|
785
|
+
testBefore( manipulationFunctionReturningObj );
|
786
|
+
});
|
787
|
+
|
788
|
+
test( "before and after w/ empty object (#10812)", function() {
|
789
|
+
|
790
|
+
expect( 1 );
|
791
|
+
|
792
|
+
var res;
|
793
|
+
|
794
|
+
res = jQuery( "#notInTheDocument" ).before( "(" ).after( ")" );
|
795
|
+
equal( res.length, 0, "didn't choke on empty object" );
|
796
|
+
});
|
797
|
+
|
798
|
+
test( "before and after on disconnected node (#10517)", function() {
|
799
|
+
|
800
|
+
expect( 6 );
|
801
|
+
|
802
|
+
var expectedBefore = "This is a normal link: bugaYahoo",
|
803
|
+
expectedAfter = "This is a normal link: Yahoobuga";
|
804
|
+
|
805
|
+
equal( jQuery("<input type='checkbox'/>").before("<div/>").length, 1, "before() on disconnected node is no-op" );
|
806
|
+
equal( jQuery("<input type='checkbox'/>").after("<div/>").length, 1, "after() on disconnected node is no-op" );
|
807
|
+
|
808
|
+
QUnit.reset();
|
809
|
+
jQuery("#yahoo").add("<span/>").before("<b>buga</b>");
|
810
|
+
equal( jQuery("#en").text(), expectedBefore, "Insert String before with disconnected node last" );
|
811
|
+
|
812
|
+
QUnit.reset();
|
813
|
+
jQuery("<span/>").add("#yahoo").before("<b>buga</b>");
|
814
|
+
equal( jQuery("#en").text(), expectedBefore, "Insert String before with disconnected node first" );
|
815
|
+
|
816
|
+
QUnit.reset();
|
817
|
+
jQuery("#yahoo").add("<span/>").after("<b>buga</b>");
|
818
|
+
equal( jQuery("#en").text(), expectedAfter, "Insert String after with disconnected node last" );
|
819
|
+
|
820
|
+
QUnit.reset();
|
821
|
+
jQuery("<span/>").add("#yahoo").after("<b>buga</b>");
|
822
|
+
equal( jQuery("#en").text(), expectedAfter, "Insert String after with disconnected node first" );
|
823
|
+
});
|
824
|
+
|
825
|
+
test( "insertBefore(String|Element|Array<Element>|jQuery)", function() {
|
826
|
+
|
827
|
+
expect( 4 );
|
828
|
+
|
829
|
+
var expected;
|
830
|
+
|
831
|
+
expected = "This is a normal link: bugaYahoo";
|
832
|
+
jQuery("<b>buga</b>").insertBefore("#yahoo");
|
833
|
+
equal( jQuery("#en").text(), expected, "Insert String before" );
|
834
|
+
|
835
|
+
QUnit.reset();
|
836
|
+
expected = "This is a normal link: Try them out:Yahoo";
|
837
|
+
jQuery( document.getElementById("first") ).insertBefore("#yahoo");
|
838
|
+
equal( jQuery("#en").text(), expected, "Insert element before" );
|
839
|
+
|
840
|
+
QUnit.reset();
|
841
|
+
expected = "This is a normal link: Try them out:diveintomarkYahoo";
|
842
|
+
jQuery( [ document.getElementById("first"), document.getElementById("mark") ] ).insertBefore("#yahoo");
|
843
|
+
equal( jQuery("#en").text(), expected, "Insert array of elements before" );
|
844
|
+
|
845
|
+
QUnit.reset();
|
846
|
+
expected = "This is a normal link: diveintomarkTry them out:Yahoo";
|
847
|
+
jQuery("#mark, #first").insertBefore("#yahoo");
|
848
|
+
equal( jQuery("#en").text(), expected, "Insert jQuery before" );
|
849
|
+
});
|
850
|
+
|
851
|
+
function testAfter( val ) {
|
852
|
+
|
853
|
+
expect( 7 );
|
854
|
+
|
855
|
+
var set, expected;
|
856
|
+
|
857
|
+
expected = "This is a normal link: Yahoobuga";
|
858
|
+
jQuery("#yahoo").after( val("<b>buga</b>") );
|
859
|
+
equal( jQuery("#en").text(), expected, "Insert String after" );
|
860
|
+
|
861
|
+
QUnit.reset();
|
862
|
+
expected = "This is a normal link: YahooTry them out:";
|
863
|
+
jQuery("#yahoo").after( val(document.getElementById("first")) );
|
864
|
+
equal( jQuery("#en").text(), expected, "Insert element after" );
|
865
|
+
|
866
|
+
QUnit.reset();
|
867
|
+
expected = "This is a normal link: YahooTry them out:diveintomark";
|
868
|
+
jQuery("#yahoo").after( val([ document.getElementById("first"), document.getElementById("mark") ]) );
|
869
|
+
equal( jQuery("#en").text(), expected, "Insert array of elements after" );
|
870
|
+
|
871
|
+
QUnit.reset();
|
872
|
+
expected = "This is a normal link: YahoodiveintomarkTry them out:";
|
873
|
+
jQuery("#yahoo").after(val( jQuery("#mark, #first") ));
|
874
|
+
equal( jQuery("#en").text(), expected, "Insert jQuery after" );
|
875
|
+
|
876
|
+
QUnit.reset();
|
877
|
+
expected = "This is a normal link: YahooTry them out:Googlediveintomark";
|
878
|
+
jQuery("#yahoo").after( val([ jQuery("#first"), jQuery("#mark, #google") ]) );
|
879
|
+
equal( jQuery("#en").text(), expected, "Insert array of jQuery objects after" );
|
880
|
+
|
881
|
+
set = jQuery("<div/>").before("<span>test</span>");
|
882
|
+
equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert after a disconnected node should be a no-op" );
|
883
|
+
equal( set.length, 1, "Insert the element after the disconnected node should be a no-op" );
|
884
|
+
}
|
885
|
+
|
886
|
+
test( "after(String|Element|Array<Element>|jQuery)", function() {
|
887
|
+
testAfter( manipulationBareObj );
|
888
|
+
});
|
889
|
+
|
890
|
+
test( "after(Function)", function() {
|
891
|
+
testAfter( manipulationFunctionReturningObj );
|
892
|
+
});
|
893
|
+
|
894
|
+
test( "insertAfter(String|Element|Array<Element>|jQuery)", function() {
|
895
|
+
|
896
|
+
expect( 4 ) ;
|
897
|
+
|
898
|
+
var expected;
|
899
|
+
|
900
|
+
expected = "This is a normal link: Yahoobuga";
|
901
|
+
jQuery("<b>buga</b>").insertAfter("#yahoo");
|
902
|
+
equal( jQuery("#en").text(), expected, "Insert String after" );
|
903
|
+
|
904
|
+
QUnit.reset();
|
905
|
+
expected = "This is a normal link: YahooTry them out:";
|
906
|
+
jQuery( document.getElementById("first") ).insertAfter("#yahoo");
|
907
|
+
equal( jQuery("#en").text(), expected, "Insert element after" );
|
908
|
+
|
909
|
+
QUnit.reset();
|
910
|
+
expected = "This is a normal link: YahooTry them out:diveintomark";
|
911
|
+
jQuery( [ document.getElementById("first"), document.getElementById("mark") ] ).insertAfter("#yahoo");
|
912
|
+
equal( jQuery("#en").text(), expected, "Insert array of elements after" );
|
913
|
+
|
914
|
+
QUnit.reset();
|
915
|
+
expected = "This is a normal link: YahoodiveintomarkTry them out:";
|
916
|
+
jQuery("#mark, #first").insertAfter("#yahoo");
|
917
|
+
equal( jQuery("#en").text(), expected, "Insert jQuery after" );
|
918
|
+
});
|
919
|
+
|
920
|
+
function testReplaceWith( val ) {
|
921
|
+
|
922
|
+
var tmp, y, child, child2, set, non_existent, $div,
|
923
|
+
expected = 29;
|
924
|
+
|
925
|
+
expect( expected );
|
926
|
+
|
927
|
+
jQuery("#yahoo").replaceWith( val("<b id='replace'>buga</b>") );
|
928
|
+
ok( jQuery("#replace")[ 0 ], "Replace element with element from string" );
|
929
|
+
ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after string" );
|
930
|
+
|
931
|
+
jQuery("#anchor2").replaceWith( val(document.getElementById("first")) );
|
932
|
+
ok( jQuery("#first")[ 0 ], "Replace element with element" );
|
933
|
+
ok( !jQuery("#anchor2")[ 0 ], "Verify that original element is gone, after element" );
|
934
|
+
|
935
|
+
jQuery("#qunit-fixture").append("<div id='bar'><div id='baz'></div></div>");
|
936
|
+
jQuery("#baz").replaceWith( val("Baz") );
|
937
|
+
equal( jQuery("#bar").text(),"Baz", "Replace element with text" );
|
938
|
+
ok( !jQuery("#baz")[ 0 ], "Verify that original element is gone, after element" );
|
939
|
+
|
940
|
+
jQuery("#bar").replaceWith( "<div id='yahoo'></div>", "...", "<div id='baz'></div>" );
|
941
|
+
deepEqual( jQuery("#yahoo, #baz").get(), q( "yahoo", "baz" ), "Replace element with multiple arguments (#13722)" );
|
942
|
+
strictEqual( jQuery("#yahoo")[0].nextSibling, jQuery("#baz")[0].previousSibling, "Argument order preserved" );
|
943
|
+
deepEqual( jQuery("#bar").get(), [], "Verify that original element is gone, after multiple arguments" );
|
944
|
+
|
945
|
+
jQuery("#google").replaceWith( val([ document.getElementById("first"), document.getElementById("mark") ]) );
|
946
|
+
deepEqual( jQuery("#mark, #first").get(), q( "first", "mark" ), "Replace element with array of elements" );
|
947
|
+
ok( !jQuery("#google")[ 0 ], "Verify that original element is gone, after array of elements" );
|
948
|
+
|
949
|
+
jQuery("#groups").replaceWith( val(jQuery("#mark, #first")) );
|
950
|
+
deepEqual( jQuery("#mark, #first").get(), q( "first", "mark" ), "Replace element with jQuery collection" );
|
951
|
+
ok( !jQuery("#groups")[ 0 ], "Verify that original element is gone, after jQuery collection" );
|
952
|
+
|
953
|
+
jQuery("#mark, #first").replaceWith( val("<span class='replacement'></span><span class='replacement'></span>") );
|
954
|
+
equal( jQuery("#qunit-fixture .replacement").length, 4, "Replace multiple elements (#12449)" );
|
955
|
+
deepEqual( jQuery("#mark, #first").get(), [], "Verify that original elements are gone, after replace multiple" );
|
956
|
+
|
957
|
+
tmp = jQuery("<b>content</b>")[0];
|
958
|
+
jQuery("#anchor1").contents().replaceWith( val(tmp) );
|
959
|
+
deepEqual( jQuery("#anchor1").contents().get(), [ tmp ], "Replace text node with element" );
|
960
|
+
|
961
|
+
|
962
|
+
tmp = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() {
|
963
|
+
ok( true, "Newly bound click run." );
|
964
|
+
});
|
965
|
+
y = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() {
|
966
|
+
ok( false, "Previously bound click run." );
|
967
|
+
});
|
968
|
+
child = y.append("<b>test</b>").find("b").on( "click", function() {
|
969
|
+
ok( true, "Child bound click run." );
|
970
|
+
return false;
|
971
|
+
});
|
972
|
+
|
973
|
+
y.replaceWith( val(tmp) );
|
974
|
+
|
975
|
+
tmp.trigger("click");
|
976
|
+
y.trigger("click"); // Shouldn't be run
|
977
|
+
child.trigger("click"); // Shouldn't be run
|
978
|
+
|
979
|
+
|
980
|
+
y = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() {
|
981
|
+
ok( false, "Previously bound click run." );
|
982
|
+
});
|
983
|
+
child2 = y.append("<u>test</u>").find("u").on( "click", function() {
|
984
|
+
ok( true, "Child 2 bound click run." );
|
985
|
+
return false;
|
986
|
+
});
|
987
|
+
|
988
|
+
y.replaceWith( val(child2) );
|
989
|
+
|
990
|
+
child2.trigger("click");
|
991
|
+
|
992
|
+
|
993
|
+
set = jQuery("<div/>").replaceWith( val("<span>test</span>") );
|
994
|
+
equal( set[0].nodeName.toLowerCase(), "div", "No effect on a disconnected node." );
|
995
|
+
equal( set.length, 1, "No effect on a disconnected node." );
|
996
|
+
equal( set[0].childNodes.length, 0, "No effect on a disconnected node." );
|
997
|
+
|
998
|
+
|
999
|
+
child = jQuery("#qunit-fixture").children().first();
|
1000
|
+
$div = jQuery("<div class='pathological'/>").insertBefore( child );
|
1001
|
+
$div.replaceWith( $div );
|
1002
|
+
deepEqual( jQuery( ".pathological", "#qunit-fixture" ).get(), $div.get(),
|
1003
|
+
"Self-replacement" );
|
1004
|
+
$div.replaceWith( child );
|
1005
|
+
deepEqual( jQuery("#qunit-fixture").children().first().get(), child.get(),
|
1006
|
+
"Replacement with following sibling (#13810)" );
|
1007
|
+
deepEqual( jQuery( ".pathological", "#qunit-fixture" ).get(), [],
|
1008
|
+
"Replacement with following sibling (context removed)" );
|
1009
|
+
|
1010
|
+
|
1011
|
+
non_existent = jQuery("#does-not-exist").replaceWith( val("<b>should not throw an error</b>") );
|
1012
|
+
equal( non_existent.length, 0, "Length of non existent element." );
|
1013
|
+
|
1014
|
+
$div = jQuery("<div class='replacewith'></div>").appendTo("#qunit-fixture");
|
1015
|
+
$div.replaceWith( val("<div class='replacewith'></div><script>" +
|
1016
|
+
"equal( jQuery('.replacewith').length, 1, 'Check number of elements in page.' );" +
|
1017
|
+
"</script>") );
|
1018
|
+
|
1019
|
+
jQuery("#qunit-fixture").append("<div id='replaceWith'></div>");
|
1020
|
+
equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
|
1021
|
+
jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
|
1022
|
+
equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists after replacement." );
|
1023
|
+
jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
|
1024
|
+
equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists after subsequent replacement." );
|
1025
|
+
|
1026
|
+
return expected;
|
1027
|
+
}
|
1028
|
+
|
1029
|
+
test( "replaceWith(String|Element|Array<Element>|jQuery)", function() {
|
1030
|
+
testReplaceWith( manipulationBareObj );
|
1031
|
+
});
|
1032
|
+
|
1033
|
+
test( "replaceWith(Function)", function() {
|
1034
|
+
expect( testReplaceWith(manipulationFunctionReturningObj) + 1 );
|
1035
|
+
|
1036
|
+
var y = jQuery("#foo")[ 0 ];
|
1037
|
+
|
1038
|
+
jQuery( y ).replaceWith(function() {
|
1039
|
+
equal( this, y, "Make sure the context is coming in correctly." );
|
1040
|
+
});
|
1041
|
+
});
|
1042
|
+
|
1043
|
+
test( "replaceWith(string) for more than one element", function() {
|
1044
|
+
|
1045
|
+
expect( 3 );
|
1046
|
+
|
1047
|
+
equal( jQuery("#foo p").length, 3, "ensuring that test data has not changed" );
|
1048
|
+
|
1049
|
+
jQuery("#foo p").replaceWith("<span>bar</span>");
|
1050
|
+
equal(jQuery("#foo span").length, 3, "verify that all the three original element have been replaced");
|
1051
|
+
equal(jQuery("#foo p").length, 0, "verify that all the three original element have been replaced");
|
1052
|
+
});
|
1053
|
+
|
1054
|
+
test( "empty replaceWith (#13401; #13596)", 4, function() {
|
1055
|
+
expect( 6 );
|
1056
|
+
|
1057
|
+
var $el = jQuery("<div/>"),
|
1058
|
+
tests = {
|
1059
|
+
"empty string": "",
|
1060
|
+
"empty array": [],
|
1061
|
+
"empty collection": jQuery("#nonexistent")
|
1062
|
+
};
|
1063
|
+
|
1064
|
+
jQuery.each( tests, function( label, input ) {
|
1065
|
+
$el.html("<a/>").children().replaceWith( input );
|
1066
|
+
strictEqual( $el.html(), "", "replaceWith(" + label + ")" );
|
1067
|
+
$el.html("<b/>").children().replaceWith(function() { return input; });
|
1068
|
+
strictEqual( $el.html(), "", "replaceWith(function returning " + label + ")" );
|
1069
|
+
});
|
1070
|
+
});
|
1071
|
+
|
1072
|
+
test( "replaceAll(String|Element|Array<Element>|jQuery)", function() {
|
1073
|
+
|
1074
|
+
expect( 10 );
|
1075
|
+
|
1076
|
+
jQuery("<b id='replace'>buga</b>").replaceAll("#yahoo");
|
1077
|
+
ok( jQuery("#replace")[ 0 ], "Replace element with string" );
|
1078
|
+
ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after string" );
|
1079
|
+
|
1080
|
+
QUnit.reset();
|
1081
|
+
jQuery( document.getElementById("first") ).replaceAll("#yahoo");
|
1082
|
+
ok( jQuery("#first")[ 0 ], "Replace element with element" );
|
1083
|
+
ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after element" );
|
1084
|
+
|
1085
|
+
QUnit.reset();
|
1086
|
+
jQuery( [ document.getElementById("first"), document.getElementById("mark") ] ).replaceAll("#yahoo");
|
1087
|
+
ok( jQuery("#first")[ 0 ], "Replace element with array of elements" );
|
1088
|
+
ok( jQuery("#mark")[ 0 ], "Replace element with array of elements" );
|
1089
|
+
ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after array of elements" );
|
1090
|
+
|
1091
|
+
QUnit.reset();
|
1092
|
+
jQuery("#mark, #first").replaceAll("#yahoo");
|
1093
|
+
ok( jQuery("#first")[ 0 ], "Replace element with set of elements" );
|
1094
|
+
ok( jQuery("#mark")[ 0 ], "Replace element with set of elements" );
|
1095
|
+
ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after set of elements" );
|
1096
|
+
});
|
1097
|
+
|
1098
|
+
test( "jQuery.clone() (#8017)", function() {
|
1099
|
+
|
1100
|
+
expect( 2 );
|
1101
|
+
|
1102
|
+
ok( jQuery.clone && jQuery.isFunction( jQuery.clone ) , "jQuery.clone() utility exists and is a function.");
|
1103
|
+
|
1104
|
+
var main = jQuery("#qunit-fixture")[ 0 ],
|
1105
|
+
clone = jQuery.clone( main );
|
1106
|
+
|
1107
|
+
equal( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" );
|
1108
|
+
});
|
1109
|
+
|
1110
|
+
test( "append to multiple elements (#8070)", function() {
|
1111
|
+
|
1112
|
+
expect( 2 );
|
1113
|
+
|
1114
|
+
var selects = jQuery("<select class='test8070'></select><select class='test8070'></select>").appendTo("#qunit-fixture");
|
1115
|
+
selects.append("<OPTION>1</OPTION><OPTION>2</OPTION>");
|
1116
|
+
|
1117
|
+
equal( selects[ 0 ].childNodes.length, 2, "First select got two nodes" );
|
1118
|
+
equal( selects[ 1 ].childNodes.length, 2, "Second select got two nodes" );
|
1119
|
+
});
|
1120
|
+
|
1121
|
+
test( "table manipulation", function() {
|
1122
|
+
expect( 2 );
|
1123
|
+
|
1124
|
+
var table = jQuery("<table style='font-size:16px'></table>").appendTo("#qunit-fixture").empty(),
|
1125
|
+
height = table[0].offsetHeight;
|
1126
|
+
|
1127
|
+
table.append("<tr><td>DATA</td></tr>");
|
1128
|
+
ok( table[0].offsetHeight - height >= 15, "appended rows are visible" );
|
1129
|
+
|
1130
|
+
table.empty();
|
1131
|
+
height = table[0].offsetHeight;
|
1132
|
+
table.prepend("<tr><td>DATA</td></tr>");
|
1133
|
+
ok( table[0].offsetHeight - height >= 15, "prepended rows are visible" );
|
1134
|
+
});
|
1135
|
+
|
1136
|
+
test( "clone()", function() {
|
1137
|
+
|
1138
|
+
expect( 45 );
|
1139
|
+
|
1140
|
+
var div, clone, form, body;
|
1141
|
+
|
1142
|
+
equal( jQuery("#en").text(), "This is a normal link: Yahoo", "Assert text for #en" );
|
1143
|
+
equal( jQuery("#first").append( jQuery("#yahoo").clone() ).text(), "Try them out:Yahoo", "Check for clone" );
|
1144
|
+
equal( jQuery("#en").text(), "This is a normal link: Yahoo", "Reassert text for #en" );
|
1145
|
+
|
1146
|
+
jQuery.each( "table thead tbody tfoot tr td div button ul ol li select option textarea iframe".split(" "), function( i, nodeName ) {
|
1147
|
+
equal( jQuery( "<" + nodeName + "/>" ).clone()[ 0 ].nodeName.toLowerCase(), nodeName, "Clone a " + nodeName );
|
1148
|
+
});
|
1149
|
+
equal( jQuery("<input type='checkbox' />").clone()[ 0 ].nodeName.toLowerCase(), "input", "Clone a <input type='checkbox' />" );
|
1150
|
+
|
1151
|
+
// Check cloning non-elements
|
1152
|
+
equal( jQuery("#nonnodes").contents().clone().length, 3, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
|
1153
|
+
|
1154
|
+
// Verify that clones of clones can keep event listeners
|
1155
|
+
div = jQuery("<div><ul><li>test</li></ul></div>").on( "click", function() {
|
1156
|
+
ok( true, "Bound event still exists." );
|
1157
|
+
});
|
1158
|
+
clone = div.clone( true ); div.remove();
|
1159
|
+
div = clone.clone( true ); clone.remove();
|
1160
|
+
|
1161
|
+
equal( div.length, 1, "One element cloned" );
|
1162
|
+
equal( div[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
|
1163
|
+
div.trigger("click");
|
1164
|
+
|
1165
|
+
// Manually clean up detached elements
|
1166
|
+
div.remove();
|
1167
|
+
|
1168
|
+
// Verify that cloned children can keep event listeners
|
1169
|
+
div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
|
1170
|
+
div.find("table").on( "click", function() {
|
1171
|
+
ok( true, "Bound event still exists." );
|
1172
|
+
});
|
1173
|
+
|
1174
|
+
clone = div.clone( true );
|
1175
|
+
equal( clone.length, 1, "One element cloned" );
|
1176
|
+
equal( clone[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
|
1177
|
+
clone.find("table").trigger("click");
|
1178
|
+
|
1179
|
+
// Manually clean up detached elements
|
1180
|
+
div.remove();
|
1181
|
+
clone.remove();
|
1182
|
+
|
1183
|
+
// Make sure that doing .clone() doesn't clone event listeners
|
1184
|
+
div = jQuery("<div><ul><li>test</li></ul></div>").on( "click", function() {
|
1185
|
+
ok( false, "Bound event still exists after .clone()." );
|
1186
|
+
});
|
1187
|
+
clone = div.clone();
|
1188
|
+
|
1189
|
+
clone.trigger("click");
|
1190
|
+
|
1191
|
+
// Manually clean up detached elements
|
1192
|
+
clone.remove();
|
1193
|
+
div.remove();
|
1194
|
+
|
1195
|
+
// Test both html() and clone() for <embed> and <object> types
|
1196
|
+
div = jQuery("<div/>").html("<embed height='355' width='425' src='http://www.youtube.com/v/3KANI2dpXLw&hl=en'></embed>");
|
1197
|
+
|
1198
|
+
clone = div.clone( true );
|
1199
|
+
equal( clone.length, 1, "One element cloned" );
|
1200
|
+
equal( clone.html(), div.html(), "Element contents cloned" );
|
1201
|
+
equal( clone[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
|
1202
|
+
|
1203
|
+
// this is technically an invalid object, but because of the special
|
1204
|
+
// classid instantiation it is the only kind that IE has trouble with,
|
1205
|
+
// so let's test with it too.
|
1206
|
+
div = jQuery("<div/>").html("<object height='355' width='425' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='wmode' value='transparent'> </object>");
|
1207
|
+
|
1208
|
+
clone = div.clone( true );
|
1209
|
+
equal( clone.length, 1, "One element cloned" );
|
1210
|
+
equal( clone[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
|
1211
|
+
div = div.find("object");
|
1212
|
+
clone = clone.find("object");
|
1213
|
+
// oldIE adds extra attributes and <param> elements, so just test for existence of the defined set
|
1214
|
+
jQuery.each( [ "height", "width", "classid" ], function( i, attr ) {
|
1215
|
+
equal( clone.attr( attr ), div.attr( attr ), "<object> attribute cloned: " + attr );
|
1216
|
+
} );
|
1217
|
+
(function() {
|
1218
|
+
var params = {};
|
1219
|
+
|
1220
|
+
clone.find("param").each(function( index, param ) {
|
1221
|
+
params[ param.attributes.name.nodeValue.toLowerCase() ] =
|
1222
|
+
param.attributes.value.nodeValue.toLowerCase();
|
1223
|
+
});
|
1224
|
+
|
1225
|
+
div.find("param").each(function( index, param ) {
|
1226
|
+
var key = param.attributes.name.nodeValue.toLowerCase();
|
1227
|
+
equal( params[ key ], param.attributes.value.nodeValue.toLowerCase(), "<param> cloned: " + key );
|
1228
|
+
});
|
1229
|
+
})();
|
1230
|
+
|
1231
|
+
// and here's a valid one.
|
1232
|
+
div = jQuery("<div/>").html("<object height='355' width='425' type='application/x-shockwave-flash' data='http://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='wmode' value='transparent'> </object>");
|
1233
|
+
|
1234
|
+
clone = div.clone(true);
|
1235
|
+
equal( clone.length, 1, "One element cloned" );
|
1236
|
+
equal( clone.html(), div.html(), "Element contents cloned" );
|
1237
|
+
equal( clone[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
|
1238
|
+
|
1239
|
+
div = jQuery("<div/>").data({ "a": true });
|
1240
|
+
clone = div.clone( true );
|
1241
|
+
equal( clone.data("a"), true, "Data cloned." );
|
1242
|
+
clone.data( "a", false );
|
1243
|
+
equal( clone.data("a"), false, "Ensure cloned element data object was correctly modified" );
|
1244
|
+
equal( div.data("a"), true, "Ensure cloned element data object is copied, not referenced" );
|
1245
|
+
|
1246
|
+
// manually clean up detached elements
|
1247
|
+
div.remove();
|
1248
|
+
clone.remove();
|
1249
|
+
|
1250
|
+
form = document.createElement("form");
|
1251
|
+
form.action = "/test/";
|
1252
|
+
|
1253
|
+
div = document.createElement("div");
|
1254
|
+
div.appendChild( document.createTextNode("test") );
|
1255
|
+
form.appendChild( div );
|
1256
|
+
|
1257
|
+
equal( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." );
|
1258
|
+
|
1259
|
+
body = jQuery("body").clone();
|
1260
|
+
equal( body.children()[ 0 ].id, "qunit", "Make sure cloning body works" );
|
1261
|
+
body.remove();
|
1262
|
+
});
|
1263
|
+
|
1264
|
+
test( "clone(script type=non-javascript) (#11359)", function() {
|
1265
|
+
|
1266
|
+
expect( 3 );
|
1267
|
+
|
1268
|
+
var src = jQuery("<script type='text/filler'>Lorem ipsum dolor sit amet</script><q><script type='text/filler'>consectetur adipiscing elit</script></q>"),
|
1269
|
+
dest = src.clone();
|
1270
|
+
|
1271
|
+
equal( dest[ 0 ].text, "Lorem ipsum dolor sit amet", "Cloning preserves script text" );
|
1272
|
+
equal( dest.last().html(), src.last().html(), "Cloning preserves nested script text" );
|
1273
|
+
ok( /^\s*<scr.pt\s+type=['"]?text\/filler['"]?\s*>consectetur adipiscing elit<\/scr.pt>\s*$/i.test( dest.last().html() ), "Cloning preserves nested script text" );
|
1274
|
+
dest.remove();
|
1275
|
+
});
|
1276
|
+
|
1277
|
+
test( "clone(form element) (Bug #3879, #6655)", function() {
|
1278
|
+
|
1279
|
+
expect( 5 );
|
1280
|
+
|
1281
|
+
var clone, element;
|
1282
|
+
|
1283
|
+
element = jQuery("<select><option>Foo</option><option value='selected' selected>Bar</option></select>");
|
1284
|
+
|
1285
|
+
equal( element.clone().find("option").filter(function() { return this.selected; }).val(), "selected", "Selected option cloned correctly" );
|
1286
|
+
|
1287
|
+
element = jQuery("<input type='checkbox' value='foo'>").attr( "checked", "checked" );
|
1288
|
+
clone = element.clone();
|
1289
|
+
|
1290
|
+
equal( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
|
1291
|
+
equal( clone[ 0 ].defaultValue, "foo", "Checked input defaultValue cloned correctly" );
|
1292
|
+
|
1293
|
+
element = jQuery("<input type='text' value='foo'>");
|
1294
|
+
clone = element.clone();
|
1295
|
+
equal( clone[ 0 ].defaultValue, "foo", "Text input defaultValue cloned correctly" );
|
1296
|
+
|
1297
|
+
element = jQuery("<textarea>foo</textarea>");
|
1298
|
+
clone = element.clone();
|
1299
|
+
equal( clone[ 0 ].defaultValue, "foo", "Textarea defaultValue cloned correctly" );
|
1300
|
+
});
|
1301
|
+
|
1302
|
+
test( "clone(multiple selected options) (Bug #8129)", function() {
|
1303
|
+
|
1304
|
+
expect( 1 );
|
1305
|
+
|
1306
|
+
var element = jQuery("<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>");
|
1307
|
+
|
1308
|
+
equal( element.clone().find("option:selected").length, element.find("option:selected").length, "Multiple selected options cloned correctly" );
|
1309
|
+
|
1310
|
+
});
|
1311
|
+
|
1312
|
+
test( "clone() on XML nodes", function() {
|
1313
|
+
|
1314
|
+
expect( 2 );
|
1315
|
+
|
1316
|
+
var xml = createDashboardXML(),
|
1317
|
+
root = jQuery(xml.documentElement).clone(),
|
1318
|
+
origTab = jQuery("tab", xml).eq( 0 ),
|
1319
|
+
cloneTab = jQuery("tab", root).eq( 0 );
|
1320
|
+
|
1321
|
+
origTab.text("origval");
|
1322
|
+
cloneTab.text("cloneval");
|
1323
|
+
equal( origTab.text(), "origval", "Check original XML node was correctly set" );
|
1324
|
+
equal( cloneTab.text(), "cloneval", "Check cloned XML node was correctly set" );
|
1325
|
+
});
|
1326
|
+
|
1327
|
+
test( "clone() on local XML nodes with html5 nodename", function() {
|
1328
|
+
|
1329
|
+
expect( 2 );
|
1330
|
+
|
1331
|
+
var $xmlDoc = jQuery( jQuery.parseXML( "<root><meter /></root>" ) ),
|
1332
|
+
$meter = $xmlDoc.find( "meter" ).clone();
|
1333
|
+
|
1334
|
+
equal( $meter[ 0 ].nodeName, "meter", "Check if nodeName was not changed due to cloning" );
|
1335
|
+
equal( $meter[ 0 ].nodeType, 1, "Check if nodeType is not changed due to cloning" );
|
1336
|
+
});
|
1337
|
+
|
1338
|
+
test( "html(undefined)", function() {
|
1339
|
+
|
1340
|
+
expect( 1 );
|
1341
|
+
|
1342
|
+
equal( jQuery("#foo").html("<i>test</i>").html(undefined).html().toLowerCase(), "<i>test</i>", ".html(undefined) is chainable (#5571)" );
|
1343
|
+
});
|
1344
|
+
|
1345
|
+
test( "html() on empty set", function() {
|
1346
|
+
|
1347
|
+
expect( 1 );
|
1348
|
+
|
1349
|
+
strictEqual( jQuery().html(), undefined, ".html() returns undefined for empty sets (#11962)" );
|
1350
|
+
});
|
1351
|
+
|
1352
|
+
function childNodeNames( node ) {
|
1353
|
+
return jQuery.map( node.childNodes, function( child ) {
|
1354
|
+
return child.nodeName.toUpperCase();
|
1355
|
+
}).join(" ");
|
1356
|
+
}
|
1357
|
+
|
1358
|
+
function testHtml( valueObj ) {
|
1359
|
+
expect( 37 );
|
1360
|
+
|
1361
|
+
var actual, expected, tmp,
|
1362
|
+
div = jQuery("<div></div>"),
|
1363
|
+
fixture = jQuery("#qunit-fixture");
|
1364
|
+
|
1365
|
+
div.html( valueObj("<div id='parent_1'><div id='child_1'/></div><div id='parent_2'/>") );
|
1366
|
+
equal( div.children().length, 2, "Found children" );
|
1367
|
+
equal( div.children().children().length, 1, "Found grandchild" );
|
1368
|
+
|
1369
|
+
actual = []; expected = [];
|
1370
|
+
tmp = jQuery("<map/>").html( valueObj("<area alt='area'/>") ).each(function() {
|
1371
|
+
expected.push("AREA");
|
1372
|
+
actual.push( childNodeNames( this ) );
|
1373
|
+
});
|
1374
|
+
equal( expected.length, 1, "Expecting one parent" );
|
1375
|
+
deepEqual( actual, expected, "Found the inserted area element" );
|
1376
|
+
|
1377
|
+
equal( div.html(valueObj(5)).html(), "5", "Setting a number as html" );
|
1378
|
+
equal( div.html(valueObj(0)).html(), "0", "Setting a zero as html" );
|
1379
|
+
|
1380
|
+
div.html( valueObj(" &") );
|
1381
|
+
equal(
|
1382
|
+
div[ 0 ].innerHTML.replace( /\xA0/, " " ),
|
1383
|
+
" &",
|
1384
|
+
"Entities are passed through correctly"
|
1385
|
+
);
|
1386
|
+
|
1387
|
+
tmp = "<div>hello1</div>";
|
1388
|
+
equal( div.html(valueObj(tmp) ).html().replace( />/g, ">" ), tmp, "Escaped html" );
|
1389
|
+
tmp = "x" + tmp;
|
1390
|
+
equal( div.html(valueObj( tmp )).html().replace( />/g, ">" ), tmp, "Escaped html, leading x" );
|
1391
|
+
tmp = " " + tmp.slice( 1 );
|
1392
|
+
equal( div.html(valueObj( tmp )).html().replace( />/g, ">" ), tmp, "Escaped html, leading space" );
|
1393
|
+
|
1394
|
+
actual = []; expected = []; tmp = {};
|
1395
|
+
jQuery("#nonnodes").contents().html( valueObj("<b>bold</b>") ).each(function() {
|
1396
|
+
var html = jQuery( this ).html();
|
1397
|
+
tmp[ this.nodeType ] = true;
|
1398
|
+
expected.push( this.nodeType === 1 ? "<b>bold</b>" : undefined );
|
1399
|
+
actual.push( html ? html.toLowerCase() : html );
|
1400
|
+
});
|
1401
|
+
deepEqual( actual, expected, "Set containing element, text node, comment" );
|
1402
|
+
ok( tmp[ 1 ], "element" );
|
1403
|
+
ok( tmp[ 3 ], "text node" );
|
1404
|
+
ok( tmp[ 8 ], "comment" );
|
1405
|
+
|
1406
|
+
actual = []; expected = [];
|
1407
|
+
fixture.children("div").html( valueObj("<b>test</b>") ).each(function() {
|
1408
|
+
expected.push("B");
|
1409
|
+
actual.push( childNodeNames( this ) );
|
1410
|
+
});
|
1411
|
+
equal( expected.length, 7, "Expecting many parents" );
|
1412
|
+
deepEqual( actual, expected, "Correct childNodes after setting HTML" );
|
1413
|
+
|
1414
|
+
actual = []; expected = [];
|
1415
|
+
fixture.html( valueObj("<style>.foobar{color:green;}</style>") ).each(function() {
|
1416
|
+
expected.push("STYLE");
|
1417
|
+
actual.push( childNodeNames( this ) );
|
1418
|
+
});
|
1419
|
+
equal( expected.length, 1, "Expecting one parent" );
|
1420
|
+
deepEqual( actual, expected, "Found the inserted style element" );
|
1421
|
+
|
1422
|
+
fixture.html( valueObj("<select/>") );
|
1423
|
+
jQuery("#qunit-fixture select").html( valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>") );
|
1424
|
+
equal( jQuery("#qunit-fixture select").val(), "O2", "Selected option correct" );
|
1425
|
+
|
1426
|
+
tmp = fixture.html(
|
1427
|
+
valueObj([
|
1428
|
+
"<script type='something/else'>ok( false, 'evaluated: non-script' );</script>",
|
1429
|
+
"<script type='text/javascript'>ok( true, 'evaluated: text/javascript' );</script>",
|
1430
|
+
"<script type='text/ecmascript'>ok( true, 'evaluated: text/ecmascript' );</script>",
|
1431
|
+
"<script>ok( true, 'evaluated: no type' );</script>",
|
1432
|
+
"<div>",
|
1433
|
+
"<script type='something/else'>ok( false, 'evaluated: inner non-script' );</script>",
|
1434
|
+
"<script type='text/javascript'>ok( true, 'evaluated: inner text/javascript' );</script>",
|
1435
|
+
"<script type='text/ecmascript'>ok( true, 'evaluated: inner text/ecmascript' );</script>",
|
1436
|
+
"<script>ok( true, 'evaluated: inner no type' );</script>",
|
1437
|
+
"</div>"
|
1438
|
+
].join(""))
|
1439
|
+
).find("script");
|
1440
|
+
equal( tmp.length, 8, "All script tags remain." );
|
1441
|
+
equal( tmp[ 0 ].type, "something/else", "Non-evaluated type." );
|
1442
|
+
equal( tmp[ 1 ].type, "text/javascript", "Evaluated type." );
|
1443
|
+
|
1444
|
+
fixture.html( valueObj("<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>") );
|
1445
|
+
fixture.html( valueObj("<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>") );
|
1446
|
+
fixture.html( valueObj("<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>") );
|
1447
|
+
fixture.html( valueObj("foo <form><script type='text/javascript'>ok( true, 'Injection of identical script (#975)' );</script></form>") );
|
1448
|
+
|
1449
|
+
jQuery.scriptorder = 0;
|
1450
|
+
fixture.html( valueObj([
|
1451
|
+
"<script>",
|
1452
|
+
"equal( jQuery('#scriptorder').length, 1,'Execute after html' );",
|
1453
|
+
"equal( jQuery.scriptorder++, 0, 'Script is executed in order' );",
|
1454
|
+
"</script>",
|
1455
|
+
"<span id='scriptorder'><script>equal( jQuery.scriptorder++, 1, 'Script (nested) is executed in order');</script></span>",
|
1456
|
+
"<script>equal( jQuery.scriptorder++, 2, 'Script (unnested) is executed in order' );</script>"
|
1457
|
+
].join("")) );
|
1458
|
+
|
1459
|
+
QUnit.reset();
|
1460
|
+
fixture.html( valueObj( fixture.text() ) );
|
1461
|
+
ok( /^[^<]*[^<\s][^<]*$/.test( fixture.html() ), "Replace html with text" );
|
1462
|
+
}
|
1463
|
+
|
1464
|
+
test( "html(String)", function() {
|
1465
|
+
testHtml( manipulationBareObj );
|
1466
|
+
});
|
1467
|
+
|
1468
|
+
test( "html(Function)", function() {
|
1469
|
+
testHtml( manipulationFunctionReturningObj );
|
1470
|
+
});
|
1471
|
+
|
1472
|
+
test( "html(Function) with incoming value", function() {
|
1473
|
+
|
1474
|
+
expect( 18 );
|
1475
|
+
|
1476
|
+
var els, actualhtml, pass, j, $div, $div2, insert;
|
1477
|
+
|
1478
|
+
els = jQuery("#foo > p");
|
1479
|
+
actualhtml = els.map(function() {
|
1480
|
+
return jQuery( this ).html();
|
1481
|
+
});
|
1482
|
+
|
1483
|
+
els.html(function( i, val ) {
|
1484
|
+
equal( val, actualhtml[ i ], "Make sure the incoming value is correct." );
|
1485
|
+
return "<b>test</b>";
|
1486
|
+
});
|
1487
|
+
|
1488
|
+
pass = true;
|
1489
|
+
els.each(function() {
|
1490
|
+
if ( this.childNodes.length !== 1 ) {
|
1491
|
+
pass = false;
|
1492
|
+
}
|
1493
|
+
});
|
1494
|
+
ok( pass, "Set HTML" );
|
1495
|
+
|
1496
|
+
QUnit.reset();
|
1497
|
+
// using contents will get comments regular, text, and comment nodes
|
1498
|
+
j = jQuery("#nonnodes").contents();
|
1499
|
+
actualhtml = j.map(function() {
|
1500
|
+
return jQuery( this ).html();
|
1501
|
+
});
|
1502
|
+
|
1503
|
+
j.html(function( i, val ) {
|
1504
|
+
equal( val, actualhtml[ i ], "Make sure the incoming value is correct." );
|
1505
|
+
return "<b>bold</b>";
|
1506
|
+
});
|
1507
|
+
|
1508
|
+
// Handle the case where no comment is in the document
|
1509
|
+
if ( j.length === 2 ) {
|
1510
|
+
equal( null, null, "Make sure the incoming value is correct." );
|
1511
|
+
}
|
1512
|
+
|
1513
|
+
equal( j.html().replace( / xmlns="[^"]+"/g, "" ).toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
|
1514
|
+
|
1515
|
+
$div = jQuery("<div />");
|
1516
|
+
|
1517
|
+
equal( $div.html(function( i, val ) {
|
1518
|
+
equal( val, "", "Make sure the incoming value is correct." );
|
1519
|
+
return 5;
|
1520
|
+
}).html(), "5", "Setting a number as html" );
|
1521
|
+
|
1522
|
+
equal( $div.html(function( i, val ) {
|
1523
|
+
equal( val, "5", "Make sure the incoming value is correct." );
|
1524
|
+
return 0;
|
1525
|
+
}).html(), "0", "Setting a zero as html" );
|
1526
|
+
|
1527
|
+
$div2 = jQuery("<div/>");
|
1528
|
+
insert = "<div>hello1</div>";
|
1529
|
+
equal( $div2.html(function( i, val ) {
|
1530
|
+
equal( val, "", "Make sure the incoming value is correct." );
|
1531
|
+
return insert;
|
1532
|
+
}).html().replace(/>/g, ">"), insert, "Verify escaped insertion." );
|
1533
|
+
|
1534
|
+
equal( $div2.html(function( i, val ) {
|
1535
|
+
equal( val.replace(/>/g, ">"), insert, "Make sure the incoming value is correct." );
|
1536
|
+
return "x" + insert;
|
1537
|
+
}).html().replace( />/g, ">" ), "x" + insert, "Verify escaped insertion." );
|
1538
|
+
|
1539
|
+
equal( $div2.html(function( i, val ) {
|
1540
|
+
equal( val.replace( />/g, ">" ), "x" + insert, "Make sure the incoming value is correct." );
|
1541
|
+
return " " + insert;
|
1542
|
+
}).html().replace( />/g, ">" ), " " + insert, "Verify escaped insertion." );
|
1543
|
+
});
|
1544
|
+
|
1545
|
+
test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function() {
|
1546
|
+
|
1547
|
+
expect( 2 );
|
1548
|
+
|
1549
|
+
var $content = jQuery("<div><b><i>text</i></b></div>").appendTo("#qunit-fixture"),
|
1550
|
+
expected = /^<b><i>text<\/i><\/b>$/i;
|
1551
|
+
|
1552
|
+
// Attach jQuery and Sizzle data (the latter with a non-qSA nth-child)
|
1553
|
+
try {
|
1554
|
+
$content.find(":nth-child(1):lt(4)").data( "test", true );
|
1555
|
+
|
1556
|
+
// But don't break on a non-Sizzle build
|
1557
|
+
} catch( e ) {
|
1558
|
+
$content.find("*").data( "test", true );
|
1559
|
+
}
|
1560
|
+
|
1561
|
+
ok( expected.test( $content.clone( false )[ 0 ].innerHTML ), "clone()" );
|
1562
|
+
ok( expected.test( $content.html() ), "html()" );
|
1563
|
+
});
|
1564
|
+
|
1565
|
+
function testRemove( method ) {
|
1566
|
+
var markup, div,
|
1567
|
+
first = jQuery("#ap").children().first();
|
1568
|
+
|
1569
|
+
first.data("foo", "bar");
|
1570
|
+
|
1571
|
+
jQuery("#ap").children()[ method ]();
|
1572
|
+
ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
|
1573
|
+
equal( jQuery("#ap").children().length, 0, "Check remove" );
|
1574
|
+
|
1575
|
+
equal( first.data("foo"), method === "remove" ? null : "bar", "first data" );
|
1576
|
+
|
1577
|
+
QUnit.reset();
|
1578
|
+
jQuery("#ap").children()[ method ]("a");
|
1579
|
+
ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
|
1580
|
+
equal( jQuery("#ap").children().length, 1, "Check filtered remove" );
|
1581
|
+
|
1582
|
+
jQuery("#ap").children()[ method ]("a, code");
|
1583
|
+
equal( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
|
1584
|
+
|
1585
|
+
// Positional and relative selectors
|
1586
|
+
markup = "<div><span>1</span><span>2</span><span>3</span><span>4</span></div>";
|
1587
|
+
div = jQuery( markup );
|
1588
|
+
div.children().remove("span:nth-child(2n)");
|
1589
|
+
equal( div.text(), "13", "relative selector in " + method );
|
1590
|
+
div = jQuery( markup );
|
1591
|
+
div.children().remove("span:first");
|
1592
|
+
equal( div.text(), "234", "positional selector in " + method );
|
1593
|
+
div = jQuery( markup );
|
1594
|
+
div.children().remove("span:last");
|
1595
|
+
equal( div.text(), "123", "positional selector in " + method );
|
1596
|
+
|
1597
|
+
// using contents will get comments regular, text, and comment nodes
|
1598
|
+
// Handle the case where no comment is in the document
|
1599
|
+
ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works" );
|
1600
|
+
jQuery("#nonnodes").contents()[ method ]();
|
1601
|
+
equal( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
|
1602
|
+
|
1603
|
+
// manually clean up detached elements
|
1604
|
+
if (method === "detach") {
|
1605
|
+
first.remove();
|
1606
|
+
}
|
1607
|
+
}
|
1608
|
+
|
1609
|
+
test( "remove()", 11, function() {
|
1610
|
+
testRemove("remove");
|
1611
|
+
});
|
1612
|
+
|
1613
|
+
test( "remove() event cleaning ", 1, function() {
|
1614
|
+
var count, first, cleanUp;
|
1615
|
+
|
1616
|
+
count = 0;
|
1617
|
+
first = jQuery("#ap").children().first();
|
1618
|
+
cleanUp = first.on( "click", function() {
|
1619
|
+
count++;
|
1620
|
+
}).remove().appendTo("#qunit-fixture").trigger("click");
|
1621
|
+
|
1622
|
+
strictEqual( 0, count, "Event handler has been removed" );
|
1623
|
+
|
1624
|
+
// Clean up detached data
|
1625
|
+
cleanUp.remove();
|
1626
|
+
});
|
1627
|
+
|
1628
|
+
test( "remove() in document order #13779", 1, function() {
|
1629
|
+
var last,
|
1630
|
+
cleanData = jQuery.cleanData;
|
1631
|
+
|
1632
|
+
jQuery.cleanData = function( nodes ) {
|
1633
|
+
last = jQuery.text( nodes[0] );
|
1634
|
+
cleanData.call( this, nodes );
|
1635
|
+
};
|
1636
|
+
|
1637
|
+
jQuery("#qunit-fixture").append(
|
1638
|
+
jQuery.parseHTML(
|
1639
|
+
"<div class='removal-fixture'>1</div>" +
|
1640
|
+
"<div class='removal-fixture'>2</div>" +
|
1641
|
+
"<div class='removal-fixture'>3</div>"
|
1642
|
+
)
|
1643
|
+
);
|
1644
|
+
|
1645
|
+
jQuery(".removal-fixture").remove();
|
1646
|
+
|
1647
|
+
equal( last, 3, "The removal fixtures were removed in document order" );
|
1648
|
+
|
1649
|
+
jQuery.cleanData = cleanData;
|
1650
|
+
});
|
1651
|
+
|
1652
|
+
test( "detach()", 11, function() {
|
1653
|
+
testRemove("detach");
|
1654
|
+
});
|
1655
|
+
|
1656
|
+
test( "detach() event cleaning ", 1, function() {
|
1657
|
+
var count, first, cleanUp;
|
1658
|
+
|
1659
|
+
count = 0;
|
1660
|
+
first = jQuery("#ap").children().first();
|
1661
|
+
cleanUp = first.on( "click", function() {
|
1662
|
+
count++;
|
1663
|
+
}).detach().appendTo("#qunit-fixture").trigger("click");
|
1664
|
+
|
1665
|
+
strictEqual( 1, count, "Event handler has not been removed" );
|
1666
|
+
|
1667
|
+
// Clean up detached data
|
1668
|
+
cleanUp.remove();
|
1669
|
+
});
|
1670
|
+
|
1671
|
+
test("empty()", function() {
|
1672
|
+
|
1673
|
+
expect( 6 );
|
1674
|
+
|
1675
|
+
equal( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
|
1676
|
+
equal( jQuery("#ap").children().length, 4, "Check elements are not removed" );
|
1677
|
+
|
1678
|
+
// using contents will get comments regular, text, and comment nodes
|
1679
|
+
var j = jQuery("#nonnodes").contents();
|
1680
|
+
j.empty();
|
1681
|
+
equal( j.html(), "", "Check node,textnode,comment empty works" );
|
1682
|
+
|
1683
|
+
// Ensure oldIE empties selects (#12336)
|
1684
|
+
notEqual( $("#select1").find("option").length, 0, "Have some initial options" );
|
1685
|
+
$("#select1").empty();
|
1686
|
+
equal( $("#select1").find("option").length, 0, "No more option elements found" );
|
1687
|
+
equal( $("#select1")[0].options.length, 0, "options.length cleared as well" );
|
1688
|
+
});
|
1689
|
+
|
1690
|
+
test( "jQuery.cleanData", function() {
|
1691
|
+
|
1692
|
+
expect( 14 );
|
1693
|
+
|
1694
|
+
var type, pos, div, child;
|
1695
|
+
|
1696
|
+
type = "remove";
|
1697
|
+
|
1698
|
+
// Should trigger 4 remove event
|
1699
|
+
div = getDiv().remove();
|
1700
|
+
|
1701
|
+
// Should both do nothing
|
1702
|
+
pos = "Outer";
|
1703
|
+
div.trigger("click");
|
1704
|
+
|
1705
|
+
pos = "Inner";
|
1706
|
+
div.children().trigger("click");
|
1707
|
+
|
1708
|
+
type = "empty";
|
1709
|
+
div = getDiv();
|
1710
|
+
child = div.children();
|
1711
|
+
|
1712
|
+
// Should trigger 2 remove event
|
1713
|
+
div.empty();
|
1714
|
+
|
1715
|
+
// Should trigger 1
|
1716
|
+
pos = "Outer";
|
1717
|
+
div.trigger("click");
|
1718
|
+
|
1719
|
+
// Should do nothing
|
1720
|
+
pos = "Inner";
|
1721
|
+
child.trigger("click");
|
1722
|
+
|
1723
|
+
// Should trigger 2
|
1724
|
+
div.remove();
|
1725
|
+
|
1726
|
+
type = "html";
|
1727
|
+
|
1728
|
+
div = getDiv();
|
1729
|
+
child = div.children();
|
1730
|
+
|
1731
|
+
// Should trigger 2 remove event
|
1732
|
+
div.html("<div></div>");
|
1733
|
+
|
1734
|
+
// Should trigger 1
|
1735
|
+
pos = "Outer";
|
1736
|
+
div.trigger("click");
|
1737
|
+
|
1738
|
+
// Should do nothing
|
1739
|
+
pos = "Inner";
|
1740
|
+
child.trigger("click");
|
1741
|
+
|
1742
|
+
// Should trigger 2
|
1743
|
+
div.remove();
|
1744
|
+
|
1745
|
+
function getDiv() {
|
1746
|
+
var div = jQuery("<div class='outer'><div class='inner'></div></div>").on( "click", function() {
|
1747
|
+
ok( true, type + " " + pos + " Click event fired." );
|
1748
|
+
}).on( "focus", function() {
|
1749
|
+
ok( true, type + " " + pos + " Focus event fired." );
|
1750
|
+
}).find("div").on( "click", function() {
|
1751
|
+
ok( false, type + " " + pos + " Click event fired." );
|
1752
|
+
}).on( "focus", function() {
|
1753
|
+
ok( false, type + " " + pos + " Focus event fired." );
|
1754
|
+
}).end().appendTo("body");
|
1755
|
+
|
1756
|
+
div[ 0 ].detachEvent = div[ 0 ].removeEventListener = function( t ) {
|
1757
|
+
ok( true, type + " Outer " + t + " event unbound" );
|
1758
|
+
};
|
1759
|
+
|
1760
|
+
div[ 0 ].firstChild.detachEvent = div[ 0 ].firstChild.removeEventListener = function( t ) {
|
1761
|
+
ok( true, type + " Inner " + t + " event unbound" );
|
1762
|
+
};
|
1763
|
+
|
1764
|
+
return div;
|
1765
|
+
}
|
1766
|
+
});
|
1767
|
+
|
1768
|
+
test( "jQuery.buildFragment - no plain-text caching (Bug #6779)", function() {
|
1769
|
+
|
1770
|
+
expect( 1 );
|
1771
|
+
|
1772
|
+
// DOM manipulation fails if added text matches an Object method
|
1773
|
+
var i,
|
1774
|
+
$f = jQuery( "<div />" ).appendTo( "#qunit-fixture" ),
|
1775
|
+
bad = [ "start-", "toString", "hasOwnProperty", "append", "here&there!", "-end" ];
|
1776
|
+
|
1777
|
+
for ( i = 0; i < bad.length; i++ ) {
|
1778
|
+
try {
|
1779
|
+
$f.append( bad[ i ] );
|
1780
|
+
}
|
1781
|
+
catch( e ) {}
|
1782
|
+
}
|
1783
|
+
equal( $f.text(), bad.join(""), "Cached strings that match Object properties" );
|
1784
|
+
$f.remove();
|
1785
|
+
});
|
1786
|
+
|
1787
|
+
test( "jQuery.html - execute scripts escaped with html comment or CDATA (#9221)", function() {
|
1788
|
+
|
1789
|
+
expect( 3 );
|
1790
|
+
|
1791
|
+
jQuery([
|
1792
|
+
"<script type='text/javascript'>",
|
1793
|
+
"<!--",
|
1794
|
+
"ok( true, '<!-- handled' );",
|
1795
|
+
"//-->",
|
1796
|
+
"</script>"
|
1797
|
+
].join("\n")).appendTo("#qunit-fixture");
|
1798
|
+
jQuery([
|
1799
|
+
"<script type='text/javascript'>",
|
1800
|
+
"<![CDATA[",
|
1801
|
+
"ok( true, '<![CDATA[ handled' );",
|
1802
|
+
"//]]>",
|
1803
|
+
"</script>"
|
1804
|
+
].join("\n")).appendTo("#qunit-fixture");
|
1805
|
+
jQuery([
|
1806
|
+
"<script type='text/javascript'>",
|
1807
|
+
"<!--//--><![CDATA[//><!--",
|
1808
|
+
"ok( true, '<!--//--><![CDATA[//><!-- (Drupal case) handled' );",
|
1809
|
+
"//--><!]]>",
|
1810
|
+
"</script>"
|
1811
|
+
].join("\n")).appendTo("#qunit-fixture");
|
1812
|
+
});
|
1813
|
+
|
1814
|
+
test( "jQuery.buildFragment - plain objects are not a document #8950", function() {
|
1815
|
+
|
1816
|
+
expect( 1 );
|
1817
|
+
|
1818
|
+
try {
|
1819
|
+
jQuery( "<input type='hidden'>", {} );
|
1820
|
+
ok( true, "Does not allow attribute object to be treated like a doc object" );
|
1821
|
+
} catch ( e ) {}
|
1822
|
+
});
|
1823
|
+
|
1824
|
+
test( "jQuery.clone - no exceptions for object elements #9587", function() {
|
1825
|
+
|
1826
|
+
expect( 1 );
|
1827
|
+
|
1828
|
+
try {
|
1829
|
+
jQuery("#no-clone-exception").clone();
|
1830
|
+
ok( true, "cloned with no exceptions" );
|
1831
|
+
} catch( e ) {
|
1832
|
+
ok( false, e.message );
|
1833
|
+
}
|
1834
|
+
});
|
1835
|
+
|
1836
|
+
test( "Cloned, detached HTML5 elems (#10667,10670)", function() {
|
1837
|
+
|
1838
|
+
expect( 7 );
|
1839
|
+
|
1840
|
+
var $clone,
|
1841
|
+
$section = jQuery( "<section>" ).appendTo( "#qunit-fixture" );
|
1842
|
+
|
1843
|
+
// First clone
|
1844
|
+
$clone = $section.clone();
|
1845
|
+
|
1846
|
+
// Infer that the test is being run in IE<=8
|
1847
|
+
if ( $clone[ 0 ].outerHTML && !jQuery.support.opacity ) {
|
1848
|
+
// This branch tests cloning nodes by reading the outerHTML, used only in IE<=8
|
1849
|
+
equal( $clone[ 0 ].outerHTML, "<section></section>", "detached clone outerHTML matches '<section></section>'" );
|
1850
|
+
} else {
|
1851
|
+
// This branch tests a known behaviour in modern browsers that should never fail.
|
1852
|
+
// Included for expected test count symmetry (expecting 1)
|
1853
|
+
equal( $clone[ 0 ].nodeName, "SECTION", "detached clone nodeName matches 'SECTION' in modern browsers" );
|
1854
|
+
}
|
1855
|
+
|
1856
|
+
// Bind an event
|
1857
|
+
$section.on( "click", function() {
|
1858
|
+
ok( true, "clone fired event" );
|
1859
|
+
});
|
1860
|
+
|
1861
|
+
// Second clone (will have an event bound)
|
1862
|
+
$clone = $section.clone( true );
|
1863
|
+
|
1864
|
+
// Trigger an event from the first clone
|
1865
|
+
$clone.trigger("click");
|
1866
|
+
$clone.off("click");
|
1867
|
+
|
1868
|
+
// Add a child node with text to the original
|
1869
|
+
$section.append("<p>Hello</p>");
|
1870
|
+
|
1871
|
+
// Third clone (will have child node and text)
|
1872
|
+
$clone = $section.clone( true );
|
1873
|
+
|
1874
|
+
equal( $clone.find("p").text(), "Hello", "Assert text in child of clone" );
|
1875
|
+
|
1876
|
+
// Trigger an event from the third clone
|
1877
|
+
$clone.trigger("click");
|
1878
|
+
$clone.off("click");
|
1879
|
+
|
1880
|
+
// Add attributes to copy
|
1881
|
+
$section.attr({
|
1882
|
+
"class": "foo bar baz",
|
1883
|
+
"title": "This is a title"
|
1884
|
+
});
|
1885
|
+
|
1886
|
+
// Fourth clone (will have newly added attributes)
|
1887
|
+
$clone = $section.clone( true );
|
1888
|
+
|
1889
|
+
equal( $clone.attr("class"), $section.attr("class"), "clone and element have same class attribute" );
|
1890
|
+
equal( $clone.attr("title"), $section.attr("title"), "clone and element have same title attribute" );
|
1891
|
+
|
1892
|
+
// Remove the original
|
1893
|
+
$section.remove();
|
1894
|
+
|
1895
|
+
// Clone the clone
|
1896
|
+
$section = $clone.clone( true );
|
1897
|
+
|
1898
|
+
// Remove the clone
|
1899
|
+
$clone.remove();
|
1900
|
+
|
1901
|
+
// Trigger an event from the clone of the clone
|
1902
|
+
$section.trigger("click");
|
1903
|
+
|
1904
|
+
// Unbind any remaining events
|
1905
|
+
$section.off("click");
|
1906
|
+
$clone.off("click");
|
1907
|
+
});
|
1908
|
+
|
1909
|
+
test( "Guard against exceptions when clearing safeChildNodes", function() {
|
1910
|
+
|
1911
|
+
expect( 1 );
|
1912
|
+
|
1913
|
+
var div;
|
1914
|
+
|
1915
|
+
try {
|
1916
|
+
div = jQuery("<div/><hr/><code/><b/>");
|
1917
|
+
} catch(e) {}
|
1918
|
+
|
1919
|
+
ok( div && div.jquery, "Created nodes safely, guarded against exceptions on safeChildNodes[ -1 ]" );
|
1920
|
+
});
|
1921
|
+
|
1922
|
+
test( "Ensure oldIE creates a new set on appendTo (#8894)", function() {
|
1923
|
+
|
1924
|
+
expect( 5 );
|
1925
|
+
|
1926
|
+
strictEqual( jQuery("<div/>").clone().addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.clone" );
|
1927
|
+
strictEqual( jQuery("<div/>").find("p").end().addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.find" );
|
1928
|
+
strictEqual( jQuery("<div/>").text("test").addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.text" );
|
1929
|
+
strictEqual( jQuery("<bdi/>").clone().addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after clone html5 element" );
|
1930
|
+
strictEqual( jQuery("<p/>").appendTo("<div/>").end().length, jQuery("<p>test</p>").appendTo("<div/>").end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" );
|
1931
|
+
});
|
1932
|
+
|
1933
|
+
test( "html() - script exceptions bubble (#11743)", function() {
|
1934
|
+
|
1935
|
+
expect( 2 );
|
1936
|
+
|
1937
|
+
raises(function() {
|
1938
|
+
jQuery("#qunit-fixture").html("<script>undefined(); ok( false, 'Exception not thrown' );</script>");
|
1939
|
+
ok( false, "Exception ignored" );
|
1940
|
+
}, "Exception bubbled from inline script" );
|
1941
|
+
|
1942
|
+
if ( jQuery.ajax ) {
|
1943
|
+
raises(function() {
|
1944
|
+
jQuery("#qunit-fixture").html("<script src='data/badcall.js'></script>");
|
1945
|
+
ok( false, "Exception ignored" );
|
1946
|
+
}, "Exception thrown in remote script" );
|
1947
|
+
} else {
|
1948
|
+
ok( true, "No jQuery.ajax" );
|
1949
|
+
}
|
1950
|
+
});
|
1951
|
+
|
1952
|
+
test( "checked state is cloned with clone()", function() {
|
1953
|
+
|
1954
|
+
expect( 2 );
|
1955
|
+
|
1956
|
+
var elem = jQuery.parseHTML("<input type='checkbox' checked='checked'/>")[ 0 ];
|
1957
|
+
elem.checked = false;
|
1958
|
+
equal( jQuery(elem).clone().attr("id","clone")[ 0 ].checked, false, "Checked false state correctly cloned" );
|
1959
|
+
|
1960
|
+
elem = jQuery.parseHTML("<input type='checkbox'/>")[ 0 ];
|
1961
|
+
elem.checked = true;
|
1962
|
+
equal( jQuery(elem).clone().attr("id","clone")[ 0 ].checked, true, "Checked true state correctly cloned" );
|
1963
|
+
});
|
1964
|
+
|
1965
|
+
test( "manipulate mixed jQuery and text (#12384, #12346)", function() {
|
1966
|
+
|
1967
|
+
expect( 2 );
|
1968
|
+
|
1969
|
+
var div = jQuery("<div>a</div>").append( " ", jQuery("<span>b</span>"), " ", jQuery("<span>c</span>") ),
|
1970
|
+
nbsp = String.fromCharCode( 160 );
|
1971
|
+
|
1972
|
+
equal( div.text(), "a" + nbsp + "b" + nbsp+ "c", "Appending mixed jQuery with text nodes" );
|
1973
|
+
|
1974
|
+
div = jQuery("<div><div></div></div>")
|
1975
|
+
.find("div")
|
1976
|
+
.after( "<p>a</p>", "<p>b</p>" )
|
1977
|
+
.parent();
|
1978
|
+
equal( div.find("*").length, 3, "added 2 paragraphs after inner div" );
|
1979
|
+
});
|
1980
|
+
|
1981
|
+
testIframeWithCallback( "buildFragment works even if document[0] is iframe's window object in IE9/10 (#12266)", "manipulation/iframe-denied.html", function( test ) {
|
1982
|
+
expect( 1 );
|
1983
|
+
|
1984
|
+
ok( test.status, test.description );
|
1985
|
+
});
|
1986
|
+
|
1987
|
+
test( "script evaluation (#11795)", function() {
|
1988
|
+
|
1989
|
+
expect( 13 );
|
1990
|
+
|
1991
|
+
var scriptsIn, scriptsOut,
|
1992
|
+
fixture = jQuery("#qunit-fixture").empty(),
|
1993
|
+
objGlobal = (function() {
|
1994
|
+
return this;
|
1995
|
+
})(),
|
1996
|
+
isOk = objGlobal.ok,
|
1997
|
+
notOk = function() {
|
1998
|
+
var args = arguments;
|
1999
|
+
args[ 0 ] = !args[ 0 ];
|
2000
|
+
return isOk.apply( this, args );
|
2001
|
+
};
|
2002
|
+
|
2003
|
+
objGlobal.ok = notOk;
|
2004
|
+
scriptsIn = jQuery([
|
2005
|
+
"<script type='something/else'>ok( false, 'evaluated: non-script' );</script>",
|
2006
|
+
"<script type='text/javascript'>ok( true, 'evaluated: text/javascript' );</script>",
|
2007
|
+
"<script type='text/ecmascript'>ok( true, 'evaluated: text/ecmascript' );</script>",
|
2008
|
+
"<script>ok( true, 'evaluated: no type' );</script>",
|
2009
|
+
"<div>",
|
2010
|
+
"<script type='something/else'>ok( false, 'evaluated: inner non-script' );</script>",
|
2011
|
+
"<script type='text/javascript'>ok( true, 'evaluated: inner text/javascript' );</script>",
|
2012
|
+
"<script type='text/ecmascript'>ok( true, 'evaluated: inner text/ecmascript' );</script>",
|
2013
|
+
"<script>ok( true, 'evaluated: inner no type' );</script>",
|
2014
|
+
"</div>"
|
2015
|
+
].join(""));
|
2016
|
+
scriptsIn.appendTo( jQuery("<div class='detached'/>") );
|
2017
|
+
objGlobal.ok = isOk;
|
2018
|
+
|
2019
|
+
scriptsOut = fixture.append( scriptsIn ).find("script");
|
2020
|
+
equal( scriptsOut[ 0 ].type, "something/else", "Non-evaluated type." );
|
2021
|
+
equal( scriptsOut[ 1 ].type, "text/javascript", "Evaluated type." );
|
2022
|
+
deepEqual( scriptsOut.get(), fixture.find("script").get(), "All script tags remain." );
|
2023
|
+
|
2024
|
+
objGlobal.ok = notOk;
|
2025
|
+
scriptsOut = scriptsOut.add( scriptsOut.clone() ).appendTo( fixture.find("div") );
|
2026
|
+
deepEqual( fixture.find("div script").get(), scriptsOut.get(), "Scripts cloned without reevaluation" );
|
2027
|
+
fixture.append( scriptsOut.detach() );
|
2028
|
+
deepEqual( fixture.children("script").get(), scriptsOut.get(), "Scripts detached without reevaluation" );
|
2029
|
+
objGlobal.ok = isOk;
|
2030
|
+
|
2031
|
+
if ( jQuery.ajax ) {
|
2032
|
+
Globals.register("testBar");
|
2033
|
+
jQuery("#qunit-fixture").append( "<script src='" + url("data/test.js") + "'/>" );
|
2034
|
+
strictEqual( window["testBar"], "bar", "Global script evaluation" );
|
2035
|
+
} else {
|
2036
|
+
ok( true, "No jQuery.ajax" );
|
2037
|
+
ok( true, "No jQuery.ajax" );
|
2038
|
+
}
|
2039
|
+
});
|
2040
|
+
|
2041
|
+
test( "jQuery._evalUrl (#12838)", function() {
|
2042
|
+
|
2043
|
+
expect( 5 );
|
2044
|
+
|
2045
|
+
var message, expectedArgument,
|
2046
|
+
ajax = jQuery.ajax,
|
2047
|
+
evalUrl = jQuery._evalUrl;
|
2048
|
+
|
2049
|
+
message = "jQuery.ajax implementation";
|
2050
|
+
expectedArgument = 1;
|
2051
|
+
jQuery.ajax = function( input ) {
|
2052
|
+
equal( ( input.url || input ).slice( -1 ), expectedArgument, message );
|
2053
|
+
expectedArgument++;
|
2054
|
+
};
|
2055
|
+
jQuery("#qunit-fixture").append("<script src='1'/><script src='2'/>");
|
2056
|
+
equal( expectedArgument, 3, "synchronous execution" );
|
2057
|
+
|
2058
|
+
message = "custom implementation";
|
2059
|
+
expectedArgument = 3;
|
2060
|
+
jQuery._evalUrl = jQuery.ajax;
|
2061
|
+
jQuery.ajax = function( options ) {
|
2062
|
+
strictEqual( options, {}, "Unexpected call to jQuery.ajax" );
|
2063
|
+
};
|
2064
|
+
jQuery("#qunit-fixture").append("<script src='3'/><script src='4'/>");
|
2065
|
+
|
2066
|
+
jQuery.ajax = ajax;
|
2067
|
+
jQuery._evalUrl = evalUrl;
|
2068
|
+
});
|
2069
|
+
|
2070
|
+
test( "insertAfter, insertBefore, etc do not work when destination is original element. Element is removed (#4087)", function() {
|
2071
|
+
|
2072
|
+
expect( 10 );
|
2073
|
+
|
2074
|
+
var elems;
|
2075
|
+
|
2076
|
+
jQuery.each([
|
2077
|
+
"appendTo",
|
2078
|
+
"prependTo",
|
2079
|
+
"insertBefore",
|
2080
|
+
"insertAfter",
|
2081
|
+
"replaceAll"
|
2082
|
+
], function( index, name ) {
|
2083
|
+
elems = jQuery( [
|
2084
|
+
"<ul id='test4087-complex'><li class='test4087'><div>c1</div>h1</li><li><div>c2</div>h2</li></ul>",
|
2085
|
+
"<div id='test4087-simple'><div class='test4087-1'>1<div class='test4087-2'>2</div><div class='test4087-3'>3</div></div></div>",
|
2086
|
+
"<div id='test4087-multiple'><div class='test4087-multiple'>1</div><div class='test4087-multiple'>2</div></div>"
|
2087
|
+
].join("") ).appendTo( "#qunit-fixture" );
|
2088
|
+
|
2089
|
+
// complex case based on http://jsfiddle.net/pbramos/gZ7vB/
|
2090
|
+
jQuery("#test4087-complex div")[ name ]("#test4087-complex li:last-child div:last-child");
|
2091
|
+
equal( jQuery("#test4087-complex li:last-child div").length, name === "replaceAll" ? 1 : 2, name +" a node to itself, complex case." );
|
2092
|
+
|
2093
|
+
// simple case
|
2094
|
+
jQuery( ".test4087-1" )[ name ](".test4087-1");
|
2095
|
+
equal( jQuery(".test4087-1").length, 1, name +" a node to itself, simple case." );
|
2096
|
+
|
2097
|
+
// clean for next test
|
2098
|
+
jQuery("#test4087-complex").remove();
|
2099
|
+
jQuery("#test4087-simple").remove();
|
2100
|
+
jQuery("#test4087-multiple").remove();
|
2101
|
+
});
|
2102
|
+
});
|
2103
|
+
|
2104
|
+
test( "Index for function argument should be received (#13094)", 2, function() {
|
2105
|
+
var i = 0;
|
2106
|
+
|
2107
|
+
jQuery("<div/><div/>").before(function( index ) {
|
2108
|
+
equal( index, i++, "Index should be correct" );
|
2109
|
+
});
|
2110
|
+
|
2111
|
+
});
|
2112
|
+
|
2113
|
+
test( "Make sure jQuery.fn.remove can work on elements in documentFragment", 1, function() {
|
2114
|
+
var fragment = document.createDocumentFragment(),
|
2115
|
+
div = fragment.appendChild( document.createElement("div") );
|
2116
|
+
|
2117
|
+
jQuery( div ).remove();
|
2118
|
+
|
2119
|
+
equal( fragment.childNodes.length, 0, "div element was removed from documentFragment" );
|
2120
|
+
});
|