From 4cd831ec91e8b949358af2f5eb1b197d226687e7 Mon Sep 17 00:00:00 2001 From: James Harries Date: Tue, 8 Oct 2013 23:41:32 +0100 Subject: [PATCH 1/2] Adding kotoeri support (Japanese text on MacOS) --- fancyInput.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fancyInput.js b/fancyInput.js index b716760..f862e75 100644 --- a/fancyInput.js +++ b/fancyInput.js @@ -120,7 +120,7 @@ $(textCont).html(caret); }, - // insert bulk text (unlike the "writer" fucntion which is for single character only) + // insert bulk text (unlike the "writer" function which is for single character only) fillText : function(text, input){ var charsCont = input.nextElementSibling, newCharElm, @@ -157,7 +157,7 @@ if( range[1] - range[0] == 1 ){ charsToRemove.css('position','absolute'); - if(isWebkit) + if(isWebkit && charsToRemove[0]) charsToRemove[0].offsetLeft; charsToRemove.addClass('deleted'); setTimeout(function(){ @@ -210,7 +210,8 @@ redo = (e.metaKey || e.ctrlKey) && e.keyCode == 89, selectAll = (e.metaKey || e.ctrlKey) && e.keyCode == 65, caretAtEndNoSelection = (this.selectionEnd == this.selectionStart && this.selectionEnd == this.value.length ), - deleteKey = e.keyCode == 46 && !caretAtEndNoSelection; + deleteKey = (e.keyCode == 46 && !caretAtEndNoSelection) || e.keyCode == 8, + kotoeri = e.keyCode == 229; fancyInput.setCaret(this); @@ -227,7 +228,7 @@ // if BACKSPACE or DELETE - if( e.keyCode == 8 || deleteKey ){ + if( deleteKey ){ var selectionRange = [this.selectionStart, this.selectionEnd]; if( charDir.lastDir == 'rtl' ) // BIDI support selectionRange = [this.value.length - this.selectionEnd, this.value.length - this.selectionStart + 1]; @@ -246,6 +247,13 @@ },0); } + if (kotoeri){ + setTimeout( function(){ + fancyInput.fillText(e.target.value, e.target); + }, 50); + return true; + } + // make sure to reset the container scrollLeft when caret is the the START or ar the END if( this.selectionStart == 0 ) this.parentNode.scrollLeft = 0; From e4ae066082901bf6c685d5b44b5a4b90a2941001 Mon Sep 17 00:00:00 2001 From: James Harries Date: Wed, 9 Oct 2013 09:28:10 +0100 Subject: [PATCH 2/2] Adding effect support to kotoeri input --- fancyInput.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/fancyInput.js b/fancyInput.js index f862e75..b732662 100644 --- a/fancyInput.js +++ b/fancyInput.js @@ -143,6 +143,36 @@ charsCont.appendChild(frag); },0); }, + + kotoeri : function (text, input) { + var charsCont = input.nextElementSibling, + newCharElm, + frag = document.createDocumentFragment(); + + fancyInput.clear( input.nextElementSibling ); + + setTimeout( function(){ + var length = text.length; + + for( var i=0; i < length; i++ ){ + var newElm = 'span'; + //fancyInput.writer( text[i], input, i); + if( text[i] == '\n' ) + newElm = 'br'; + newCharElm = document.createElement(newElm); + newCharElm.innerHTML = (text[i] == ' ') ? ' ' : text[i]; + this.classToggler = this.classToggler == 'state2' ? 'state1' : 'state2'; + frag.appendChild(newCharElm); + setTimeout(function(){ + newCharElm.className = this.classToggler; + setTimeout(function(){ + newCharElm.className = ''; + },50); + },0); + } + charsCont.appendChild(frag); + },0); + }, // Handles characters removal from the fake text input removeChars : function(el, range){ @@ -249,7 +279,7 @@ if (kotoeri){ setTimeout( function(){ - fancyInput.fillText(e.target.value, e.target); + fancyInput.kotoeri(e.target.value, e.target); }, 50); return true; }