1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
|
var wanakana,__indexOf=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};wanakana=wanakana||{},wanakana.version="1.3.9","function"==typeof define&&define.amd&&define("wanakana",[],function(){return wanakana}),wanakana.LOWERCASE_START=97,wanakana.LOWERCASE_END=122,wanakana.UPPERCASE_START=65,wanakana.UPPERCASE_END=90,wanakana.HIRAGANA_START=12353,wanakana.HIRAGANA_END=12438,wanakana.KATAKANA_START=12449,wanakana.KATAKANA_END=12538,wanakana.LOWERCASE_FULLWIDTH_START=65345,wanakana.LOWERCASE_FULLWIDTH_END=65370,wanakana.UPPERCASE_FULLWIDTH_START=65313,wanakana.UPPERCASE_FULLWIDTH_END=65338,wanakana.defaultOptions={useObseleteKana:!1,IMEMode:!1,convertKatakanaToUppercase:!1},wanakana.bind=function(a){return a.addEventListener("input",wanakana._onInput)},wanakana.unbind=function(a){return a.removeEventListener("input",wanakana._onInput)},wanakana._onInput=function(a){var b,c,d,e,f,g;if(b=a.target,f=b.selectionStart,g=b.value.length,d=wanakana._convertFullwidthCharsToASCII(b.value),c=wanakana.toKana(d,{IMEMode:!0}),d!==c){if(b.value=c,"number"==typeof b.selectionStart)return b.selectionStart=b.selectionEnd=b.value.length;if("undefined"!=typeof b.createTextRange)return b.focus(),e=b.createTextRange(),e.collapse(!1),e.select()}},wanakana._extend=function(a,b){var c;if(null==a)return b;for(c in b)null==a[c]&&null!=b[c]&&(a[c]=b[c]);return a},wanakana._isCharInRange=function(a,b,c){var d;return d=a.charCodeAt(0),d>=b&&c>=d},wanakana._isCharVowel=function(a,b){var c;return null==b&&(b=!0),c=b?/[aeiouy]/:/[aeiou]/,-1!==a.toLowerCase().charAt(0).search(c)},wanakana._isCharConsonant=function(a,b){var c;return null==b&&(b=!0),c=b?/[bcdfghjklmnpqrstvwxyz]/:/[bcdfghjklmnpqrstvwxz]/,-1!==a.toLowerCase().charAt(0).search(c)},wanakana._isCharKatakana=function(a){return wanakana._isCharInRange(a,wanakana.KATAKANA_START,wanakana.KATAKANA_END)},wanakana._isCharHiragana=function(a){return wanakana._isCharInRange(a,wanakana.HIRAGANA_START,wanakana.HIRAGANA_END)},wanakana._isCharKana=function(a){return wanakana._isCharHiragana(a)||wanakana._isCharKatakana(a)},wanakana._isCharNotKana=function(a){return!wanakana._isCharHiragana(a)&&!wanakana._isCharKatakana(a)},wanakana._convertFullwidthCharsToASCII=function(a){var b,c,d,e,f,g;for(c=a.split(""),e=f=0,g=c.length;g>f;e=++f)b=c[e],d=b.charCodeAt(0),wanakana._isCharInRange(b,wanakana.LOWERCASE_FULLWIDTH_START,wanakana.LOWERCASE_FULLWIDTH_END)&&(c[e]=String.fromCharCode(d-wanakana.LOWERCASE_FULLWIDTH_START+wanakana.LOWERCASE_START)),wanakana._isCharInRange(b,wanakana.UPPERCASE_FULLWIDTH_START,wanakana.UPPERCASE_FULLWIDTH_END)&&c[e](String.fromCharCode(d-wanakana.UPPERCASE_FULLWIDTH_START+wanakana.UPPERCASE_START));return c.join("")},wanakana._katakanaToHiragana=function(a){var b,c,d,e,f,g,h;for(c=[],h=a.split(""),f=0,g=h.length;g>f;f++)e=h[f],wanakana._isCharKatakana(e)?(b=e.charCodeAt(0),b+=wanakana.HIRAGANA_START-wanakana.KATAKANA_START,d=String.fromCharCode(b),c.push(d)):c.push(e);return c.join("")},wanakana._hiraganaToKatakana=function(a){var b,c,d,e,f,g,h;for(d=[],h=a.split(""),f=0,g=h.length;g>f;f++)c=h[f],wanakana._isCharHiragana(c)?(b=c.charCodeAt(0),b+=wanakana.KATAKANA_START-wanakana.HIRAGANA_START,e=String.fromCharCode(b),d.push(e)):d.push(c);return d.join("")},wanakana._hiraganaToRomaji=function(a,b){var c,d,e,f,g,h,i,j,k,l,m;for(b=wanakana._extend(b,wanakana.defaultOptions),h=a.length,l=[],f=0,d=0,i=2,g=function(){return a.substr(f,d)},k=function(){return d=Math.min(i,h-f)};h>f;){for(e=!1,k();d>0;){if(c=g(),wanakana.isKatakana(c)&&(e=b.convertKatakanaToUppercase,c=wanakana._katakanaToHiragana(c)),"っ"===c.charAt(0)&&1===d&&h-1>f){j=!0,m="";break}if(m=wanakana.J_to_R[c],null!=m&&j&&(m=m.charAt(0).concat(m),j=!1),null!=m)break;d--}null==m&&(m=c),e&&(m=m.toUpperCase()),l.push(m),f+=d||1}return l.join("")},wanakana._romajiToHiragana=function(a,b){return wanakana._romajiToKana(a,b,!0)},wanakana._romajiToKana=function(a,b,c){var d,e,f,g,h,i,j,k,l,m;for(null==c&&(c=!1),b=wanakana._extend(b,wanakana.defaultOptions),l=a.length,j=[],g=0,m=3,h=fun
|