Skip to content

Commit

Permalink
fix(jqLite): make jqLite('<iframe src="someurl">').contents() return …
Browse files Browse the repository at this point in the history
…iframe document, as in jQuery

This is a very tiny change to make behaviour consistent with jQuery.

Closes angular#6320
  • Loading branch information
caitp committed Feb 18, 2014
1 parent 12e4d3a commit 9ea67e1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
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>
22 changes: 22 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,28 @@ describe('jqLite', function() {
expect(contents[0].data).toEqual(' some comment ');
expect(contents[1].data).toEqual('before-');
});


iit('should select all types iframe contents', function() {
var iframe_ = document.createElement('iframe'), tested;
var iframe = jqLite(iframe_);
iframe_.onload = iframe_.onreadystatechange = function() {
if (iframe_.contentDocument.readyState !== 'complete') {
return;
}
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_.src = "/base/test/fixtures/iframe.html";
jqLite(document).find('body').append(iframe);
waitsFor(function() { return tested; }, 500);
});
});


Expand Down

0 comments on commit 9ea67e1

Please sign in to comment.