PageSourceSearch

https://www.chuman.co.jp/common/js/jquery.autoKana.js

js chuman.co.jp collected 2026-10-05 03:41:13 UTC 6,578 bytes, 195 lines download raw bytes

vendor: 6,578 bytes, lines 1-195
1// Copyright (c) 2013 Keith Perhac @ DelfiNet (http://delfi-net.com)
2//
3// Based on the AutoRuby library created by:
4// Copyright (c) 2005-2008 spinelz.org (http://script.spinelz.org/)
5// 
6// Permission is hereby granted, free of charge, to any person obtaining
7// a copy of this software and associated documentation files (the
8// "Software"), to deal in the Software without restriction, including
9// without limitation the rights to use, copy, modify, merge, publish,
10// distribute, sublicense, and/or sell copies of the Software, and to
11// permit persons to whom the Software is furnished to do so, subject to
12// the following conditions:
13// 
14// The above copyright notice and this permission notice shall be
15// included in all copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25(function ($) {
26    $.fn.autoKana = function (element1, element2, passedOptions) {
27
28        var options = $.extend(
29            {
30                'katakana': false
31            }, passedOptions);
32
33        var kana_extraction_pattern = new RegExp('[^  ぁあ-んー]', 'g');
34        var kana_compacting_pattern = new RegExp('[ぁぃぅぇぉっゃゅょ]', 'g');
35        var elName,
36            elKana,
37            active = false,
38            timer = null,
39            flagConvert = true,
40            input;
41
42        elName = $(element1);
43        elKana = $(element2);
44        active = true;
45        _stateClear();
46
47        elName.blur(_eventBlur);
48        elName.focus(_eventFocus);
49        elName.keydown(_eventKeyDown);
50
51        function start() {
52            active = true;
53        };
54
55        function stop() {
56            active = false;
57        };
58
59        function toggle(event) {
60            var ev = event || window.event;
61            if (event) {
62                var el = Event.element(event);
63                if (el.checked) {
64                    active = true;
65                } else {
66                    active = false;
67                }
68            } else {
69                active = !active;
70            }
71        };
72
73        function _checkConvert(new_values) {
74            if (!flagConvert) {
75                if (Math.abs(values.length - new_values.length) > 1) {
76                    var tmp_values = new_values.join('').replace(kana_compacting_pattern, '').split('');
77                    if (Math.abs(values.length - tmp_values.length) > 1) {
78                        _stateConvert();
79                    }
80                } else {
81                    if (values.length == input.length && values.join('') != input) {
82                        if (input.match(kana_extraction_pattern)) {
83                            _stateConvert();
84                        }
85                    }
86                }
87            }
88        };
89
90        function _checkValue() {
91            var new_input, new_values;
92            new_input = elName.val()
93            if (new_input == '') {
94                _stateClear();
95                _setKana();
96            } else {
97                new_input = _removeString(new_input);
98                if (input == new_input) {
99                    return;
100                } else {
101                    input = new_input;
102                    if (!flagConvert) {
103                        new_values = new_input.replace(kana_extraction_pattern, '').split('');
104                        _checkConvert(new_values);
105                        _setKana(new_values);
106                    }
107                }
108            }
109        };
110
111        function _clearInterval() {
112            clearInterval(timer);
113        };
114
115        function _eventBlur(event) {
116            _clearInterval();
117        };
118        function _eventFocus(event) {
119            _stateInput();
120            _setInterval();
121        };
122        function _eventKeyDown(event) {
123            if (flagConvert) {
124                _stateInput();
125            }
126        };
127        function _isHiragana(chara) {
128            return ((chara >= 12353 && chara <= 12435) || chara == 12445 || chara == 12446);
129        };
130        function _removeString(new_input) {
131            if (new_input.match(ignoreString)) {
132                return new_input.replace(ignoreString, '');
133            } else {
134                var i, ignoreArray, inputArray;
135                ignoreArray = ignoreString.split('');
136                inputArray = new_input.split('');
137                for (i = 0; i < ignoreArray.length; i++) {
138                    if (ignoreArray[i] == inputArray[i]) {
139                        inputArray[i] = '';
140                    }
141                }
142                return inputArray.join('');
143            }
144        };
145        function _setInterval() {
146            var self = this;
147            timer = setInterval(_checkValue, 30);
148        };
149        function _setKana(new_values) {
150            if (!flagConvert) {
151                if (new_values) {
152                    values = new_values;
153                }
154                if (active) {
155                    var _val = _toKatakana(baseKana + values.join(''));
156                    elKana.val(_val);
157                }
158            }
159        };
160        function _stateClear() {
161            baseKana = '';
162            flagConvert = false;
163            ignoreString = '';
164            input = '';
165            values = [];
166        };
167        function _stateInput() {
168            baseKana = elKana.val();
169            flagConvert = false;
170            ignoreString = elName.val();
171        };
172        function _stateConvert() {
173            baseKana = baseKana + values.join('');
174            flagConvert = true;
175            values = [];
176        };
177        function _toKatakana(src) {
178            if (options.katakana) {
179                var c, i, str;
180                str = new String;
181                for (i = 0; i < src.length; i++) {
182                    c = src.charCodeAt(i);
183                    if (_isHiragana(c)) {
184                        str += String.fromCharCode(c + 96);
185                    } else {
186                        str += src.charAt(i);
187                    }
188                }
189                return str;
190            } else {
191                return src;
192            }
193        }
194    };
195})(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.