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 #176 from arv/event-on-non-element-document-nodes
Browse files Browse the repository at this point in the history
Fix issue with events and non Element/Document nodes
  • Loading branch information
dfreedm committed Jun 19, 2013
2 parents befe80b + 3e7fc49 commit 4f1adb1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/wrappers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@
'dispatchEvent'
];

[Element, Window, Document].forEach(function(constructor) {
[Node, Window].forEach(function(constructor) {
var p = constructor.prototype;
methodNames.forEach(function(name) {
Object.defineProperty(p, name + '_', {value: p[name]});
Expand Down
25 changes: 25 additions & 0 deletions test/js/MutationObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,29 @@ suite('MutationObserver', function() {
document.head.setAttribute('a', newValue());
});

test('observe text node', function(done) {
if (!window.MutationObserver) {
done();
return;
}

div = document.body.appendChild(document.createElement('div'));
var a = document.createTextNode('');
div.appendChild(a);

var mo = new MutationObserver(function(records, observer) {
mergeRecords(records);
assert.equal(this, mo);
assert.equal(observer, mo);
assert.equal(records[0].type, 'childList');
assert.equal(records[0].target, div);
assert.equal(removedNodes.length, 1);
assert.equal(removedNodes[0], a);
done();
});
mo.observe(div, {childList: true});

div.removeChild(a);
});

});
11 changes: 11 additions & 0 deletions test/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -1266,4 +1266,15 @@ test('retarget order (multiple shadow roots)', function() {
doc.body.dispatchEvent(e);
});

test('dispatch on text node', function() {
var text = document.createTextNode('x');
text.addEventListener('x', function f(e) {
assert.equal(e.target, text);
assert.equal(e.currentTarget, text);
assert.equal(this, text);
text.removeEventListener('x', f);
});
text.dispatchEvent(new Event('x'));
});

});

0 comments on commit 4f1adb1

Please sign in to comment.