PageSourceSearch

https://www.pnm.com/o/pnm-com-modern-flat-theme/js/autotab.js?t=2026092571809967

js pnm.com collected 2026-09-24 09:41:20 UTC 6,989 bytes, 257 lines download raw bytes

1/**
2 * Autotab - jQuery plugin 1.1b
3 * http://www.lousyllama.com/sandbox/jquery-autotab
4 * 
5 * Copyright (c) 2008 Matthew Miller
6 * 
7 * Dual licensed under the MIT and GPL licenses:
8 *   http://www.opensource.org/licenses/mit-license.php
9 *   http://www.gnu.org/licenses/gpl.html
10 * 
11 * Revised: 2008-09-10 16:55:08
12 */
13
14(function($) {
15// Look for an element based on ID or name
16var check_element = function(name) {
17	var obj = null;
18	var check_id = $('#' + name);
19	var check_name = $('input[name=' + name + ']');
20
21	if(check_id.length)
22		obj = check_id;
23	else if(check_name != undefined)
24		obj = check_name;
25
26	return obj;
27};
28
29/**
30 * autotab_magic automatically establishes autotabbing with the
31 * next and previous elements as provided by :input.
32 * 
33 * autotab_magic should called after applying filters, if used.
34 * If any filters are applied after calling autotab_magic, then
35 * Autotab may not protect against brute force typing.
36 * 
37 * @name	autotab_magic
38 * @param	focus	Applies focus on the specified element
39 * @example	$(':input').autotab_magic();
40 */
41$.fn.autotab_magic = function(focus) {
42	for(var i = 0; i < this.length; i++)
43	{
44		var n = i + 1;
45		var p = i - 1;
46
47		if(i > 0 && n < this.length)
48			$(this[i]).autotab({ target: $(this[n]), previous: $(this[p]) });
49		else if(i > 0)
50			$(this[i]).autotab({ previous: $(this[p]) });
51		else
52			$(this[i]).autotab({ target: $(this[n]) });
53
54		// Set the focus on the specified element
55		if(focus != null && (isNaN(focus) && focus == $(this[i]).attr('id')) || (!isNaN(focus) && focus == i))
56			$(this[i]).focus();
57	}
58	return this;
59};
60
61/**
62 * This will take any of the text that is typed and
63 * format it according to the options specified.
64 * 
65 * Option values:
66 *	format		text|number|alphanumeric|all|custom
67 *	- Text			Allows all characters except numbers
68 *	- Number		Allows only numbers
69 *	- Alphanumeric	Allows only letters and numbers
70 *	- All			Allows any and all characters
71 *	- Custom		Allows developer to provide their own filter
72 *
73 *	uppercase	true|false
74 *	- Converts a string to UPPERCASE
75 * 
76 *	lowercase	true|false
77 *	- Converts a string to lowecase
78 * 
79 *	nospace		true|false
80 *	- Remove spaces in the user input
81 * 
82 *	pattern		null|(regular expression)
83 *	- Custom regular expression for the filter
84 * 
85 * @name	autotab_filter
86 * @param	options		Can be a string, function or a list of options. If a string or
87 *						function is passed, it will be assumed to be a format option.
88 * @example	$('#number1, #number2, #number3').autotab_filter('number');
89 * @example	$('#product_key').autotab_filter({ format: 'alphanumeric', nospace: true });
90 * @example	$('#unique_id').autotab_filter({ format: 'custom', pattern: '[^0-9\.]' });
91 */
92$.fn.autotab_filter = function(options) {
93	var defaults = {
94		format: 'all',
95		uppercase: false,
96		lowercase: false,
97		nospace: false,
98		pattern: null
99	};
100
101	if(typeof options == 'string' || typeof options == 'function')
102		defaults.format = options;
103	else
104		$.extend(defaults, options);
105
106	for(var i = 0; i < this.length; i++)
107	{
108		$(this[i]).bind('keyup', function(e) {
109			var val = this.value;
110
111			switch(defaults.format)
112			{
113				case 'text':
114					var pattern = new RegExp('[0-9]+', 'g');
115					val = val.replace(pattern, '');
116					break;
117
118				case 'alpha':
119					var pattern = new RegExp('[^a-zA-Z]+', 'g');
120					val = val.replace(pattern, '');
121					break;
122
123				case 'number':
124				case 'numeric':
125					var pattern = new RegExp('[^0-9]+', 'g');
126					val = val.replace(pattern, '');
127					break;
128
129				case 'alphanumeric':
130					var pattern = new RegExp('[^0-9a-zA-Z]+', 'g');
131					val = val.replace(pattern, '');
132					break;
133
134				case 'custom':
135					var pattern = new RegExp(defaults.pattern, 'g');
136					val = val.replace(pattern, '');
137					break;
138
139				case 'all':
140				default:
141					if(typeof defaults.format == 'function')
142						var val = defaults.format(val);
143
144					break;
145			}
146
147			if(defaults.nospace)
148			{
149				var pattern = new RegExp('[ ]+', 'g');
150				val = val.replace(pattern, '');
151			}
152
153			if(defaults.uppercase)
154				val = val.toUpperCase();
155
156			if(defaults.lowercase)
157				val = val.toLowerCase();
158
159			if(val != this.value)
160				this.value = val;
161		});
162	}
163};
164
165/**
166 * Provides the autotabbing mechanism for the supplied element and passes
167 * any formatting options to autotab_filter.
168 * 
169 * Refer to autotab_filter's description for a detailed explanation of
170 * the options available.
171 * 
172 * @name	autotab
173 * @param	options
174 * @example	$('#phone').autotab({ format: 'number' });
175 * @example	$('#username').autotab({ format: 'alphanumeric', target: 'password' });
176 * @example	$('#password').autotab({ previous: 'username', target: 'confirm' });
177 */
178$.fn.autotab = function(options) {
179	var defaults = {
180		format: 'all',
181		maxlength: 2147483647,
182		uppercase: false,
183		lowercase: false,
184		nospace: false,
185		target: null,
186		previous: null,
187		pattern: null
188	};
189
190	$.extend(defaults, options);
191
192	// Sets targets to element based on the name or ID
193	// passed if they are not currently objects
194	if(typeof defaults.target == 'string')
195		defaults.target = check_element(defaults.target);
196
197	if(typeof defaults.previous == 'string')
198		defaults.previous = check_element(defaults.previous);
199
200	var maxlength = $(this).attr('maxlength');
201
202	// defaults.maxlength has not changed and maxlength was specified
203	if(defaults.maxlength == 2147483647 && maxlength != 2147483647)
204		defaults.maxlength = maxlength;
205	// defaults.maxlength overrides maxlength
206	else if(defaults.maxlength > 0)
207		$(this).attr('maxlength', defaults.maxlength)
208	// defaults.maxlength and maxlength have not been specified
209	// A target cannot be used since there is no defined maxlength
210	else
211		defaults.target = null;
212
213	if(defaults.format != 'all')
214		$(this).autotab_filter(defaults);
215
216	// Go to the previous element when backspace
217	// is pressed in an empty input field
218	return $(this).bind('keydown', function(e) {
219		if(e.which == 8 && this.value.length == 0 && defaults.previous)
220			defaults.previous.focus().val(defaults.previous.val());
221	}).bind('keyup', function(e) {
222		/**
223		 * Do not auto tab when the following keys are pressed
224		 * 8:	Backspace
225		 * 9:	Tab
226		 * 16:	Shift
227		 * 17:	Ctrl
228		 * 18:	Alt
229		 * 19:	Pause Break
230		 * 20:	Caps Lock
231		 * 27:	Esc
232		 * 33:	Page Up
233		 * 34:	Page Down
234		 * 35:	End
235		 * 36:	Home
236		 * 37:	Left Arrow
237		 * 38:	Up Arrow
238		 * 39:	Right Arrow
239		 * 40:	Down Arrow
240		 * 45:	Insert
241		 * 46:	Delete
242		 * 144:	Num Lock
243		 * 145:	Scroll Lock
244		 */
245		var keys = [8, 9, 16, 17, 18, 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 144, 145];
246
247		if(e.which != 8)
248		{
249			var val = $(this).val();
250
251			if($.inArray(e.which, keys) == -1 && val.length == defaults.maxlength && defaults.target)
252				defaults.target.focus();
253		}
254	});
255};
256
257})(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.