2015-09-02 23:52:01 +00:00
|
|
|
( function() {
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
if ( !jQuery.fn.wrap ) { // no wrap module
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.module( "wrap", {
|
2013-04-08 21:40:08 +00:00
|
|
|
teardown: moduleTeardown
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
// See test/unit/manipulation.js for explanation about these 2 functions
|
|
|
|
function manipulationBareObj( value ) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function manipulationFunctionReturningObj( value ) {
|
|
|
|
return function() {
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
function testWrap( val, assert ) {
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.expect( 19 );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
var defaultText, result, j, i, cacheLength;
|
|
|
|
|
|
|
|
defaultText = "Try them out:";
|
2015-09-02 23:52:01 +00:00
|
|
|
result = jQuery( "#first" ).wrap( val( "<div class='red'><span></span></div>" ) ).text();
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
defaultText, result, "Check for wrapping of on-the-fly html"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
result = jQuery( "#first" ).wrap( val( document.getElementById( "empty" ) ) ).parent();
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.ok(
|
|
|
|
result.is( "ol" ), "Check for element wrapping"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
result.text(), defaultText, "Check for element wrapping"
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#check1" ).on( "click", function() {
|
2013-04-08 21:40:08 +00:00
|
|
|
var checkbox = this;
|
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.ok(
|
|
|
|
checkbox.checked, "Checkbox's state is erased after wrap() action, see #769"
|
|
|
|
);
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( checkbox ).wrap( val( "<div id='c1' style='display:none;'></div>" ) );
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.ok(
|
|
|
|
checkbox.checked, "Checkbox's state is erased after wrap() action, see #769"
|
|
|
|
);
|
2015-09-02 23:52:01 +00:00
|
|
|
} ).prop( "checked", false )[ 0 ].click();
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
// using contents will get comments regular, text, and comment nodes
|
2015-09-02 23:52:01 +00:00
|
|
|
j = jQuery( "#nonnodes" ).contents();
|
|
|
|
j.wrap( val( "<i></i>" ) );
|
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#nonnodes > i" ).length, 3, "Check node,textnode,comment wraps ok"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#nonnodes > i" ).text(),
|
|
|
|
j.text(),
|
|
|
|
"Check node,textnode,comment wraps doesn't hurt text"
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
// Try wrapping a disconnected node
|
|
|
|
cacheLength = 0;
|
|
|
|
for ( i in jQuery.cache ) {
|
|
|
|
cacheLength++;
|
|
|
|
}
|
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
j = jQuery( "<label/>" ).wrap( val( "<li/>" ) );
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped"
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
for ( i in jQuery.cache ) {
|
|
|
|
cacheLength--;
|
|
|
|
}
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)"
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
// Wrap an element containing a text node
|
2015-09-02 23:52:01 +00:00
|
|
|
j = jQuery( "<span/>" ).wrap( "<div>test</div>" );
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element."
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
// Try to wrap an element with multiple elements (should fail)
|
2015-09-02 23:52:01 +00:00
|
|
|
j = jQuery( "<div><span></span></div>" ).children().wrap( "<p></p><div></div>" );
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
j[ 0 ].parentNode.parentNode.childNodes.length,
|
|
|
|
1,
|
|
|
|
"There should only be one element wrapping."
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
j.length, 1, "There should only be one element (no cloning)."
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph."
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
// Wrap an element with a jQuery set
|
2015-09-02 23:52:01 +00:00
|
|
|
j = jQuery( "<span/>" ).wrap( jQuery( "<div></div>" ) );
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works."
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
// Wrap an element with a jQuery set and event
|
2015-09-02 23:52:01 +00:00
|
|
|
result = jQuery( "<div></div>" ).on( "click", function() {
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.ok(
|
|
|
|
true, "Event triggered."
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
// Remove handlers on detached elements
|
|
|
|
result.off();
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( this ).off();
|
|
|
|
} );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
j = jQuery( "<span/>" ).wrap( result );
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works."
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
j.parent().trigger( "click" );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( "wrap(String|Element)", function( assert ) {
|
|
|
|
testWrap( manipulationBareObj, assert );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( "wrap(Function)", function( assert ) {
|
|
|
|
testWrap( manipulationFunctionReturningObj, assert );
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( "wrap(Function) with index (#10177)", function( assert ) {
|
2013-04-08 21:40:08 +00:00
|
|
|
var expectedIndex = 0,
|
2015-09-02 23:52:01 +00:00
|
|
|
targets = jQuery( "#qunit-fixture p" );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.expect( targets.length );
|
2015-09-02 23:52:01 +00:00
|
|
|
targets.wrap( function( i ) {
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
i,
|
|
|
|
expectedIndex,
|
|
|
|
"Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")"
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
expectedIndex++;
|
|
|
|
|
|
|
|
return "<div id='wrap_index_'" + i + "'></div>";
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( "wrap(String) consecutive elements (#10177)", function( assert ) {
|
2015-09-02 23:52:01 +00:00
|
|
|
var targets = jQuery( "#qunit-fixture p" );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.expect( targets.length * 2 );
|
2015-09-02 23:52:01 +00:00
|
|
|
targets.wrap( "<div class='wrapper'></div>" );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
targets.each( function() {
|
|
|
|
var $this = jQuery( this );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.ok(
|
|
|
|
$this.parent().is( ".wrapper" ),
|
|
|
|
"Check each elements parent is correct (.wrapper)"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
$this.siblings().length, 0, "Each element should be wrapped individually"
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( "wrapAll(String)", function( assert ) {
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.expect( 5 );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
var prev, p, result;
|
|
|
|
|
2015-09-02 23:52:01 +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>" );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
result.parent().length, 1, "Check for wrapping of on-the-fly html"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
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(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).parent().parent()[ 0 ].parentNode, p, "Correct Parent"
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2013-12-24 16:35:41 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( "wrapAll(Element)", function( assert ) {
|
2013-12-24 16:35:41 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.expect( 3 );
|
2013-12-24 16:35:41 +00:00
|
|
|
|
|
|
|
var prev, p;
|
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
prev = jQuery( "#firstp" )[ 0 ].previousSibling;
|
|
|
|
p = jQuery( "#first" )[ 0 ].parentNode;
|
|
|
|
jQuery( "#firstp,#first" ).wrapAll( document.getElementById( "empty" ) );
|
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).parent()[ 0 ], jQuery( "#firstp" ).parent()[ 0 ], "Same Parent"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).parent()[ 0 ].parentNode, p, "Correct Parent"
|
|
|
|
);
|
|
|
|
} );
|
2013-12-24 16:35:41 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( "wrapInner(String)", function( assert ) {
|
2013-12-24 16:35:41 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.expect( 6 );
|
2013-12-24 16:35:41 +00:00
|
|
|
|
|
|
|
var num;
|
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
num = jQuery( "#first" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( "<div class='red'><div id='tmp'></div></div>" );
|
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
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>" );
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
|
|
|
} );
|
2013-12-24 16:35:41 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( "wrapInner(Element)", function( assert ) {
|
2013-12-24 16:35:41 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.expect( 5 );
|
2013-12-24 16:35:41 +00:00
|
|
|
|
|
|
|
var num,
|
2015-09-02 23:52:01 +00:00
|
|
|
div = jQuery( "<div/>" );
|
|
|
|
|
|
|
|
num = jQuery( "#first" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( document.getElementById( "empty" ) );
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( "#empty" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2013-12-24 16:35:41 +00:00
|
|
|
div.wrapInner( "<span></span>" );
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
div.children().length, 1, "The contents were wrapped."
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted."
|
|
|
|
);
|
|
|
|
} );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( "wrapInner(Function) returns String", function( assert ) {
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.expect( 6 );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2013-12-24 16:35:41 +00:00
|
|
|
var num,
|
|
|
|
val = manipulationFunctionReturningObj;
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
num = jQuery( "#first" ).children().length;
|
|
|
|
jQuery( "#first" ).wrapInner( val( "<div class='red'><div id='tmp'></div></div>" ) );
|
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
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>" ) );
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).children().length, 1, "Only one child"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.ok(
|
|
|
|
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
|
|
|
|
);
|
|
|
|
} );
|
2013-12-24 16:35:41 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( "wrapInner(Function) returns Element", function( assert ) {
|
2013-12-24 16:35:41 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.expect( 5 );
|
2013-12-24 16:35:41 +00:00
|
|
|
|
|
|
|
var num,
|
|
|
|
val = manipulationFunctionReturningObj,
|
2015-12-22 18:20:16 +00:00
|
|
|
div = jQuery("<div/>");
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
num = jQuery("#first").children().length;
|
|
|
|
jQuery("#first").wrapInner( val(document.getElementById("empty")) );
|
|
|
|
equal( jQuery("#first").children().length, 1, "Only one child" );
|
|
|
|
ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
|
|
|
|
equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
div.wrapInner( val("<span></span>") );
|
|
|
|
equal( div.children().length, 1, "The contents were wrapped." );
|
|
|
|
equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
|
|
|
|
});
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
test( "unwrap()", function() {
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
expect( 9 );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-12-22 18:20:16 +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>");
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(),
|
|
|
|
abcdef = jQuery("#unwrap span").get();
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
equal( jQuery("#unwrap1 span").add("#unwrap2 span:first-child").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" );
|
|
|
|
deepEqual( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" );
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" );
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" );
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
deepEqual( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" );
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
deepEqual( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" );
|
2015-01-12 03:17:41 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
deepEqual( jQuery("body > span.unwrap").unwrap().get(), jQuery("body > span.unwrap").get(), "can't unwrap children of body" );
|
|
|
|
deepEqual( jQuery("body > span.unwrap").unwrap().get(), abcdef, "can't unwrap children of body" );
|
2015-01-12 03:17:41 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
deepEqual( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" );
|
2015-09-02 23:52:01 +00:00
|
|
|
|
2015-12-22 18:20:16 +00:00
|
|
|
jQuery("body > span.unwrap").remove();
|
|
|
|
});
|
2015-01-12 03:17:41 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", function( assert ) {
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.expect( 2 );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
var $wraptarget = jQuery( "<div id='wrap-target'>Target</div>" ).appendTo( "#qunit-fixture" ),
|
|
|
|
$section = jQuery( "<section>" ).appendTo( "#qunit-fixture" );
|
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
$wraptarget.wrapAll( "<aside style='background-color:green'></aside>" );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.notEqual(
|
2015-09-02 23:52:01 +00:00
|
|
|
$wraptarget.parent( "aside" ).get( 0 ).style.backgroundColor,
|
|
|
|
"transparent",
|
|
|
|
"HTML5 elements created with wrapAll inherit styles"
|
|
|
|
);
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.notEqual(
|
2015-09-02 23:52:01 +00:00
|
|
|
$section.get( 0 ).style.backgroundColor,
|
|
|
|
"transparent",
|
|
|
|
"HTML5 elements create with jQuery( string ) inherit styles"
|
|
|
|
);
|
|
|
|
} );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
QUnit.test( "wrapping scripts (#10470)", function( assert ) {
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.expect( 2 );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
var script = document.createElement( "script" );
|
|
|
|
script.text = script.textContent =
|
|
|
|
"ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;";
|
2013-04-08 21:40:08 +00:00
|
|
|
|
|
|
|
document.eval10470 = false;
|
2015-09-02 23:52:01 +00:00
|
|
|
jQuery( "#qunit-fixture" ).empty()[ 0 ].appendChild( script );
|
|
|
|
jQuery( "#qunit-fixture script" ).wrap( "<b></b>" );
|
2015-09-03 01:46:31 +00:00
|
|
|
assert.strictEqual(
|
2015-09-02 23:52:01 +00:00
|
|
|
script.parentNode, jQuery( "#qunit-fixture > b" )[ 0 ], "correctly wrapped"
|
|
|
|
);
|
2013-04-08 21:40:08 +00:00
|
|
|
jQuery( script ).remove();
|
2015-09-02 23:52:01 +00:00
|
|
|
} );
|
2013-04-08 21:40:08 +00:00
|
|
|
|
2015-09-02 23:52:01 +00:00
|
|
|
} )();
|