1// â»Macæã®ç¬èªã®å¦çããããã䏿¸ãããéã¯æ³¨æãã¦ãã ãã!! 2 3// Copyright (c) 2013 Keith Perhac @ DelfiNet (http://delfi-net.com) 4// 5// Based on the AutoRuby library created by: 6// Copyright (c) 2005-2008 spinelz.org (http://script.spinelz.org/) 7// 8// Permission is hereby granted, free of charge, to any person obtaining 9// a copy of this software and associated documentation files (the 10// "Software"), to deal in the Software without restriction, including 11// without limitation the rights to use, copy, modify, merge, publish, 12// distribute, sublicense, and/or sell copies of the Software, and to 13// permit persons to whom the Software is furnished to do so, subject to 14// the following conditions: 15// 16// The above copyright notice and this permission notice shall be 17// included in all copies or substantial portions of the Software. 18// 19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 27(function ($) { 28 $.fn.autoKana = function (element1, element2, passedOptions) { 29 30 // Macæã®å¦ç䏿¸ã注æ 31 var ua = navigator.userAgent.toLowerCase(); 32 var isMac = ((ua.indexOf("mac") > -1) && (ua.indexOf("os") > -1)) && !((ua.indexOf("iphone") > -1) || (ua.indexOf("ipad") > -1) || (ua.indexOf("windows") > -1)); 33 34 var options = $.extend( 35 { 36 "katakana": false 37 }, passedOptions); 38 39 var kanaExtractionPattern = new RegExp("[^ ããã-ãã¼]", "g"); 40 var kanaCompactingPattern = new RegExp("[ããã ããã£ãã ã]", "g"); 41 var elName, 42 elKana, 43 active = false, 44 timer = null, 45 flagConvert = true, 46 input, 47 romanChar, 48 values, 49 ignoreString, 50 baseKana; 51 52 elName = $(element1); 53 elKana = $(element2); 54 active = true; 55 stateClear(); 56 57 if (isMac) { 58 elName.keyup(eventKeyUp); 59 } else { 60 elName.blur(eventBlur); 61 elName.focus(eventFocus); 62 elName.keydown(eventKeyDown); 63 } 64 65 function checkConvert(newValues) { 66 if (!flagConvert) { 67 if (Math.abs(values.length - newValues.length) > 1) { 68 var tmpValues = newValues.join("").replace(kanaCompactingPattern, "").split(""); 69 if (Math.abs(values.length - tmpValues.length) > 1) { 70 stateConvert(); 71 } 72 } else { 73 if (values.length === input.length && values.join("") !== input) { 74 if (input.match(kanaExtractionPattern)) { 75 stateConvert(); 76 } 77 } 78 } 79 } 80 }; 81 82 function checkValue() { 83 var newInput, newValues; 84 newInput = elName.val(); 85 if (newInput === "") { 86 stateClear(); 87 setKana(); 88 } else { 89 newInput = removeString(newInput); 90 if (input === newInput) { 91 return; 92 } else { 93 input = newInput; 94 if (!flagConvert) { 95 newValues = newInput.replace(kanaExtractionPattern, "").split(""); 96 checkConvert(newValues); 97 setKana(newValues); 98 } 99 } 100 } 101 }; 102 103 function resetInterval() { 104 clearInterval(timer); 105 }; 106 107 function eventBlur(event) { 108 resetInterval(); 109 }; 110 function eventFocus(event) { 111 stateInput(); 112 startInterval(); 113 }; 114 function eventKeyDown(event) { 115 if (flagConvert) { 116 stateInput(); 117 } 118 }; 119 120 // Macæã®å¦ç䏿¸ã注æ 121 function eventKeyUp(event) {// ãã¼ãã¼ãå ¥åãè¡ãããå ´å(ãã¼ãå ¥åããããæ¯åº¦è¡ã) 122 123 var realTimeKeyCode = event.keyCode;// ãã¼ã³ã¼ããæå¾ 124 if (65 <= realTimeKeyCode && realTimeKeyCode <= 90) { 125 romanChar += String.fromCharCode(realTimeKeyCode)// ãã¼ãåãå ¥ã(a-z) 126 } else if (realTimeKeyCode === 8 && elName.val() === "") {// TextBoxã®ä¸èº«ã空ã«ãªã£ãå ´å 127 romanChar = ""; 128 elKana.val(""); 129 } else if (realTimeKeyCode === 13) {// Enterãæ¼ãããå ´å 130 romanChar = ""; 131 } 132 if (romanChar) { 133 var newValues = romanToHiragana(romanChar.toLowerCase());
133// ãã¼ãåããã²ãããªã¸å¤æãã¦ãã 134 if (newValues.match(/^[ã-ãã¼ã]+$/)) {// ã²ãããªãå ¥ã£ã¦ããããã§ãã¯ã¯ãã¦ãããsetKanaãè¡ã 135 setKanaMac(newValues); 136 romanChar = ""; 137 } 138 } 139 }; 140 function isHiragana(chara) { 141 return ((chara >= 12353 && chara <= 12435) || chara == 12445 || chara == 12446); 142 }; 143 function removeString(newInput) { 144 if (newInput.indexOf(ignoreString) !== -1) { 145 return newInput.replace(ignoreString, ""); 146 } else { 147 var i; 148 var ignoreArray = ignoreString.split(""); 149 var inputArray = newInput.split(""); 150 for (i = 0; i < ignoreArray.length; i++) { 151 if (ignoreArray[i] === inputArray[i]) { 152 inputArray[i] = ""; 153 } 154 } 155 return inputArray.join(""); 156 } 157 }; 158 function startInterval() { 159 var self = this; 160 timer = setInterval(checkValue, 30); 161 }; 162 function setKana(newValues) { 163 if (!flagConvert) { 164 if (newValues) { 165 values = newValues; 166 } 167 if (active) { 168 var _val = toKatakana(baseKana + values.join("")); 169 elKana.val(_val); 170 } 171 } 172 }; 173 // Macæã®å¦ç䏿¸ã注æ 174 function setKanaMac(newValues) { 175 baseKana = elKana.val(); 176 var values = toKatakana(baseKana + newValues); 177 elKana.val(values); 178 }; 179 function stateClear() { 180 baseKana = ""; 181 flagConvert = false; 182 ignoreString = ""; 183 input = ""; 184 romanChar = ""; 185 values = []; 186 }; 187 function stateInput() { 188 baseKana = elKana.val(); 189 flagConvert = false; 190 ignoreString = elName.val(); 191 }; 192 function stateConvert() { 193 baseKana = baseKana + values.join(""); 194 flagConvert = true; 195 values = []; 196 }; 197 function toKatakana(src) { 198 if (options.katakana) { 199 var c, i, str; 200 str = new String; 201 for (i = 0; i < src.length; i++) { 202 c = src.charCodeAt(i); 203 if (isHiragana(c)) { 204 str += String.fromCharCode(c + 96); 205 } else { 206 str += src.charAt(i); 207 } 208 } 209 return str; 210 } else { 211 return src; 212 } 213 } 214 // Macæã®å¦ç䏿¸ã注æ 215 var hiraganaBox = { 216 "a": "ã", "i": "ã", "u": "ã", "e": "ã", "o": "ã", 217 "ka": "ã", "ki": "ã", "ku": "ã", "ke": "ã", "ko": "ã", 218 "sa": "ã", "si": "ã", "su": "ã", "se": "ã", "so": "ã", 219 "ta": "ã", "ti": "ã¡", "tu": "ã¤", "te": "ã¦", "to": "ã¨", "chi": "ã¡", "tsu": "ã¤", 220 "na": "ãª", "ni": "ã«", "nu": "ã¬", "ne": "ã", "no": "ã®", 221 "ha": "ã¯", "hi": "ã²", "hu": "ãµ", "he": "ã¸", "ho": "ã»", "fu": "ãµ", 222 "ma": "ã¾", "mi": "ã¿", "mu": "ã", "me": "ã", "mo": "ã", 223 "ya": "ã", "yi": "ã", "yu": "ã", "ye": "ãã", "yo": "ã", 224 "ra": "ã", "ri": "ã", "ru": "ã", "re": "ã", "ro": "ã", 225 "wa": "ã", "wyi": "ã", "wu": "ã", "wye": "ã", "wo": "ã", 226 "nn": "ã", 227 "ga": "ã", "gi": "ã", "gu": "ã", "ge": "ã", "go": "ã", 228 "za": "ã", "zi": "ã", "zu": "ã", "ze": "ã", "zo": "ã", "ji": "ã", 229 "da": "ã ", "di": "ã¢", "du": "ã¥", "de": "ã§", "do": "ã©", 230 "ba": "ã°", "bi": "ã³", "bu": "ã¶", "be": "ã¹", "bo": "ã¼", 231 "pa": "ã±", "pi": "ã´", "pu": "ã·", "pe": "ãº", "po": "ã½", 232 "kya": "ãã", "kyu": "ãã ", "kyo": "ãã", 233 "sya": "ãã", "syu": "ãã ", "syo": "ãã", 234 "tya": "ã¡ã", "tyi": "ã¡ã", "tyu": "ã¡ã ", "tye": "ã¡ã", "tyo": "ã¡ã", "cha": "ã¡ã", "chu": "ã¡ã ", "che": "ã¡ã", "cho": "ã¡ã", 235 "nya": "ã«ã", "nyi": "ã«ã", "nyu": "ã«ã ", "nye": "ã«ã", "nyo": "ã«ã", 236 "hya": "ã²ã", "hyi": "ã²ã", "hyu": "ã²ã ", "hye": "ã²ã", "hyo": "ã²ã", 237 "mya": "ã¿ã", "myi": "ã¿ã", "myu": "ã¿ã ", "mye": "ã¿ã", "myo": "ã¿ã", 238 "rya": "ãã", "ryi": "ãã", "ryu": "ãã ", "rye": "ãã", "ryo": "ãã", 239 "gya": "ãã", "gyi": "ãã", "gyu": "ãã ", "gye": "ãã", "gyo": "ãã", 240 "zya": "ãã", "zyi": "ãã", "zyu": "ãã ", "zye": "ãã", "zyo": "ãã", 241 "ja": "ãã", "ju": "ãã ", "je": "ãã", "jo": "ãã", "jya": "ãã", "jyi": "ãã", "jyu": "ãã ", "jye": "ãã", "jyo": "ãã", 242 "dya": "ã¢ã", "dyi": "ã¢ã", "dyu": "ã¢ã ", "dye": "ã¢ã", "dyo": "ã¢ã", 243 "bya": "ã³ã", "byi": "ã³ã", "byu": "ã³ã ", "bye": "ã³ã", "byo": "ã³ã", 244 "pya": "ã´ã", "pyi": "ã´ã", "pyu": "ã´ã ", "pye": "ã´ã", "pyo": "ã´ã", 245 "fa": "ãµã", "fi": "ãµã", "fe": "ãµã", "fo": "ãµã", 246 "fya": "ãµã", "fyu": "ãµã ", "fyo": "ãµã", 247 "xa": "ã", "xi": "ã", "xu": "ã ", "xe": "ã", "xo": "ã", "la": "ã", "li": "ã", "lu": "ã ", "le": "ã", "lo": "ã", 248 "xya": "ã", "xyu": "ã ", "xyo": "ã", 249 "xtu": "ã£", "xtsu": "ã£", 250 "wi": "ãã", "we": "ãã", 251 "va": "ã´ã", "vi": "ã´ã", "vu": "ã´", "ve": "ã´ã", "vo": "ã´ã" 252 }; 253 // Macæã®å¦ç䏿¸ã注æ 254 function romanToHiragana(roman) { 255 var i, iz, match, regex, 256 hiragana = "", table = hiraganaBox; 257 258 regex = new RegExp((function (table) { 259 var key, 260 s = "^(?:"; 261 262 for (key in table) if (table.hasOwnProperty(key)) { 263 s += key + "|"; 264 }
265 return s + "(?:n(?![aiueo]|y[aiueo]|$))|" + "([^aiueon])\\1)"; 266 })(table)); 267 for (i = 0, iz = roman.length; i < iz; ++i) { 268 if (match = roman.slice(i).match(regex)) { 269 if (match[0] === "n") { 270 hiragana += "ã"; 271 } else if (/^([^n])\1$/.test(match[0])) { 272 hiragana += "ã£"; 273 --i; 274 } else { 275 hiragana += table[match[0]]; 276 } 277 i += match[0].length - 1; 278 } else { 279 hiragana += roman[i]; 280 } 281 } 282 return hiragana; 283 }; 284 }; 285})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.