});
var testWrap = function(val) {
- expect(15);
+ expect(18);
var defaultText = 'Try them out:'
var result = jQuery('#first').wrap(val( '<div class="red"><span></span></div>' )).text();
equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
equals( j[0].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
equals( j.length, 1, "There should only be one element (no cloning)." );
equals( j[0].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
+
+ // Wrap an element with a jQuery set
+ j = jQuery("<span/>").wrap(jQuery("<div></div>"));
+ equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
+
+ // Wrap an element with a jQuery set and event
+ result = jQuery("<div></div>").click(function(){
+ ok(true, "Event triggered.");
+ });
+
+ j = jQuery("<span/>").wrap(result);
+ equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
+
+ j.parent().trigger("click");
}
test("wrap(String|Element)", function() {
// TODO: Figure out why each(wrapAll) is not equivalent to wrapAll
// test("wrapAll(Function)", function() {
-// testWrapAll(functionReturningObj);
+// testWrapAll(functionReturningObj);
// })
var testWrapInner = function(val) {
// TODO: wrapInner uses wrapAll -- get wrapAll working with Function
// test("wrapInner(Function)", function() {
-// testWrapInner(functionReturningObj)
+// testWrapInner(functionReturningObj)
// })
var testUnwrap = function() {
var abcd = jQuery('#unwrap1 > span, #unwrap2 > span').get(),
abcdef = jQuery('#unwrap span').get();
- equals( jQuery('#unwrap1 span, #unwrap2 span:first').unwrap().length, 3, 'make #unwrap1 and #unwrap2 go away' );
+ equals( jQuery('#unwrap1 span').add('#unwrap2 span:first').unwrap().length, 3, 'make #unwrap1 and #unwrap2 go away' );
same( jQuery('#unwrap > span').get(), abcd, 'all four spans should still exist' );
same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap3 > span').get(), 'make all b in #unwrap3 go away' );
});
var testAppend = function(valueObj) {
- expect(21);
+ expect(22);
var defaultText = 'Try them out:'
var result = jQuery('#first').append(valueObj('<b>buga</b>'));
equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
+ equals( "Two nodes", jQuery('<div />').append("Two", " nodes").text(), "Appending two text nodes (#4011)" );
+
// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();
var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
}
test("append(String|Element|Array<Element>|jQuery)", function() {
- testAppend(bareObj);
+ testAppend(bareObj);
});
test("append(Function)", function() {
});
var testReplaceWith = function(val) {
- expect(12);
+ expect(14);
jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
ok( jQuery("#replace")[0], 'Replace element with string' );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
var set = jQuery("<div/>").replaceWith(val("<span>test</span>"));
equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
equals( set.length, 1, "Replace the disconnected node." );
+
+ var $div = jQuery("<div class='replacewith'></div>").appendTo("body");
+ $div.replaceWith("<div class='replacewith'></div><script>" +
+ "equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');" +
+ "</script>");
+ equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');
+ jQuery('.replacewith').remove();
}
test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
});
test("clone()", function() {
- expect(28);
+ expect(30);
equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
var clone = jQuery('#yahoo').clone();
equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
div = div.clone(true);
equals( div.length, 1, "One element cloned" );
equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
+
+ div = jQuery("<div/>").data({ a: true, b: true });
+ div = div.clone(true);
+ equals( div.data("a"), true, "Data cloned." );
+ equals( div.data("b"), true, "Data cloned." );
});
if (!isLocal) {
});
var testVal = function(valueObj) {
- expect(5);
+ expect(6);
jQuery("#text1").val(valueObj( 'test' ));
equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
jQuery("#select1").val(valueObj( 2 ));
equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
+ jQuery("#select1").append("<option value='4'>four</option>");
+ jQuery("#select1").val(valueObj( 4 ));
+ equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
+
// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();
j.val(valueObj( "asdf" ));
})
var testHtml = function(valueObj) {
- expect(20);
-
- window.debug = true;
+ expect(22);
jQuery.scriptorder = 0;
}
ok( pass, "Set HTML" );
- delete window.debug;
-
reset();
// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();
equals( $div2.html("x" + insert).html(), "x" + insert, "Verify escaped insertion." );
equals( $div2.html(" " + insert).html(), " " + insert, "Verify escaped insertion." );
+ var map = jQuery("<map/>").html(valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>"));
+
+ equals( map[0].childNodes.length, 1, "The area was inserted." );
+ equals( map[0].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
reset();
test("html(Function)", function() {
testHtml(functionReturningObj);
-})
+});
var testText = function(valueObj) {
expect(4);
- equals( jQuery("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML.replace(/>/g, ">"), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
+ var val = valueObj("<div><b>Hello</b> cruel world!</div>");
+ equals( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, ">"), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();
- j.text("hi!");
+ j.text(valueObj("hi!"));
equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );