Skip to content

Instantly share code, notes, and snippets.

@sounisi5011
Last active May 5, 2018 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sounisi5011/36c896a1bfab1d05f6121381d4b95366 to your computer and use it in GitHub Desktop.
Save sounisi5011/36c896a1bfab1d05f6121381d4b95366 to your computer and use it in GitHub Desktop.
document.createEvent run test
<!doctype html>
<html lang=ja>
<meta charset=utf-8>
<meta name=viewport content="width=device-width,initial-scale=1">
<meta name=format-detection content="telephone=no,email=no,address=no">
<title>document.createEvent run test</title>
<link rel=preload href=main.css as=style>
<link rel=preload href=main.js as=script>
<link href=main.css rel=stylesheet>
<body>
<script src=main.js></script>
.main {
overflow-x: scroll;
}
(function(init) {
var printTextLines = [];
init(printTextLines);
var preElem = document.createElement('pre');
preElem.className = 'main';
preElem.appendChild(document.createTextNode(printTextLines.join("\n")));
document.body.insertBefore(preElem, null);
})(function(line) {
function forEach(list, callback) {
for (var i = 0, l = list.length; i < l; i++) {
callback(list[i], i, list);
}
}
if (typeof document.addEventListener !== 'function') {
line.push('Your browser does not support the document.addEventListener method.');
return;
}
if (typeof document.createEvent !== 'function') {
line.push('Your browser does not support the document.createEvent method.');
return;
}
var eventTypeList = ['Event', 'MouseEvent', 'UIEvent'];
forEach(eventTypeList, function(eventType) {
var typeList = [
eventType,
eventType + 's',
eventType.toLowerCase(),
eventType.toLowerCase() + 's'
];
forEach(typeList, function(type) {
try {
line.push('document.createEvent("' + type + '"):');
var event = document.createEvent(type);
line.push(String(event).replace(/^/gm, ' '));
if (event) {
var propNameList = [];
for (var prop in event) {
var propName = prop;
try {
var type = typeof event[prop];
if (type === 'function') {
propName += '()';
} else {
propName += ' [' + type + ']';
}
} catch(error) {
propName += ' [???]';
}
propNameList.push(propName);
}
propNameList.sort();
forEach(propNameList, function(propName) {
line.push(' * ' + propName);
});
}
} catch(error) {
line.push(' Error:');
line.push(String(error).replace(/^/gm, ' '));
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment