2015-08-16 06:59:58 +00:00
|
|
|
( function() {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2022-07-12 15:12:27 +00:00
|
|
|
if ( !includesModule( "wrap" ) ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.module( "wrap", {
|
2019-02-18 18:02:38 +00:00
|
|
|
afterEach: moduleTeardown
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// See test/unit/manipulation.js for explanation about these 2 functions
|
2017-07-31 19:16:23 +00:00
|
|
|
function manipulationBareObj( value ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
return value;
|
2013-04-09 15:45:09 +00:00
|
|
|
}
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
function manipulationFunctionReturningObj( value ) {
|
|
|
|
return function() {
|
2013-04-08 22:00:02 +00:00
|
|
|
return value;
|
2013-04-09 15:45:09 +00:00
|
|
|
};
|
|
|
|
}
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
function testWrap( val, assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2020-05-18 16:43:01 +00:00
|
|
|
assert.expect( 18 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
var defaultText, result, j, i, cacheLength;
|
|
|
|
|
|
|
|
defaultText = "Try them out:";
|
2015-08-16 06:59:58 +00:00
|
|
|
result = jQuery( "#first" ).wrap( val( "<div class='red'><span></span></div>" ) ).text();
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
defaultText, result, "Check for wrapping of on-the-fly html"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
|
|
);
|
|
|
|
|
|
|
|
result = jQuery( "#first" ).wrap( val( document.getElementById( "empty" ) ) ).parent();
|
|
|
|
assert.ok(
|
|
|
|
result.is( "ol" ), "Check for element wrapping"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
result.text(), defaultText, "Check for element wrapping"
|
|
|
|
);
|
|
|
|
|
|
|
|
jQuery( "#check1" ).on( "click", function() {
|
2013-04-08 22:00:02 +00:00
|
|
|
var checkbox = this;
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.ok(
|
2022-01-12 22:23:10 +00:00
|
|
|
checkbox.checked, "Checkbox's state is erased after wrap() action, see trac-769"
|
2015-08-16 06:59:58 +00:00
|
|
|
);
|
|
|
|
jQuery( checkbox ).wrap( val( "<div id='c1' style='display:none;'></div>" ) );
|
|
|
|
assert.ok(
|
2022-01-12 22:23:10 +00:00
|
|
|
checkbox.checked, "Checkbox's state is erased after wrap() action, see trac-769"
|
2015-08-16 06:59:58 +00:00
|
|
|
);
|
|
|
|
} ).prop( "checked", false )[ 0 ].click();
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// using contents will get comments regular, text, and comment nodes
|
2015-08-16 06:59:58 +00:00
|
|
|
j = jQuery( "#nonnodes" ).contents();
|
|
|
|
j.wrap( val( "<i></i>" ) );
|
|
|
|
|
|
|
|
assert.equal(
|
2016-03-23 13:16:38 +00:00
|
|
|
jQuery( "#nonnodes > i" ).length, 3,
|
2015-08-16 06:59:58 +00:00
|
|
|
"Check node,textnode,comment wraps ok"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#nonnodes > i" ).text(), j.text(),
|
|
|
|
"Check node,textnode,comment wraps doesn't hurt text"
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2020-03-16 20:49:29 +00:00
|
|
|
j = jQuery( "<label></label>" ).wrap( val( "<li></li>" ) );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal(
|
|
|
|
j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped"
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// Wrap an element containing a text node
|
2020-03-16 20:49:29 +00:00
|
|
|
j = jQuery( "<span></span>" ).wrap( "<div>test</div>" );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element."
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// Try to wrap an element with multiple elements (should fail)
|
2015-08-16 06:59:58 +00:00
|
|
|
j = jQuery( "<div><span></span></div>" ).children().wrap( "<p></p><div></div>" );
|
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].parentNode.parentNode.childNodes.length, 1,
|
|
|
|
"There should only be one element wrapping."
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
j.length, 1, "There should only be one element (no cloning)."
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph."
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// Wrap an element with a jQuery set
|
2020-03-16 20:49:29 +00:00
|
|
|
j = jQuery( "<span></span>" ).wrap( jQuery( "<div></div>" ) );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works."
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// Wrap an element with a jQuery set and event
|
2015-08-16 06:59:58 +00:00
|
|
|
result = jQuery( "<div></div>" ).on( "click", function() {
|
|
|
|
assert.ok(
|
|
|
|
true, "Event triggered."
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
// Remove handlers on detached elements
|
|
|
|
result.off();
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery( this ).off();
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2020-03-16 20:49:29 +00:00
|
|
|
j = jQuery( "<span></span>" ).wrap( result );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal(
|
|
|
|
j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works."
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
j.parent().trigger( "click" );
|
2013-04-09 15:45:09 +00:00
|
|
|
}
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrap(String|Element)", function( assert ) {
|
|
|
|
testWrap( manipulationBareObj, assert );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrap(Function)", function( assert ) {
|
|
|
|
testWrap( manipulationFunctionReturningObj, assert );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2022-01-12 22:23:10 +00:00
|
|
|
QUnit.test( "wrap(Function) with index (trac-10177)", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
var expectedIndex = 0,
|
2015-08-16 06:59:58 +00:00
|
|
|
targets = jQuery( "#qunit-fixture p" );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( targets.length );
|
2015-08-16 06:59:58 +00:00
|
|
|
targets.wrap( function( i ) {
|
|
|
|
assert.equal(
|
|
|
|
i, expectedIndex,
|
|
|
|
"Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")"
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
expectedIndex++;
|
|
|
|
|
|
|
|
return "<div id='wrap_index_'" + i + "'></div>";
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2022-01-12 22:23:10 +00:00
|
|
|
QUnit.test( "wrap(String) consecutive elements (trac-10177)", function( assert ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
var targets = jQuery( "#qunit-fixture p" );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( targets.length * 2 );
|
2015-08-16 06:59:58 +00:00
|
|
|
targets.wrap( "<div class='wrapper'></div>" );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
targets.each( function() {
|
|
|
|
var $this = jQuery( this );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.ok(
|
|
|
|
$this.parent().is( ".wrapper" ), "Check each elements parent is correct (.wrapper)"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
$this.siblings().length, 0, "Each element should be wrapped individually"
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapAll(String)", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 5 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
var prev, p, result;
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
prev = jQuery( "#firstp" )[ 0 ].previousSibling;
|
|
|
|
p = jQuery( "#firstp,#first" )[ 0 ].parentNode;
|
|
|
|
result = jQuery( "#firstp,#first" ).wrapAll( "<div class='red'><div class='tmp'></div></div>" );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
result.parent().length, 1, "Check for wrapping of on-the-fly html"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).parent().parent()[ 0 ].parentNode, p, "Correct Parent"
|
|
|
|
);
|
|
|
|
|
|
|
|
} );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapAll(Function)", function( assert ) {
|
|
|
|
assert.expect( 5 );
|
2015-07-29 15:10:04 +00:00
|
|
|
|
2014-12-08 07:32:57 +00:00
|
|
|
var prev = jQuery( "#firstp" )[ 0 ].previousSibling,
|
|
|
|
p = jQuery( "#firstp,#first" )[ 0 ].parentNode,
|
2015-08-16 06:59:58 +00:00
|
|
|
result = jQuery( "#firstp,#first" ).wrapAll( function() {
|
2014-12-08 07:32:57 +00:00
|
|
|
return "<div class='red'><div class='tmp'></div></div>";
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
result.parent().length, 1, "Check for wrapping of on-the-fly html"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).parent().parent().parent().is( p ), "Correct Parent"
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
|
|
|
|
);
|
|
|
|
} );
|
2014-12-08 07:32:57 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapAll(Function) check execution characteristics", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2015-07-29 15:10:04 +00:00
|
|
|
|
2014-12-08 07:32:57 +00:00
|
|
|
var i = 0;
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery( "non-existent" ).wrapAll( function() {
|
2014-12-08 07:32:57 +00:00
|
|
|
i++;
|
|
|
|
return "";
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
!i, "should not execute function argument if target element does not exist"
|
|
|
|
);
|
|
|
|
|
|
|
|
jQuery( "#firstp" ).wrapAll( function( index ) {
|
|
|
|
assert.strictEqual(
|
|
|
|
this, jQuery( "#firstp" )[ 0 ], "context must be the first found element"
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
index, undefined, "index argument should not be included in function execution"
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
2014-12-08 07:32:57 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapAll(Element)", function( assert ) {
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 3 );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
|
|
|
var prev, p;
|
2015-08-16 06:59:58 +00:00
|
|
|
prev = jQuery( "#firstp" )[ 0 ].previousSibling;
|
|
|
|
p = jQuery( "#first" )[ 0 ].parentNode;
|
|
|
|
jQuery( "#firstp,#first" ).wrapAll( document.getElementById( "empty" ) );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).parent()[ 0 ], jQuery( "#firstp" ).parent()[ 0 ], "Same Parent"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).parent()[ 0 ].parentNode, p, "Correct Parent"
|
|
|
|
);
|
|
|
|
} );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapInner(String)", function( assert ) {
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 6 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2013-12-11 16:34:05 +00:00
|
|
|
var num;
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
num = jQuery( "#first" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( "<div class='red'><div id='tmp'></div></div>" );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
|
|
|
|
|
|
|
num = jQuery( "#first" ).html( "foo<div>test</div><div>test2</div>" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( "<div class='red'><div id='tmp'></div></div>" );
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapInner(Element)", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 5 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2013-04-09 15:45:09 +00:00
|
|
|
var num,
|
2020-03-16 20:49:29 +00:00
|
|
|
div = jQuery( "<div></div>" );
|
2015-08-16 06:59:58 +00:00
|
|
|
|
|
|
|
num = jQuery( "#first" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( document.getElementById( "empty" ) );
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( "#empty" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
2013-12-11 16:34:05 +00:00
|
|
|
|
|
|
|
div.wrapInner( "<span></span>" );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal(
|
|
|
|
div.children().length, 1, "The contents were wrapped."
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted."
|
|
|
|
);
|
|
|
|
} );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapInner(Function) returns String", function( assert ) {
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 6 );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
|
|
|
var num,
|
|
|
|
val = manipulationFunctionReturningObj;
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
num = jQuery( "#first" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( val( "<div class='red'><div id='tmp'></div></div>" ) );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
|
|
|
|
|
|
|
num = jQuery( "#first" ).html( "foo<div>test</div><div>test2</div>" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( val( "<div class='red'><div id='tmp'></div></div>" ) );
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
|
|
|
} );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "wrapInner(Function) returns Element", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 5 );
|
2013-12-11 16:34:05 +00:00
|
|
|
|
|
|
|
var num,
|
|
|
|
val = manipulationFunctionReturningObj,
|
2020-03-16 20:49:29 +00:00
|
|
|
div = jQuery( "<div></div>" );
|
2015-08-16 06:59:58 +00:00
|
|
|
|
|
|
|
num = jQuery( "#first" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( val( document.getElementById( "empty" ) ) );
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( "#empty" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#first" ).children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
|
|
|
|
|
|
|
div.wrapInner( val( "<span></span>" ) );
|
|
|
|
assert.equal(
|
|
|
|
div.children().length, 1, "The contents were wrapped."
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted."
|
|
|
|
);
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "unwrap()", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 9 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery( "body" ).append(
|
|
|
|
" <div id='unwrap' style='display: none;'> <div id='unwrap1'>" +
|
|
|
|
" <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'>" +
|
|
|
|
" <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> <div id='unwrap3'>" +
|
|
|
|
" <b><span class='unwrap unwrap3'>e</span></b>" +
|
|
|
|
" <b><span class='unwrap unwrap3'>f</span></b> </div> </div>"
|
|
|
|
);
|
|
|
|
|
|
|
|
var abcd = jQuery( "#unwrap1 > span, #unwrap2 > span" ).get(),
|
|
|
|
abcdef = jQuery( "#unwrap span" ).get();
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
jQuery( "#unwrap1 span" ).add( "#unwrap2 span:first-child" ).unwrap().length, 3,
|
|
|
|
"make #unwrap1 and #unwrap2 go away"
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "#unwrap > span" ).get(), abcd, "all four spans should still exist"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "#unwrap3 span" ).unwrap().get(), jQuery( "#unwrap3 > span" ).get(),
|
|
|
|
"make all b in #unwrap3 go away"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "#unwrap3 span" ).unwrap().get(), jQuery( "#unwrap > span.unwrap3" ).get(),
|
|
|
|
"make #unwrap3 go away"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "#unwrap" ).children().get(), abcdef, "#unwrap only contains 6 child spans"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "#unwrap > span" ).unwrap().get(), jQuery( "body > span.unwrap" ).get(),
|
|
|
|
"make the 6 spans become children of body"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "body > span.unwrap" ).unwrap().get(), jQuery( "body > span.unwrap" ).get(),
|
|
|
|
"can't unwrap children of body"
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "body > span.unwrap" ).unwrap().get(), abcdef, "can't unwrap children of body"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "body > span.unwrap" ).get(), abcdef, "body contains 6 .unwrap child spans"
|
|
|
|
);
|
|
|
|
|
|
|
|
jQuery( "body > span.unwrap" ).remove();
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
QUnit.test( "unwrap( selector )", function( assert ) {
|
2015-01-12 03:17:41 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 5 );
|
2015-01-12 03:17:41 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery( "body" ).append(
|
|
|
|
" <div id='unwrap' style='display: none;'> <div id='unwrap1'>" +
|
|
|
|
"<span class='unwrap'>a</span> <span class='unwrap'>b</span> </div>" +
|
|
|
|
" <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span>" +
|
|
|
|
" </div> </div>"
|
|
|
|
);
|
2015-01-12 03:17:41 +00:00
|
|
|
|
|
|
|
// Shouldn't unwrap, no match
|
|
|
|
jQuery( "#unwrap1 span" ) .unwrap( "#unwrap2" );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal(
|
|
|
|
jQuery( "#unwrap1" ).length, 1, "still wrapped"
|
|
|
|
);
|
2015-01-12 03:17:41 +00:00
|
|
|
|
2016-05-10 09:12:28 +00:00
|
|
|
// Shouldn't unwrap, no match
|
2015-01-12 03:17:41 +00:00
|
|
|
jQuery( "#unwrap1 span" ) .unwrap( "span" );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal(
|
|
|
|
jQuery( "#unwrap1" ).length, 1, "still wrapped"
|
|
|
|
);
|
2015-01-12 03:17:41 +00:00
|
|
|
|
|
|
|
// Unwraps
|
|
|
|
jQuery( "#unwrap1 span" ) .unwrap( "#unwrap1" );
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.equal(
|
|
|
|
jQuery( "#unwrap1" ).length, 0, "unwrapped match"
|
|
|
|
);
|
2015-01-12 03:17:41 +00:00
|
|
|
|
|
|
|
// Check return values
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "quote" ).get(),
|
|
|
|
"return on unmatched unwrap"
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "#unwrap2" ).get(),
|
|
|
|
"return on matched unwrap"
|
|
|
|
);
|
|
|
|
|
|
|
|
jQuery( "body > span.unwrap" ).remove();
|
|
|
|
} );
|
2015-01-12 03:17:41 +00:00
|
|
|
|
2022-01-12 22:23:10 +00:00
|
|
|
QUnit.test( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (trac-10667)", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 2 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
var $wraptarget = jQuery( "<div id='wrap-target'>Target</div>" ).appendTo( "#qunit-fixture" ),
|
|
|
|
$section = jQuery( "<section>" ).appendTo( "#qunit-fixture" );
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
$wraptarget.wrapAll( "<aside style='background-color:green'></aside>" );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
assert.notEqual(
|
|
|
|
$wraptarget.parent( "aside" ).get( 0 ).style.backgroundColor, "transparent",
|
|
|
|
"HTML5 elements created with wrapAll inherit styles"
|
|
|
|
);
|
|
|
|
assert.notEqual(
|
|
|
|
$section.get( 0 ).style.backgroundColor, "transparent",
|
|
|
|
"HTML5 elements create with jQuery( string ) inherit styles"
|
|
|
|
);
|
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2022-01-12 22:23:10 +00:00
|
|
|
QUnit.test( "wrapping scripts (trac-10470)", function( assert ) {
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 03:45:28 +00:00
|
|
|
assert.expect( 2 );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
var script = document.createElement( "script" );
|
|
|
|
script.text = script.textContent =
|
2019-02-18 18:02:38 +00:00
|
|
|
"QUnit.assert.ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;";
|
2013-04-08 22:00:02 +00:00
|
|
|
|
|
|
|
document.eval10470 = false;
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery( "#qunit-fixture" ).empty()[ 0 ].appendChild( script );
|
|
|
|
jQuery( "#qunit-fixture script" ).wrap( "<b></b>" );
|
|
|
|
assert.strictEqual(
|
|
|
|
script.parentNode, jQuery( "#qunit-fixture > b" )[ 0 ], "correctly wrapped"
|
|
|
|
);
|
2013-04-08 22:00:02 +00:00
|
|
|
jQuery( script ).remove();
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-04-08 22:00:02 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
} )();
|