Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #323 from arv/outer-html-mutation-observer
Browse files Browse the repository at this point in the history
Fix outerHTML setter so that mutation observers are notified
  • Loading branch information
Steve Orvell committed Nov 25, 2013
2 parents 6401f84 + c632455 commit c12a7c0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/wrappers/HTMLElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@
return getOuterHTML(this);
},
set outerHTML(value) {
// TODO(arv): Mutation observer
var p = this.parentNode;
if (p) {
p.invalidateShadowRenderer();
this.impl.outerHTML = value;
var df = frag(p, value);
p.replaceChild(df, this);
}
},

Expand Down
32 changes: 32 additions & 0 deletions test/js/MutationObserver/childList.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,38 @@ suite('MutationObserver', function() {
});
});

test('outerHTML', function() {
var a = document.createElement('a');
a.innerHTML = '<b></b><c></c><d></d>';
var b = a.firstChild;
var c = b.nextSibling;
var d = a.lastChild;

var sr = a.createShadowRoot();
a.offsetHeight;

var observer = new MutationObserver(function() {});
observer.observe(a, {
childList: true
});

c.outerHTML = '<e></e><f></f>';
assert.equal(a.innerHTML, '<b></b><e></e><f></f><d></d>');
var e = b.nextSibling;
var f = e.nextSibling;

var records = observer.takeRecords();
assert.equal(records.length, 1);
expectMutationRecord(records[0], {
type: 'childList',
target: a,
addedNodes: [e, f],
removedNodes: [c],
previousSibling: b,
nextSibling: d
});
});

});

});

0 comments on commit c12a7c0

Please sign in to comment.