From 35a12124ec0068a468ad68eb319d2b802854572f Mon Sep 17 00:00:00 2001 From: Steve Orvell Date: Wed, 20 Nov 2013 18:30:37 -0800 Subject: [PATCH] Corrects document.importNode, fixes #317 --- src/wrappers/Document.js | 6 ++++++ test/js/Document.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/wrappers/Document.js b/src/wrappers/Document.js index 6f54f88..e696f74 100644 --- a/src/wrappers/Document.js +++ b/src/wrappers/Document.js @@ -80,6 +80,8 @@ doc.adoptNode(oldShadowRoot); } + var originalImportNode = document.importNode; + mixin(Document.prototype, { adoptNode: function(node) { if (node.parentNode) @@ -89,6 +91,9 @@ }, elementFromPoint: function(x, y) { return elementFromPoint(this, this, x, y); + }, + importNode: function(node, deep) { + return wrap(originalImportNode.call(this.impl, unwrap(node), deep)); } }); @@ -207,6 +212,7 @@ window.HTMLDocument || window.Document, // Gecko adds these to HTMLDocument ], [ 'adoptNode', + 'importNode', 'contains', 'createComment', 'createDocumentFragment', diff --git a/test/js/Document.js b/test/js/Document.js index 48228bf..b897681 100644 --- a/test/js/Document.js +++ b/test/js/Document.js @@ -221,6 +221,22 @@ htmlSuite('Document', function() { assert.equal(c.ownerDocument, doc); }); + test('importNode', function() { + var doc = wrap(document); + var doc2 = doc.implementation.createHTMLDocument(''); + var div = doc2.createElement('div'); + div.innerHTML = 'test'; + assert.equal(div.ownerDocument, doc2); + + var div2 = document.importNode(div, true); + assert.equal(div.innerHTML, div2.innerHTML); + assert.equal(div2.ownerDocument, doc); + + var div3 = doc2.importNode(div2); + assert.equal(div3.innerHTML, ''); + assert.equal(div3.ownerDocument, doc2); + }); + test('elementFromPoint', function() { div = document.body.appendChild(document.createElement('div')); div.style.cssText = 'position: fixed; background: green; ' +