PageSourceSearch

https://www.casamil.ce.gov.br/wp-content/themes/ceara2017/Keyboard…ery.keyboard.extension-typing.js?1697601668

js casamil.ce.gov.br collected 2026-10-08 20:31:39 UTC 12,137 bytes, 329 lines download raw bytes

1/*! jQuery UI Virtual Keyboard Typing Simulator v1.10.2 *//*
2 * for Keyboard v1.18+ only (1/10/2016)
3 *
4 * By Rob Garrison (aka Mottie & Fudgey)
5 * Licensed under the MIT License
6 *
7 * Use this extension with the Virtual Keyboard to simulate
8 * typing for tutorials or whatever else use you can find
9 *
10 * Requires:
11 *  jQuery
12 *  Keyboard plugin : https://github.com/Mottie/Keyboard
13 *
14 * Setup:
15 *  $('.ui-keyboard-input')
16 *   .keyboard(options)
17 *   .addTyping(typing-options);
18 *
19 *  // or if targeting a specific keyboard
20 *  $('#keyboard1')
21 *   .keyboard(options)
22 *   .addTyping(typing-options);
23 *
24 * Basic Usage:
25 *  // To disable manual typing on the virtual keyboard, just set "showTyping" option to false
26 *  $('#keyboard-input').keyboard(options).addTyping({ showTyping: false });
27 *
28 *  // Change the default typing delay (time the virtual keyboard highlights the manually typed key) - default = 250 milliseconds
29 *  $('#keyboard-input').keyboard(options).addTyping({ delay: 500 });
30 *
31 *  // get keyboard object, open it, then start typing simulation
32 *  $('#keyboard-input').getkeyboard().reveal().typeIn('Hello World', 700);
33 *
34 *  // get keyboard object, open it, type in "This is a test" with 700ms delay between types, then accept & close the keyboard
35 *  $('#keyboard-input').getkeyboard().reveal().typeIn('This is a test', 700, function(){ $('#keyboard-input').getkeyboard().close(true); });
36 */
37
38// EXAMPLES:
39// $('#inter').getkeyboard().reveal().typeIn('\tHello \b\n\tWorld', 500);
40// $('#meta').getkeyboard().reveal().typeIn('abCDd11123\u2648\u2649\u264A\u264B', 700, function(){ alert('all done!'); });
41/*jshint browser:true, jquery:true, unused:false */
42/*global require:false, define:false, module:false */
43;(function(factory) {
44	if (typeof define === 'function' && define.amd) {
45		define(['jquery'], factory);
46	} else if (typeof module === 'object' && typeof module.exports === 'object') {
47		module.exports = factory(require('jquery'));
48	} else {
49		factory(jQuery);
50	}
51}(function($) {
52	$.fn.addTyping = function(options){
53		//Set the default values, use comma to separate the settings, example:
54		var defaults = {
55			showTyping : true,
56			lockTypeIn : false,
57			delay      : 250
58		},
59		$keyboard = $.keyboard;
60		return this.each(function(){
61			// make sure a keyboard is attached
62			var o, base = $(this).data('keyboard');
63			if (!base) { return; }
64
65			// variables
66			o = base.typing_options = $.extend({}, defaults, options);
67			base.typing_keymap = {
68				' '   : 'space',
69				'"'   : '34',
70				"'"   : '39',
71				' ' : 'space',
72				'\b'  : 'bksp', // delete character to the left
73				'{b}' : 'bksp',
74				'{d}' : 'del',  // delete character to the right
75				'{l}' : 'left', // move caret left
76				'{r}' : 'right', // move caret right
77				'\n'  : 'enter',
78				'\r'  : 'enter',
79				'{e}' : 'enter',
80				'\t'  : 'tab',
81				'{t}' : 'tab'
82			};
83			base.typing_xref = {
84				8  : 'bksp',
85				9  : 'tab',
86				13 : 'enter',
87				32 : 'space',
88				37 : 'left',
89				39 : 'right',
90				46 : 'del'
91			};
92			base.typing_event = false;
93			base.typing_namespace = base.namespace + 'typing';
94			base.extensionNamespace.push( base.typing_namespace );
95			// save lockInput setting
96			o.savedLockInput = base.options.lockInput;
97
98			base.typing_setup = function(){
99				var kbevents = $keyboard.events,
100					namespace = base.typing_namespace;
101				base.$el
102					.unbind( namespace )
103					.bind([ kbevents.kbHidden, kbevents.kbInactive, '' ].join( namespace + ' ' ), function(e){
104						base.typing_reset();
105					})
106					.bind( $keyboard.events.kbBeforeVisible + namespace, function(){
107						base.typing_setup();
108					});
109				base.$allKeys
110					.unbind( namespace )
111					.bind('mousedown' + namespace, function(){
112						base.typing_reset();
113					});
114				base.$preview
115				.unbind( namespace )
116				.bind('keyup' + namespace, function(e){
117					if (o.init && o.lockTypeIn) { return false; }
118					if (e.which >= 37 && e.which <=40) { return; } // ignore arrow keys
119					if (e.which === 16) { base.shiftActive = false; }
120					if (e.which === 18) { base.altActive = false; }
121					if (e.which === 16 || e.which === 18) {
122						base.showSet();
123						// Alt key will shift focus to the menu - doesn't work in Windows
124						setTimeout(function(){ base.$preview.focus(); }, 200);
125						return;
126					}
127				})
128				// change keyset when either shift or alt is held down
129				.bind('keydown' + namespace, function(e){
130					if (o.init && o.lockTypeIn) { return false; }
131					e.temp = false; // prevent repetitive calls while keydown repeats.
132					if (e.which === 16) { e.temp = !base.shiftActive; base.shiftActive = true; }
133					// it should be ok to reset e.temp, since both alt and shift will call this function separately
134					if (e.which === 18) { e.temp = !base.altActive; base.altActive = true; }
135					if (e.temp) {
136						base.showSet();
137						base.$preview.focus(); // Alt shift focus to the menu
138					}
139					base.typing_event = true;
140					// Simulate key press for tab and backspace since they don't fire the keypress event
141					if (base.typing_xref[e.which]) {
142						base.typing_findKey( '', e ); // pass event object
143					}
144
145				})
146				.bind('keypress' + namespace, function(e){
147					if (o.init && o.lockTypeIn) { return false; }
148					// Simulate key press on virtual keyboard
149					if (base.typing_event && !base.options.lockInput) {
150						base.typing_reset();
151						base.typing_event = true;
152						base.typing_findKey( '', e ); // pass event object
153					}
154				});
155			};
156
157			base.typing_reset = function(){
158				base.typing_event = o.init = false;
159				o.text = '';
160				o.len = o.current = 0;
161				base.options.lockInput = o.savedLockInput;
162				// clearTimeout(base.typing_timer);
163			};
164
165			// Store typing text
166			base.typeIn = function(txt, delay, callback, e){
167				if (!base.isVisible()) {
168					// keyboard was closed
169					clearTimeout(base.typing_timer);
170					base.typing_reset();
171					return;
172				}
173				if (!base.typing_event){
174
175					if (o.init !== true) {
176						o.init = true;
177						base.options.lockInput = o.lockTypeIn;
178						o.text = txt || o.text || '';
179						o.len = o.text.length;
180						o.delay = delay || 300;
181						o.current = 0; // position in text string
182						if (callback) {
183							o.callback = callback;
184						}
185					}
186					// function that loops through and types each character
187					txt = o.text.substring( o.current, ++o.current );
188					// add support for curly-wrapped single character: {l}, {r}, {d}, etc.
189					if ( txt === '{' && o.text.substring( o.current + 1, o.current + 2 ) === '}' ) {
190						txt += o.text.substring( o.current, o.current += 2 );
191					}
192					base.typing_findKey( txt, e );
193				} else if (typeof txt === 'undefined') {
194					// typeIn called by user input
195					base.typing_event = false;
196					base.options.lockInput = o.savedLockInput;
197					return;
198				}
199
200			};
201
202			base.typing_findKey = function(txt, e){
203				var tar, m, n, k, key, ks, meta, set,
204					kbcss = $keyboard.css,
205					mappedKeys = $keyboard.builtLayouts[base.layout].mappedKeys;
206				// stop if keyboard is closed
207				if ( !base.isOpen || !base.$keyboard.length ) { return; }
208				ks = base.$keyboard.find('.' + kbcss.keySet);
209				k = txt in base.typing_keymap ? base.typing_keymap[txt] : txt;
210				// typing_event is true when typing on the actual keyboard - look for actual key
211				// All of this breaks when the CapLock is on... unable to find a cross-browser method that works.
212				tar = '.' + kbcss.keyButton + '[data-action="' + k + '"]';
213				if (base.typing_event && e) {
214					// xref used for keydown ( 46 = delete in keypress & period on keydown )
215					if (e.type !== 'keypress' && base.typing_xref.hasOwnProperty(e.keyCode || e.which)) {
216						// special named keys: bksp, tab and enter
217						tar = '.' + kbcss.keyPrefix + base.processName( base.typing_xref[e.keyCode || e.which] );
218					} else {
219						m = String.fromCharCode(e.charCode || e.which);
220						tar = (mappedKeys.hasOwnProperty(m)) ?
221							'.' + kbcss.keyButton + '[data-value="' + mappedKeys[m].replace(/"/g, '\\"') + '"]' :
222							'.' + kbcss.keyPrefix + base.processName( m );
223					}
224				}
225				// find key
226				key = ks.filter(':visible').find(tar);
227				if (key.length) {
228					// key is visible, simulate typing
229					base.typing_simulateKey(key, txt, e);
230				} else {
231					// key not found, check if it is in the keymap (tab, space, enter, etc)
232					if (base.typing_event) {
233						key = ks.find(tar);
234					} else {
235						// key not found, check if it is in the keymap (tab, space, enter, etc)
236						n = txt in base.typing_keymap ? base.typing_keymap[txt] : base.processName( txt );
237						// find actual key on keyboard
238						key = ks.find('.' + kbcss.keyPrefix + n);
239					}
240					// find the keyset
241					set = key.closest('.' + kbcss.keySet);
242					// figure out which keyset the key is in then simulate clicking on that meta key, then on the key
243					if (set.attr('name')) {
244						// get meta key name
245						meta = set.attr('name');
246						// show correct key set
247						base.shiftActive = /shift/.test(meta);
248						base.altActive = /alt/.test(meta);
249						base.metaActive = base.last.keyset[2] = (meta).match(/meta\d+/) || false;
250						// make the plugin think we're passing it a jQuery object with a name
251						base.showSet( base.metaActive );
252						// Add the key
253						base.typing_simulateKey(key, txt, e);
254					} else {
255						if (!base.typing_event) {
256							// Key doesn't exist on the keyboard, so just enter it
257							if (txt in base.typing_keymap && base.typing_keymap[txt] in $keyboard.keyaction) {
258								$keyboard.keyaction[base.typing_keymap[txt]](base, key, e);
259							} else {
260								base.insertText(txt);
261							}
262							base.checkCombos();
263							base.$el.trigger( $keyboard.events.kbChange, [ base, base.el ] );
264						}
265					}
266
267				}
268
269				if (o.current <= o.len && o.len !== 0){
270					if (!base.isVisible()) { return; }
270 // keyboard was closed, abort!!
271					setTimeout(function(){ base.typeIn(); }, o.delay);
272				} else if (o.len !== 0){
273					// o.len is zero when the user typed on the actual keyboard during simulation
274					base.typing_reset();
275					if ($.isFunction(o.callback)) {
276						// ensure all typing animation is done before the callback
277						setTimeout(function(){
278							// if the user typed during the key simulation, the "o" variable may sometimes be undefined
279							if ($.isFunction(o.callback)) {
280								o.callback(base);
281							}
282						}, o.delay);
283					}
284					return;
285				} else {
286					base.typing_reset();
287				}
288			};
289
290			// mouseover the key, add the text directly, then mouseout on the key
291			base.typing_simulateKey = function(el, txt, e){
292				var len = el.length;
293				if (len) { el.filter(':visible').trigger('mouseenter' + base.namespace); }
294				base.typing_timer = setTimeout(function(){
295					var len = el.length;
296					if (len) { setTimeout(function(){ el.trigger('mouseleave' + base.namespace); }, o.delay/3); }
297					if (!base.isVisible()) { return; }
298					if (!base.typing_event) {
299						if (txt in base.typing_keymap && base.typing_keymap[txt] in $keyboard.keyaction) {
300							e = e || $.Event('keypress');
301							e.target = el; // "Enter" checks for the e.target
302							$keyboard.keyaction[base.typing_keymap[txt]](base, el, e );
303						} else {
304							base.insertText(txt);
305						}
306						base.checkCombos();
307						base.$el.trigger( $keyboard.events.kbChange, [ base, base.el ] );
308					}
309				}, o.delay/3);
310			};
311
312			if (o.showTyping) {
313				// visible event is fired before this extension is initialized, so check!
314				if (base.options.alwaysOpen && base.isVisible()) {
315					base.typing_setup();
316				} else {
317					// capture and simulate typing
318					base.$el
319						.unbind( $keyboard.events.kbBeforeVisible + base.typing_namespace )
320						.bind( $keyboard.events.kbBeforeVisible + base.typing_namespace, function(){
321							base.typing_setup();
322						});
323				}
324			}
325
326		});
327	};
328
329}));

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.