Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Merge 8857a2a into f37f07f
Browse files Browse the repository at this point in the history
  • Loading branch information
SheepFromHeaven committed Jan 8, 2019
2 parents f37f07f + 8857a2a commit 62a0cb6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/CustomEvent.js
Expand Up @@ -11,4 +11,9 @@ module.exports = class CustomEvent extends Event {
super(type, eventInitDict);
this.detail = eventInitDict.detail;
}

initCustomEvent(type, bubbles, cancelable, detail) {
this.initEvent(type, bubbles, cancelable);
this.detail = detail;
}
};
11 changes: 9 additions & 2 deletions src/Document.js
@@ -1,5 +1,6 @@
const CustomElementRegistry = require('./CustomElementRegistry');
const Event = require('./Event');
const CustomEvent = require('./CustomEvent');
const Node = require('./Node');
const DocumentType = require('./DocumentType');
const Attr = require('./Attr');
Expand Down Expand Up @@ -83,8 +84,14 @@ module.exports = class Document extends Node {
}

createEvent(name) {
if (name !== 'Event') throw new Error(name + ' not implemented');
return new Event();
switch (name) {
case 'Event':
return new Event();
case 'CustomEvent':
return new CustomEvent();
default:
throw new Error(name + ' not implemented');
}
}

createRange() {
Expand Down
7 changes: 7 additions & 0 deletions test/all.js
Expand Up @@ -354,6 +354,13 @@ assert(
'CustomEvent also works as expected'
);

var createdCustomEvent = document.createEvent('CustomEvent');
createdCustomEvent.initCustomEvent('custom', true, true, 'detail');
assert(
createdCustomEvent.detail === 'detail',
'CustomEvent can be created procedurally'
);

log('## Comments');
let comment = document.createComment('Here a comment');
assert(comment.textContent === 'Here a comment');
Expand Down

0 comments on commit 62a0cb6

Please sign in to comment.