Created
July 14, 2014 19:44
-
-
Save nhunzaker/7bbafa9d82ec00106ed7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Event runner</title> | |
<script src="http://modernizr.com/downloads/modernizr-latest.js"></script> | |
<style> | |
body { | |
font-family: sans-serif; | |
} | |
</style> | |
</head> | |
<body> | |
<form> | |
<input type="text" id="input" disabled /> | |
<select id="select" disabled> | |
<option>Foo</option> | |
</select> | |
<textarea id="textarea" disabled="true" disabled> | |
Textarea | |
</textarea> | |
<button id="button" disabled></button> | |
</form> | |
<table> | |
<thead> | |
<tr> | |
<th>Element</th> | |
<th>Event</th> | |
</tr> | |
</thead> | |
<tbody id="triggered"> | |
</tbody> | |
</table> | |
<script> | |
var mouseEvents = [ | |
'click', 'contextmenu', 'DOMMouseScroll', 'dblclick', | |
'keydown', 'keypress', 'keyup', 'mousedown', | |
'mouseenter', 'mouseleave', 'mousemove', 'mouseout', | |
'mouseover', 'mouseup', 'mousewheel', | |
'pointerlockchange', 'pointerlockerror', 'wheel' | |
] | |
var focusEvents = ['focus', 'blur'] | |
var touchEvents = [ | |
'touchcancel', 'touchend', 'touchenter', 'touchleave', | |
'touchmove', 'touchstart' | |
]; | |
var input = document.getElementById('input'); | |
var triggered = document.getElementById('triggered'); | |
function addEntry(name, event) { | |
var row = document.createElement('tr'); | |
row.innerHTML = "<td>" + name + "</td><td>" + event + "</td>"; | |
triggered.appendChild(row); | |
} | |
function test(pool, EventType, flag) { | |
var event; | |
for (var i = 0, len = pool.length; i < len; i++) { | |
event = pool[i]; | |
input.addEventListener(event, function() { | |
addEntry('input', event); | |
}, false); | |
input.dispatchEvent(new EventType(event)); | |
select.addEventListener(event, function() { | |
addEntry('select', event); | |
}, false); | |
select.dispatchEvent(new EventType(event)); | |
textarea.addEventListener(event, function() { | |
addEntry('select', event); | |
}, false); | |
textarea.dispatchEvent(new EventType(event)); | |
button.addEventListener(event, function() { | |
addEntry('button', event); | |
}, false); | |
button.dispatchEvent(new EventType(event)); | |
} | |
} | |
test(mouseEvents, MouseEvent, 'mouse'); | |
test(focusEvents, FocusEvent, 'focus'); | |
if (Modernizr.touch) { | |
test(touchEvents, TouchEvent, 'touch'); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment