Skip to content
This repository has been archived by the owner on Jan 20, 2021. It is now read-only.

Adding kotoeri support (Japanese text on MacOS) #28

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions fancyInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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] == ' ') ? '&nbsp;' : 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){
Expand All @@ -157,7 +187,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(){
Expand Down Expand Up @@ -210,7 +240,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);

Expand All @@ -227,7 +258,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];
Expand All @@ -246,6 +277,13 @@
},0);
}

if (kotoeri){
setTimeout( function(){
fancyInput.kotoeri(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;
Expand Down