PageSourceSearch

https://www.menkyo.jp/common_form/js/jquery.autoKana.js

js menkyo.jp collected 2026-10-09 22:47:18 UTC 6,480 bytes, 193 lines download raw bytes

vendor: 6,480 bytes, lines 1-193
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                        _stateConvert();
83                    }
84                }
85            }
86        };
87
88        function _checkValue() {
89            var new_input, new_values;
90            new_input = elName.val()
91            if (new_input == '') {
92                _stateClear();
93                _setKana();
94            } else {
95                new_input = _removeString(new_input);
96                if (input == new_input) {
97                    return;
98                } else {
99                    input = new_input;
100                    if (!flagConvert) {
101                        new_values = new_input.replace(kana_extraction_pattern, '').split('');
102                        _checkConvert(new_values);
103                        _setKana(new_values);
104                    }
105                }
106            }
107        };
108
109        function _clearInterval() {
110            clearInterval(timer);
111        };
112
113        function _eventBlur(event) {
114            _clearInterval();
115        };
116        function _eventFocus(event) {
117            _stateInput();
118            _setInterval();
119        };
120        function _eventKeyDown(event) {
121            if (flagConvert) {
122                _stateInput();
123            }
124        };
125        function _isHiragana(chara) {
126            return ((chara >= 12353 && chara <= 12435) || chara == 12445 || chara == 12446);
127        };
128        function _removeString(new_input) {
129            if (new_input.match(ignoreString)) {
130                return new_input.replace(ignoreString, '');
131            } else {
132                var i, ignoreArray, inputArray;
133                ignoreArray = ignoreString.split('');
134                inputArray = new_input.split('');
135                for (i = 0; i < ignoreArray.length; i++) {
136                    if (ignoreArray[i] == inputArray[i]) {
137                        inputArray[i] = '';
138                    }
139                }
140                return inputArray.join('');
141            }
142        };
143        function _setInterval() {
144            var self = this;
145            timer = setInterval(_checkValue, 30);
146        };
147        function _setKana(new_values) {
148            if (!flagConvert) {
149                if (new_values) {
150                    values = new_values;
151                }
152                if (active) {
153                    var _val = _toKatakana(baseKana + values.join(''));
154                    elKana.val(_val);
155                }
156            }
157        };
158        function _stateClear() {
159            baseKana = '';
160            flagConvert = false;
161            ignoreString = '';
162            input = '';
163            values = [];
164        };
165        function _stateInput() {
166            baseKana = elKana.val();
167            flagConvert = false;
168            ignoreString = elName.val();
169        };
170        function _stateConvert() {
171            baseKana = baseKana + values.join('');
172            flagConvert = true;
173            values = [];
174        };
175        function _toKatakana(src) {
176            if (options.katakana) {
177                var c, i, str;
178                str = new String;
179                for (i = 0; i < src.length; i++) {
180                    c = src.charCodeAt(i);
181                    if (_isHiragana(c)) {
182                        str += String.fromCharCode(c + 96);
183                    } else {
184                        str += src.charAt(i);
185                    }
186                }
187                return str;
188            } else {
189                return src;
190            }
191        }
192    };
193})(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.