🌐 AI搜索 & 代理 主页
Skip to content

Commit bd2c5a3

Browse files
committed
Use tabs instead of spaces at fn.contents()
1 parent a8d84fb commit bd2c5a3

File tree

2 files changed

+48
-50
lines changed

2 files changed

+48
-50
lines changed

src/traversing.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,18 @@ jQuery.each( {
145145
return siblings( elem.firstChild );
146146
},
147147
contents: function( elem ) {
148-
if ( typeof elem.contentDocument !== "undefined" ) {
149-
return elem.contentDocument;
150-
}
151-
152-
// Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only
153-
// Treat the template element as a regular one in browsers that
154-
// don't support it.
155-
if ( nodeName( elem, "template" ) ) {
156-
elem = elem.content || elem;
157-
}
158-
159-
return jQuery.merge( [], elem.childNodes );
148+
if ( typeof elem.contentDocument !== "undefined" ) {
149+
return elem.contentDocument;
150+
}
151+
152+
// Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only
153+
// Treat the template element as a regular one in browsers that
154+
// don't support it.
155+
if ( nodeName( elem, "template" ) ) {
156+
elem = elem.content || elem;
157+
}
158+
159+
return jQuery.merge( [], elem.childNodes );
160160
}
161161
}, function( name, fn ) {
162162
jQuery.fn[ name ] = function( until, selector ) {

test/unit/traversing.js

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -744,56 +744,53 @@ QUnit.test( "contents()", function( assert ) {
744744
} );
745745

746746
QUnit.test( "contents() for <template />", function( assert ) {
747-
assert.expect( 4 );
747+
assert.expect( 4 );
748748

749-
jQuery( "#qunit-fixture" ).append(
750-
"<template id='template'>" +
751-
" <div id='template-div0'>" +
752-
" <span>Hello, Web Component!</span>" +
753-
" </div>" +
754-
" <div id='template-div1'></div>" +
755-
" <div id='template-div2'></div>" +
756-
"</template>"
757-
);
749+
jQuery( "#qunit-fixture" ).append(
750+
"<template id='template'>" +
751+
" <div id='template-div0'>" +
752+
" <span>Hello, Web Component!</span>" +
753+
" </div>" +
754+
" <div id='template-div1'></div>" +
755+
" <div id='template-div2'></div>" +
756+
"</template>"
757+
);
758758

759-
var contents = jQuery( "#template" ).contents();
760-
assert.equal( contents.length, 6, "Check template element contents" );
759+
var contents = jQuery( "#template" ).contents();
760+
assert.equal( contents.length, 6, "Check template element contents" );
761761

762-
assert.equal( contents.find( "span" ).text(), "Hello, Web Component!", "Find span in template and check its text" );
762+
assert.equal( contents.find( "span" ).text(), "Hello, Web Component!", "Find span in template and check its text" );
763763

764-
jQuery( "<div id='templateTest' />" ).append(
765-
jQuery( jQuery.map( contents, function( node ) {
766-
return document.importNode( node, true );
767-
} ) )
768-
).appendTo( "#qunit-fixture" );
764+
jQuery( "<div id='templateTest' />" ).append(
765+
jQuery( jQuery.map( contents, function( node ) {
766+
return document.importNode( node, true );
767+
} ) )
768+
).appendTo( "#qunit-fixture" );
769769

770-
contents = jQuery( "#templateTest" ).contents();
771-
assert.equal( contents.length, 6, "Check cloned nodes of template element contents" );
770+
contents = jQuery( "#templateTest" ).contents();
771+
assert.equal( contents.length, 6, "Check cloned nodes of template element contents" );
772772

773-
assert.equal( contents.filter( "div" ).length, 3, "Count cloned elements from template" );
773+
assert.equal( contents.filter( "div" ).length, 3, "Count cloned elements from template" );
774774
} );
775775

776-
QUnit[ "content" in document.createElement( "template" ) ? "test" : "skip" ](
777-
"contents() for <template /> remains inert",
778-
function( assert ) {
779-
assert.expect( 2 );
776+
QUnit[ "content" in document.createElement( "template" ) ? "test" : "skip" ]( "contents() for <template /> remains inert", function( assert ) {
777+
assert.expect( 2 );
780778

781-
Globals.register( "testScript" );
782-
Globals.register( "testImgOnload" );
779+
Globals.register( "testScript" );
780+
Globals.register( "testImgOnload" );
783781

784-
jQuery( "#qunit-fixture" ).append(
785-
"<template id='template'>" +
786-
" <script>testScript = 1;</script>" +
787-
" <img src='" + baseURL + "1x1.jpg' onload='testImgOnload = 1' >" +
788-
"</template>"
789-
);
782+
jQuery( "#qunit-fixture" ).append(
783+
"<template id='template'>" +
784+
" <script>testScript = 1;</script>" +
785+
" <img src='" + baseURL + "1x1.jpg' onload='testImgOnload = 1' >" +
786+
"</template>"
787+
);
790788

791-
var content = jQuery( "#template" ).contents();
789+
var content = jQuery( "#template" ).contents();
792790

793-
assert.strictEqual( window.testScript, true, "script in template isn't executed" );
794-
assert.strictEqual( window.testImgOnload, true, "onload of image in template isn't executed" );
795-
}
796-
);
791+
assert.strictEqual( window.testScript, true, "script in template isn't executed" );
792+
assert.strictEqual( window.testImgOnload, true, "onload of image in template isn't executed" );
793+
} );
797794

798795
QUnit.test( "contents() for <object />", function( assert ) {
799796
assert.expect( 2 );
@@ -820,6 +817,7 @@ QUnit.test( "contents() for <frame />", function( assert ) {
820817
iframe.on( "load", function() {
821818
var container = jQuery( "#frame-contents" ).contents();
822819
var contents = container.find( "#test-frame" ).contents();
820+
console.log( contents.find( "html" ).html() );
823821
assert.equal( contents.length, 1, "Check frame contents" );
824822
assert.equal( contents.find( "body" ).length, 1, "Find body within frame" );
825823
done();

0 commit comments

Comments
 (0)