Skip to content

Commit

Permalink
bringing back Dav's ownerDocument fixes...
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpvar committed Oct 28, 2010
2 parents abdc0df + 19d218a commit 4f2191d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/jsdom/level2/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ core.Node.prototype.__proto__ = events.EventTarget.prototype;
(function(level1) {
core.Node.prototype.appendChild = function(newChild) {
var ret = level1.call(this, newChild);
if (this.nodeType == 1) {
if (this.nodeType == 1 && this.ownerDocument) {
var ev = this.ownerDocument.createEvent("MutationEvents");
ev.initMutationEvent("DOMNodeInserted", true, false, this, null, null, null, null);
newChild.dispatchEvent(ev);
Expand All @@ -299,9 +299,11 @@ core.Node.prototype.__proto__ = events.EventTarget.prototype;
// Wrap the level-1 implementation of removeChild() to dispatch a DOMNodeRemoved event
(function(level1) {
core.Node.prototype.removeChild = function(oldChild) {
var ev = this.ownerDocument.createEvent("MutationEvents");
ev.initMutationEvent("DOMNodeRemoved", true, false, this, null, null, null, null);
oldChild.dispatchEvent(ev);
if (this.ownerDocument) {
var ev = this.ownerDocument.createEvent("MutationEvents");
ev.initMutationEvent("DOMNodeRemoved", true, false, this, null, null, null, null);
oldChild.dispatchEvent(ev);
}
return level1.call(this, oldChild);
};
})(core.Node.prototype.removeChild);
Expand Down

0 comments on commit 4f2191d

Please sign in to comment.