-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use correct event interface (#977)
- Loading branch information
1 parent
0fb50d8
commit 8771b8f
Showing
6 changed files
with
247 additions
and
1,702 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
"vue-template-compiler": "^2.x" | ||
}, | ||
"dependencies": { | ||
"dom-event-types": "^1.0.0", | ||
"lodash": "^4.17.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import eventTypes from 'dom-event-types' | ||
|
||
const defaultEventType = { | ||
eventInterface: 'Event', | ||
cancelable: true, | ||
bubbles: true | ||
} | ||
|
||
const modifiers = { | ||
enter: 13, | ||
tab: 9, | ||
delete: 46, | ||
esc: 27, | ||
space: 32, | ||
up: 38, | ||
down: 40, | ||
left: 37, | ||
right: 39, | ||
end: 35, | ||
home: 36, | ||
backspace: 8, | ||
insert: 45, | ||
pageup: 33, | ||
pagedown: 34 | ||
} | ||
|
||
export default function createDOMEvent (type, options) { | ||
const [eventType, modifier] = type.split('.') | ||
const { | ||
eventInterface, | ||
bubbles, | ||
cancelable | ||
} = eventTypes[eventType] || defaultEventType | ||
|
||
if (typeof window.Event === 'function') { | ||
const SupportedEventInterface = | ||
typeof window[eventInterface] === 'function' | ||
? window[eventInterface] | ||
: window.Event | ||
|
||
return new SupportedEventInterface(eventType, { | ||
bubbles, | ||
cancelable, | ||
...options, | ||
keyCode: modifiers[modifier] | ||
}) | ||
} | ||
|
||
// Fallback for IE10,11 - https://stackoverflow.com/questions/26596123 | ||
const eventObject = document.createEvent('Event') | ||
|
||
eventObject.initEvent(eventType, bubbles, cancelable) | ||
Object.keys(options || {}).forEach(key => { | ||
eventObject[key] = options[key] | ||
}) | ||
eventObject.keyCode = modifiers[modifier] | ||
|
||
return eventObject | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.