cleanup key handling

This commit is contained in:
Fabian Jakobs 2011-08-15 12:21:24 +02:00
commit 7b2ddf13c3

View file

@ -92,7 +92,7 @@ var TextInput = function(parentNode, host) {
}, 0);
};
var onKeyPress = function(e) {
var onPropertyChange = function(e) {
if (useragent.isIE && text.value.charCodeAt(0) > 128) return;
setTimeout(function() {
if (!inCompostion)
@ -155,22 +155,11 @@ var TextInput = function(parentNode, host) {
inCompostion ? onCompositionUpdate() : onCompositionStart();
});
};
if (text.attachEvent) {
// Old IE + Opera
event.addListener(text, "propertychange", onKeyPress);
}
else {
if (useragent.isChrome || useragent.isSafari)
event.addListener(text, "textInput", onTextInput);
else if (useragent.isIE)
// IE9
event.addListener(text, "textinput", onTextInput);
else
// All browsers except old IE
event.addListener(text, "input", onTextInput);
}
if ("onpropertychange" in text && !("oninput" in text))
event.addListener(text, "propertychange", onPropertyChange);
else
event.addListener(text, "input", onTextInput);
event.addListener(text, "paste", function(e) {
// Mark that the next input text comes from past.
@ -184,7 +173,7 @@ var TextInput = function(parentNode, host) {
else {
// If a browser doesn't support any of the things above, use the regular
// method to detect the pasted input.
onKeyPress();
onPropertyChange();
}
});