Add new textChange event: input + IE shim

IE8 doesn't support oninput and IE9 supports it badly but we can do
almost a perfect shim by listening to a handful of different events
(focus, blur, propertychange, selectionchange, keyup, keydown).

This always triggers event handlers during the browser's event loop (not
later in a setTimeout) and after the value property has been updated.

The only case I know of where this doesn't fire the event immediately is
if (in IE8) you modify the input value using JS and then the user does a
key repeat, in which case we fire the event on the second keydown.

Test Plan:
Modify ballmer-peak example to add es5-shim and to use onTextChange
instead of onInput. In IE8, IE9, and latest Chrome, make sure that the
event is fired upon:

* typing normally,
* backspacing,
* forward-deleting,
* cutting,
* pasting,
* context-menu deleting,
* dragging text to reorder characters.

After modifying the example to change .value, make sure that the event
is not fired as a result of the changes from JS (even when the input box
is focused).
This commit is contained in:
Ben Alpert committed 2013-06-09 04:18:15 -07:00
1 parent 7e7579e1ba
commit c19bf9cffe
5 files changed
+212 -3

No files matched your search

+3 -2
View File
@@ -41,13 +41,14 @@ var topLevelTypes = keyMirror({
topMouseOut: null,
topMouseOver: null,
topMouseUp: null,
topWheel: null,
topScroll: null,
topSelectionChange: null,
topSubmit: null,
topTouchCancel: null,
topTouchEnd: null,
topTouchMove: null,
topTouchStart: null
topTouchStart: null,
topWheel: null
});
var EventConstants = {