Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(jqLite): make jqLite('<iframe src="someurl">').contents() return iframe document, as in jQuery #6323

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion karma-jqlite.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ module.exports = function(config) {
sharedConfig(config, {testName: 'AngularJS: jqLite', logFile: 'karma-jqlite.log'});

config.set({
files: angularFiles.mergeFilesFor('karma'),
files: angularFiles.mergeFilesFor('karma').concat({
pattern: "test/fixtures/**/*.html",
served: true,
watched: true,
included: false
}),
exclude: angularFiles.mergeFilesFor('karmaExclude'),

junitReporter: {
Expand Down
7 changes: 6 additions & 1 deletion karma-jquery.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ module.exports = function(config) {
sharedConfig(config, {testName: 'AngularJS: jQuery', logFile: 'karma-jquery.log'});

config.set({
files: angularFiles.mergeFilesFor('karmaJquery'),
files: angularFiles.mergeFilesFor('karmaJquery').concat({
pattern: "test/fixtures/**/*.html",
served: true,
watched: true,
included: false
}),
exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'),

junitReporter: {
Expand Down
2 changes: 1 addition & 1 deletion src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ forEach({
},

contents: function(element) {
return element.childNodes || [];
return element.contentDocument || element.childNodes || [];
},

append: function(element, node) {
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Iframe Test</title>
</head>
<body>
<span>Text</span>
</body>
</html>
24 changes: 24 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,30 @@ describe('jqLite', function() {
expect(contents[0].data).toEqual(' some comment ');
expect(contents[1].data).toEqual('before-');
});

// IE8 does not like this test, although the functionality may still work there.
if (!msie || msie > 8) {
it('should select all types iframe contents', function() {
var iframe_ = document.createElement('iframe'), tested,
iframe = jqLite(iframe_);
function test() {
var contents = iframe.contents();
expect(contents[0]).toBeTruthy();
expect(contents.length).toBe(1);
expect(contents.prop('nodeType')).toBe(9);
expect(contents[0].body).toBeTruthy();
expect(jqLite(contents[0].body).contents().length).toBe(3);
iframe.remove();
tested = true;
}
iframe_.onload = iframe_.onreadystatechange = function() {
if (iframe_.contentDocument) test();
};
iframe_.src = "/base/test/fixtures/iframe.html";
jqLite(document).find('body').append(iframe);
waitsFor(function() { return tested; }, 500);
});
}
});


Expand Down