Skip to content

Commit bc25a36

Browse files
committed
fix(jqLite): make jqLite('<iframe src="someurl">').contents() return iframe document, as in jQuery
This is a very tiny change to make behaviour consistent with jQuery. Closes angular#6320
1 parent 12e4d3a commit bc25a36

File tree

5 files changed

+47
-3
lines changed

5 files changed

+47
-3
lines changed

karma-jqlite.conf.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ module.exports = function(config) {
55
sharedConfig(config, {testName: 'AngularJS: jqLite', logFile: 'karma-jqlite.log'});
66

77
config.set({
8-
files: angularFiles.mergeFilesFor('karma'),
8+
files: angularFiles.mergeFilesFor('karma').concat({
9+
pattern: "test/fixtures/**/*.html",
10+
served: true,
11+
watched: true,
12+
included: false
13+
}),
914
exclude: angularFiles.mergeFilesFor('karmaExclude'),
1015

1116
junitReporter: {

karma-jquery.conf.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ module.exports = function(config) {
55
sharedConfig(config, {testName: 'AngularJS: jQuery', logFile: 'karma-jquery.log'});
66

77
config.set({
8-
files: angularFiles.mergeFilesFor('karmaJquery'),
8+
files: angularFiles.mergeFilesFor('karmaJquery').concat({
9+
pattern: "test/fixtures/**/*.html",
10+
served: true,
11+
watched: true,
12+
included: false
13+
}),
914
exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'),
1015

1116
junitReporter: {

src/jqLite.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ forEach({
793793
},
794794

795795
contents: function(element) {
796-
return element.childNodes || [];
796+
return element.contentDocument || element.childNodes || [];
797797
},
798798

799799
append: function(element, node) {

test/fixtures/iframe.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Iframe Test</title>
5+
</head>
6+
<body>
7+
<span>Text</span>
8+
</body>
9+
</html>

test/jqLiteSpec.js

+25
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,31 @@ describe('jqLite', function() {
12991299
expect(contents[0].data).toEqual(' some comment ');
13001300
expect(contents[1].data).toEqual('before-');
13011301
});
1302+
1303+
1304+
it('should select all types iframe contents', function() {
1305+
var iframe_ = document.createElement('iframe'), tested,
1306+
iframe = jqLite(iframe_);
1307+
function test() {
1308+
var contents = iframe.contents();
1309+
expect(contents[0]).toBeTruthy();
1310+
expect(contents.length).toBe(1);
1311+
expect(contents.prop('nodeType')).toBe(9);
1312+
expect(contents[0].body).toBeTruthy();
1313+
expect(jqLite(contents[0].body).contents().length).toBe(3);
1314+
iframe.remove();
1315+
tested = true;
1316+
}
1317+
iframe_.onload = function() { test(); };
1318+
iframe_.onreadystatechange = function() {
1319+
if (iframe_.readyState === "complete") {
1320+
test();
1321+
}
1322+
};
1323+
iframe_.src = "/base/test/fixtures/iframe.html";
1324+
jqLite(document).find('body').append(iframe);
1325+
waitsFor(function() { return tested; }, 500);
1326+
});
13021327
});
13031328

13041329

0 commit comments

Comments
 (0)