diff --git a/Editor.js b/Editor.js index 7b827fa5..959d9773 100644 --- a/Editor.js +++ b/Editor.js @@ -1,86 +1,3 @@ -function TextInput(parentNode, host) { - - var text = document.createElement("textarea"); - var style = text.style; - style.position = "absolute"; - style.left = "-10000px"; - style.top = "-10000px"; - parentNode.appendChild(text); - - var inCompostion = false; - - var onTextInput = function(e) { - setTimeout(function() { - if (!inCompostion) { - if (text.value) host.onTextInput(text.value); - text.value = ""; - } - }, 0) - } - - var onCompositionStart = function(e) - { - inCompostion = true; - - if (text.value) host.onTextInput(text.value); - text.value = ""; - - host.onCompositionStart(); - setTimeout(onCompositionUpdate, 0); - } - - var onCompositionUpdate = function() { - host.onCompositionUpdate(text.value); - } - - var onCompositionEnd = function() - { - inCompostion = false; - host.onCompositionEnd(); - onTextInput(); - } - - var onCopy = function() { - text.value = host.getCopyText(); - text.select(); - } - - var onCut = function() { - text.value = host.getCopyText(); - host.onCut(); - text.select(); - } - - addListener(text, "keypress", onTextInput, false); - addListener(text, "textInput", onTextInput, false); - addListener(text, "paste", onTextInput, false); - addListener(text, "propertychange", onTextInput, false); - - addListener(text, "copy", onCopy, false); - addListener(text, "cut", onCut, false); - - addListener(text, "compositionstart", onCompositionStart, false); - addListener(text, "compositionupdate", onCompositionUpdate, false); - addListener(text, "compositionend", onCompositionEnd, false); - - addListener(text, "blur", function() { - host.onBlur(); - }, false); - - addListener(text, "focus", function() { - host.onFocus(); - }, false); - - - this.focus = function() { - text.focus(); - } - - this.blur = function() { - this.blur(); - } -}; - var keys = { UP: 38, RIGHT: 39, diff --git a/TextInput.js b/TextInput.js new file mode 100644 index 00000000..c4ffb03b --- /dev/null +++ b/TextInput.js @@ -0,0 +1,82 @@ +function TextInput(parentNode, host) { + + var text = document.createElement("textarea"); + var style = text.style; + style.position = "absolute"; + style.left = "-10000px"; + style.top = "-10000px"; + parentNode.appendChild(text); + + var inCompostion = false; + + var onTextInput = function(e) { + setTimeout(function() { + if (!inCompostion) { + if (text.value) host.onTextInput(text.value); + text.value = ""; + } + }, 0) + } + + var onCompositionStart = function(e) + { + inCompostion = true; + + if (text.value) host.onTextInput(text.value); + text.value = ""; + + host.onCompositionStart(); + setTimeout(onCompositionUpdate, 0); + } + + var onCompositionUpdate = function() { + host.onCompositionUpdate(text.value); + } + + var onCompositionEnd = function() + { + inCompostion = false; + host.onCompositionEnd(); + onTextInput(); + } + + var onCopy = function() { + text.value = host.getCopyText(); + text.select(); + } + + var onCut = function() { + text.value = host.getCopyText(); + host.onCut(); + text.select(); + } + + addListener(text, "keypress", onTextInput, false); + addListener(text, "textInput", onTextInput, false); + addListener(text, "paste", onTextInput, false); + addListener(text, "propertychange", onTextInput, false); + + addListener(text, "copy", onCopy, false); + addListener(text, "cut", onCut, false); + + addListener(text, "compositionstart", onCompositionStart, false); + addListener(text, "compositionupdate", onCompositionUpdate, false); + addListener(text, "compositionend", onCompositionEnd, false); + + addListener(text, "blur", function() { + host.onBlur(); + }, false); + + addListener(text, "focus", function() { + host.onFocus(); + }, false); + + + this.focus = function() { + text.focus(); + } + + this.blur = function() { + this.blur(); + } +}; \ No newline at end of file diff --git a/editor.html b/editor.html index f39218f8..7c6ab42a 100644 --- a/editor.html +++ b/editor.html @@ -24,6 +24,7 @@ +