PageSourceSearch

https://benridesu.jp/contents/js/lib/jquery.autoKana_eltexCustomize.js

js benridesu.jp collected 2026-10-08 14:05:31 UTC 6,926 bytes, 203 lines download raw bytes

vendor: 4,885 bytes, lines 1-139
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/*! 2021/02 eltex.co.jp 廃止や非推奨になったメソッドなどを更新。 */
25
26(function ($) {
27    $.fn.autoKana = function (element1, element2, passedOptions) {
28
29        var options = $.extend(
30            {
31                'katakana': false
32            }, passedOptions);
33
34        var kana_extraction_pattern = new RegExp('[^  ぁあ-んー]', 'g');
35        var kana_compacting_pattern = new RegExp('[ぁぃぅぇぉっゃゅょ]', 'g');
36        var elName,
37            elKana,
38            active = false,
39            timer = null,
40            flagConvert = true,
41            input,
42            values,
43            ignoreString,
44            baseKana;
45
46        elName = $(element1);
47        elKana = $(element2);
48        active = true;
49        _stateClear();
50
51        elName.on('blur', _eventBlur);
52        elName.on('focus', _eventFocus);
53        elName.on('keydown', _eventKeyDown);
54
55        function start() {
56            active = true;
57        };
58
59        function stop() {
60            active = false;
61        };
62
63        function toggle(event) {
64            var ev = event || window.event;
65            if (event) {
66                var el = Event.element(event);
67                if (el.checked) {
68                    active = true;
69                } else {
70                    active = false;
71                }
72            } else {
73                active = !active;
74            }
75        };
76
77        function _checkConvert(new_values) {
78            if (!flagConvert) {
79                if (Math.abs(values.length - new_values.length) > 1) {
80                    var tmp_values = new_values.join('').replace(kana_compacting_pattern, '').split('');
81                    if (Math.abs(values.length - tmp_values.length) > 1) {
82                        _stateConvert();
83                    }
84                } else {
85                    if (values.length == input.length && values.join('') != input) {
86                        if (input.match(kana_extraction_pattern)) {
87                            _stateConvert();
88                        }
89                    }
90                }
91            }
92        };
93
94        function _checkValue() {
95            var new_input, new_values;
96            new_input = elName.val()
97            if (new_input == '') {
98                _stateClear();
99                _setKana();
100            } else {
101                new_input = _removeString(new_input);
102                if (input == new_input) {
103                    return;
104                } else {
105                    input = new_input;
106                    if (!flagConvert) {
107                        new_values = new_input.replace(kana_extraction_pattern, '').split('');
108                        _checkConvert(new_values);
109                        _setKana(new_values);
110                    }
111                }
112            }
113        };
114
115        function _clearInterval() {
116            clearInterval(timer);
117        };
118
119        function _eventBlur(event) {
120            _clearInterval();
121           // blurのアクションを定義可能
122           if(typeof options.blurAction == 'function') {
123                 options.blurAction(elName, elKana);
124           }
125        };
126        function _eventFocus(event) {
127            _stateInput();
128            _setInterval();
129        };
130        function _eventKeyDown(event) {
131            if (flagConvert) {
132                _stateInput();
133            }
134        };
135        function _isHiragana(chara) {
136            return ((chara >= 12353 && chara <= 12435) || chara == 12445 || chara == 12446);
137        };
138        function _removeString(new_input) {
139            if (new_input.match(ignoreString)
vendor: 2,041 bytes, lines 139-203
139) {
140                return new_input.replace(ignoreString, '');
141            } else {
142                var i, ignoreArray, inputArray;
143                ignoreArray = ignoreString.split('');
144                inputArray = new_input.split('');
145                for (i = 0; i < ignoreArray.length; i++) {
146                    if (ignoreArray[i] == inputArray[i]) {
147                        inputArray[i] = '';
148                    }
149                }
150                return inputArray.join('');
151            }
152        };
153        function _setInterval() {
154            var self = this;
155            timer = setInterval(_checkValue, 30);
156        };
157        function _setKana(new_values) {
158            if (!flagConvert) {
159                if (new_values) {
160                    values = new_values;
161                }
162                if (active) {
163                    var _val = _toKatakana(baseKana + values.join(''));
164                    elKana.val(_val);
165                }
166            }
167        };
168        function _stateClear() {
169            baseKana = '';
170            flagConvert = false;
171            ignoreString = '';
172            input = '';
173            values = [];
174        };
175        function _stateInput() {
176            baseKana = elKana.val();
177            flagConvert = false;
178            ignoreString = elName.val();
179        };
180        function _stateConvert() {
181            baseKana = baseKana + values.join('');
182            flagConvert = true;
183            values = [];
184        };
185        function _toKatakana(src) {
186            if (options.katakana) {
187                var c, i, str;
188                str = new String;
189                for (i = 0; i < src.length; i++) {
190                    c = src.charCodeAt(i);
191                    if (_isHiragana(c)) {
192                        str += String.fromCharCode(c + 96);
193                    } else {
194                        str += src.charAt(i);
195                    }
196                }
197                return str;
198            } else {
199                return src;
200            }
201        }
202    };
203})(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.