jquery-keypad-rails 2.0.0.2 → 2.0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/build.me +2 -2
- data/lib/jquery/keypad/rails/version.rb +1 -1
- data/vendor/assets/javascripts/jquery.keypad.js +426 -423
- data/vendor/assets/javascripts/jquery.keypad.min.js +3 -3
- data/vendor/assets/javascripts/jquery.plugin.js +1 -1
- data/vendor/assets/javascripts/jquery.plugin.min.js +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
ODgyODdkZTFmMTE5NGM4MjEwMGVkMTU5ODdmN2ZkMDllMTY2YWM1Mw==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
ZmUzN2YxMWE1YTgyNWQwMzI4ZmU2YmFkYjBjNmNlNTdlOWVjYmZjZQ==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
ZWY0MjcxZTMyNWUwYTkxZTM3OWZjYTMzOGQ1YmFlNDMxOWIyNzkyOWRkMDVm
|
|
10
|
+
ODgzODlhZDI4NmEyMDA4YjU1ZGIwZDMwMWJjZjFmNzk1MDM0ZGI5OTEzNjI2
|
|
11
|
+
OTQ4NThhMzlhMWYyOTVhZDAwYThiNjQyNDE2OGZiMmQzMzcyYmY=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
OTgyM2M5NGFmNGZhOTE4NDZjMGQzMWU4NGUxMzFkZTFkZGVlNDY4ZGZkMGYy
|
|
14
|
+
ODM1ZjIwYmM5ZGUwNWJhNjAwOTNlZGNiZDM3YWM1ZDUwMmEzNjAxMWFiMTRm
|
|
15
|
+
ZTYyY2FlNmY4YTk2N2M1MGNmOTQ0MDEzYTMyN2ExN2NjNjhjMGM=
|
data/build.me
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* http://keith-wood.name/keypad.html
|
|
2
|
-
Keypad field entry extension for jQuery v2.0.
|
|
2
|
+
Keypad field entry extension for jQuery v2.0.1.
|
|
3
3
|
Written by Keith Wood (kbwood{at}iinet.com.au) August 2008.
|
|
4
|
-
Available under the MIT (https://github.com/jquery/jquery/blob/master/
|
|
4
|
+
Available under the MIT (https://github.com/jquery/jquery/blob/master/LICENSE.txt) license.
|
|
5
5
|
Please attribute the author if you use it. */
|
|
6
6
|
|
|
7
7
|
(function($) { // hide the namespace
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
@property [clearStatus='Erase all the text'] {string} Status text for clear link.
|
|
130
130
|
@property [backText='Back'] {string} Display text for back link.
|
|
131
131
|
@property [backStatus='Erase the previous character'] {string} Status text for back link.
|
|
132
|
-
@property [spacebarText='
|
|
132
|
+
@property [spacebarText=' '] {string} Display text for space bar.
|
|
133
133
|
@property [spacebarStatus='Space'] {string} Status text for space bar.
|
|
134
134
|
@property [enterText='Enter'] {string} Display text for carriage return.
|
|
135
135
|
@property [enterStatus='Carriage return'] {string} Status text for carriage return.
|
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
clearStatus: 'Erase all the text',
|
|
154
154
|
backText: 'Back',
|
|
155
155
|
backStatus: 'Erase the previous character',
|
|
156
|
-
spacebarText: '
|
|
156
|
+
spacebarText: ' ',
|
|
157
157
|
spacebarStatus: 'Space',
|
|
158
158
|
enterText: 'Enter',
|
|
159
159
|
enterStatus: 'Carriage return',
|
|
@@ -193,15 +193,15 @@
|
|
|
193
193
|
_keyClass: pluginName + '-key', // The key marker class
|
|
194
194
|
_keyDownClass: pluginName + '-key-down', // The key down marker class
|
|
195
195
|
|
|
196
|
-
|
|
196
|
+
// Standard US keyboard alphabetic layout
|
|
197
197
|
qwertyAlphabetic: ['qwertyuiop', 'asdfghjkl', 'zxcvbnm'],
|
|
198
|
-
|
|
198
|
+
// Standard US keyboard layout
|
|
199
199
|
qwertyLayout: ['!@#$%^&*()_=' + this.HALF_SPACE + this.SPACE + this.CLOSE,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
this.HALF_SPACE + '`~[]{}<>\\|/' + this.SPACE + '789',
|
|
201
|
+
'qwertyuiop\'"' + this.HALF_SPACE + '456',
|
|
202
|
+
this.HALF_SPACE + 'asdfghjkl;:' + this.SPACE + '123',
|
|
203
|
+
this.SPACE + 'zxcvbnm,.?' + this.SPACE + this.HALF_SPACE + '-0+',
|
|
204
|
+
'' + this.TAB + this.ENTER + this.SPACE_BAR + this.SHIFT +
|
|
205
205
|
this.HALF_SPACE + this.BACK + this.CLEAR],
|
|
206
206
|
|
|
207
207
|
/** Add the definition of a special key.
|
|
@@ -211,15 +211,15 @@
|
|
|
211
211
|
@param noHighlight {boolean} True to suppress highlight when using ThemeRoller.
|
|
212
212
|
@return {Keypad} The keypad object for chaining further calls.
|
|
213
213
|
@example $.keypad.addKeyDef('CLEAR', 'clear', function(inst) { plugin._clearValue(inst); }); */
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
214
|
+
addKeyDef: function(id, name, action, noHighlight) {
|
|
215
|
+
if (this._keyCode == 32) {
|
|
216
|
+
throw 'Only 32 special keys allowed';
|
|
217
|
+
}
|
|
218
|
+
this[id] = String.fromCharCode(this._keyCode++);
|
|
219
|
+
this._specialKeys.push({code: this[id], id: id, name: name,
|
|
220
|
+
action: action, noHighlight: noHighlight});
|
|
221
|
+
return this;
|
|
222
|
+
},
|
|
223
223
|
|
|
224
224
|
/** Additional setup for the keypad.
|
|
225
225
|
Create popup div. */
|
|
@@ -238,12 +238,12 @@
|
|
|
238
238
|
if (inst._inline) {
|
|
239
239
|
elem.append(inst._mainDiv).
|
|
240
240
|
on('click.' + inst.name, function() { inst._input.focus(); });
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
this._updateKeypad(inst);
|
|
242
|
+
}
|
|
243
243
|
else if (elem.is(':disabled')) {
|
|
244
244
|
this.disable(elem);
|
|
245
|
-
|
|
246
|
-
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
247
|
|
|
248
248
|
/** Determine the input field for the keypad.
|
|
249
249
|
@private
|
|
@@ -252,76 +252,76 @@
|
|
|
252
252
|
_setInput: function(elem, inst) {
|
|
253
253
|
inst._input = $(!inst._inline ? elem : inst.options.target ||
|
|
254
254
|
'<input type="text" class="' + this._inlineEntryClass + '" disabled/>');
|
|
255
|
-
|
|
255
|
+
if (inst._inline) {
|
|
256
256
|
elem.find('input').remove();
|
|
257
|
-
|
|
257
|
+
if (!inst.options.target) {
|
|
258
258
|
elem.append(inst._input);
|
|
259
|
+
}
|
|
259
260
|
}
|
|
260
|
-
}
|
|
261
|
-
},
|
|
261
|
+
},
|
|
262
262
|
|
|
263
263
|
_optionsChanged: function(elem, inst, options) {
|
|
264
264
|
$.extend(inst.options, options);
|
|
265
265
|
elem.off('.' + inst.name).
|
|
266
266
|
siblings('.' + this._appendClass).remove().end().
|
|
267
267
|
siblings('.' + this._triggerClass).remove();
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
var appendText = inst.options.appendText;
|
|
269
|
+
if (appendText) {
|
|
270
270
|
elem[inst.options.isRTL ? 'before' : 'after'](
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
271
|
+
'<span class="' + this._appendClass + '">' + appendText + '</span>');
|
|
272
|
+
}
|
|
273
|
+
if (!inst._inline) {
|
|
274
|
+
if (inst.options.showOn == 'focus' || inst.options.showOn == 'both') {
|
|
275
|
+
// pop-up keypad when in the marked field
|
|
276
276
|
elem.on('focus.' + inst.name, this.show).
|
|
277
277
|
on('keydown.' + inst.name, this._doKeyDown);
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
278
|
+
}
|
|
279
|
+
if (inst.options.showOn == 'button' || inst.options.showOn == 'both') {
|
|
280
|
+
// pop-up keypad when button clicked
|
|
281
|
+
var buttonStatus = inst.options.buttonStatus;
|
|
282
|
+
var buttonImage = inst.options.buttonImage;
|
|
283
|
+
var trigger = $(inst.options.buttonImageOnly ?
|
|
284
|
+
$('<img src="' + buttonImage + '" alt="' +
|
|
285
|
+
buttonStatus + '" title="' + buttonStatus + '"/>') :
|
|
286
|
+
$('<button type="button" title="' + buttonStatus + '"></button>').
|
|
287
|
+
html(buttonImage == '' ? inst.options.buttonText :
|
|
288
|
+
$('<img src="' + buttonImage + '" alt="' +
|
|
289
|
+
buttonStatus + '" title="' + buttonStatus + '"/>')));
|
|
290
|
+
elem[inst.options.isRTL ? 'before' : 'after'](trigger);
|
|
291
|
+
trigger.addClass(this._triggerClass).click(function() {
|
|
292
292
|
if (plugin._keypadShowing && plugin._lastField == elem[0]) {
|
|
293
293
|
plugin.hide();
|
|
294
|
-
|
|
295
|
-
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
296
|
plugin.show(elem[0]);
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
297
|
+
}
|
|
298
|
+
return false;
|
|
299
|
+
});
|
|
300
|
+
}
|
|
300
301
|
}
|
|
301
|
-
}
|
|
302
302
|
inst.saveReadonly = elem.attr('readonly');
|
|
303
303
|
elem[inst.options.keypadOnly ? 'attr' : 'removeAttr']('readonly', true).
|
|
304
304
|
on('setData.' + inst.name, function(event, key, value) {
|
|
305
|
-
|
|
305
|
+
inst.options[key] = value;
|
|
306
306
|
}).
|
|
307
307
|
on('getData.' + inst.name, function(event, key) {
|
|
308
|
-
|
|
309
|
-
|
|
308
|
+
return inst.options[key];
|
|
309
|
+
});
|
|
310
310
|
this._setInput(elem, inst);
|
|
311
|
-
|
|
312
|
-
|
|
311
|
+
this._updateKeypad(inst);
|
|
312
|
+
},
|
|
313
313
|
|
|
314
314
|
_preDestroy: function(elem, inst) {
|
|
315
|
-
|
|
315
|
+
if (this._curInst == inst) {
|
|
316
316
|
this.hide();
|
|
317
|
-
|
|
317
|
+
}
|
|
318
318
|
elem.siblings('.' + this._appendClass).remove().end().
|
|
319
|
-
|
|
320
|
-
|
|
319
|
+
siblings('.' + this._triggerClass).remove().end().
|
|
320
|
+
prev('.' + this._inlineEntryClass).remove();
|
|
321
321
|
elem.empty().off('.' + inst.name)
|
|
322
|
-
|
|
322
|
+
[inst.saveReadonly ? 'attr' : 'removeAttr']('readonly', true);
|
|
323
323
|
inst._input.removeData(inst.name);
|
|
324
|
-
|
|
324
|
+
},
|
|
325
325
|
|
|
326
326
|
/** Enable the keypad for a jQuery selection.
|
|
327
327
|
@param elem {Element} The target text field.
|
|
@@ -329,21 +329,21 @@
|
|
|
329
329
|
enable: function(elem) {
|
|
330
330
|
elem = $(elem);
|
|
331
331
|
if (!elem.hasClass(this._getMarker())) {
|
|
332
|
-
|
|
333
|
-
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
334
|
var nodeName = elem[0].nodeName.toLowerCase();
|
|
335
|
-
|
|
335
|
+
if (nodeName.match(/input|textarea/)) {
|
|
336
336
|
elem.prop('disabled', false).
|
|
337
337
|
siblings('button.' + this._triggerClass).prop('disabled', false).end().
|
|
338
338
|
siblings('img.' + this._triggerClass).css({opacity: '1.0', cursor: ''});
|
|
339
|
-
|
|
340
|
-
|
|
339
|
+
}
|
|
340
|
+
else if (nodeName.match(/div|span/)) {
|
|
341
341
|
elem.children('.' + this._disableClass).remove();
|
|
342
342
|
this._getInst(elem)._mainDiv.find('button').prop('disabled', false);
|
|
343
|
-
|
|
344
|
-
|
|
343
|
+
}
|
|
344
|
+
this._disabledFields = $.map(this._disabledFields,
|
|
345
345
|
function(value) { return (value == elem[0] ? null : value); }); // delete entry
|
|
346
|
-
|
|
346
|
+
},
|
|
347
347
|
|
|
348
348
|
/** Disable the keypad for a jQuery selection.
|
|
349
349
|
@param elem {Element} The target text field.
|
|
@@ -351,34 +351,34 @@
|
|
|
351
351
|
disable: function(elem) {
|
|
352
352
|
elem = $(elem);
|
|
353
353
|
if (!elem.hasClass(this._getMarker())) {
|
|
354
|
-
|
|
355
|
-
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
356
|
var nodeName = elem[0].nodeName.toLowerCase();
|
|
357
|
-
|
|
357
|
+
if (nodeName.match(/input|textarea/)) {
|
|
358
358
|
elem.prop('disabled', true).
|
|
359
359
|
siblings('button.' + this._triggerClass).prop('disabled', true).end().
|
|
360
360
|
siblings('img.' + this._triggerClass).css({opacity: '0.5', cursor: 'default'});
|
|
361
|
-
|
|
362
|
-
|
|
361
|
+
}
|
|
362
|
+
else if (nodeName.match(/div|span/)) {
|
|
363
363
|
var inline = elem.children('.' + this._inlineClass);
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
364
|
+
var offset = inline.offset();
|
|
365
|
+
var relOffset = {left: 0, top: 0};
|
|
366
|
+
inline.parents().each(function() {
|
|
367
|
+
if ($(this).css('position') == 'relative') {
|
|
368
|
+
relOffset = $(this).offset();
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
372
|
elem.prepend('<div class="' + this._disableClass + '" style="width: ' +
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
373
|
+
inline.outerWidth() + 'px; height: ' + inline.outerHeight() +
|
|
374
|
+
'px; left: ' + (offset.left - relOffset.left) +
|
|
375
|
+
'px; top: ' + (offset.top - relOffset.top) + 'px;"></div>');
|
|
376
376
|
this._getInst(elem)._mainDiv.find('button').prop('disabled', true);
|
|
377
|
-
|
|
378
|
-
|
|
377
|
+
}
|
|
378
|
+
this._disabledFields = $.map(this._disabledFields,
|
|
379
379
|
function(value) { return (value == elem[0] ? null : value); }); // delete entry
|
|
380
380
|
this._disabledFields[this._disabledFields.length] = elem[0];
|
|
381
|
-
|
|
381
|
+
},
|
|
382
382
|
|
|
383
383
|
/** Is the text field disabled as a keypad?
|
|
384
384
|
@param elem {Element} The target text field.
|
|
@@ -394,78 +394,78 @@
|
|
|
394
394
|
show: function(elem) {
|
|
395
395
|
elem = elem.target || elem;
|
|
396
396
|
if (plugin.isDisabled(elem) || plugin._lastField == elem) { // already here
|
|
397
|
-
|
|
398
|
-
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
399
|
var inst = plugin._getInst(elem);
|
|
400
400
|
plugin.hide(null, '');
|
|
401
401
|
plugin._lastField = elem;
|
|
402
402
|
plugin._pos = plugin._findPos(elem);
|
|
403
403
|
plugin._pos[1] += elem.offsetHeight; // add the height
|
|
404
|
-
|
|
404
|
+
var isFixed = false;
|
|
405
405
|
$(elem).parents().each(function() {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
406
|
+
isFixed |= $(this).css('position') == 'fixed';
|
|
407
|
+
return !isFixed;
|
|
408
|
+
});
|
|
409
|
+
var offset = {left: plugin._pos[0], top: plugin._pos[1]};
|
|
410
|
+
plugin._pos = null;
|
|
411
|
+
// determine sizing offscreen
|
|
412
|
+
inst._mainDiv.css({position: 'absolute', display: 'block', top: '-1000px', width: 'auto'});
|
|
413
|
+
plugin._updateKeypad(inst);
|
|
414
|
+
// and adjust position before showing
|
|
415
|
+
offset = plugin._checkOffset(inst, offset, isFixed);
|
|
416
|
+
inst._mainDiv.css({position: (isFixed ? 'fixed' : 'absolute'), display: 'none',
|
|
417
|
+
left: offset.left + 'px', top: offset.top + 'px'});
|
|
418
|
+
var duration = inst.options.duration;
|
|
419
|
+
var showAnim = inst.options.showAnim;
|
|
420
|
+
var postProcess = function() {
|
|
421
|
+
plugin._keypadShowing = true;
|
|
422
|
+
};
|
|
423
|
+
if ($.effects && ($.effects[showAnim] || ($.effects.effect && $.effects.effect[showAnim]))) {
|
|
424
|
+
var data = inst._mainDiv.data(); // Update old effects data
|
|
425
|
+
for (var key in data) {
|
|
426
|
+
if (key.match(/^ec\.storage\./)) {
|
|
427
|
+
data[key] = inst._mainDiv.css(key.replace(/ec\.storage\./, ''));
|
|
428
|
+
}
|
|
428
429
|
}
|
|
429
|
-
|
|
430
|
-
inst._mainDiv.data(data).show(showAnim,
|
|
430
|
+
inst._mainDiv.data(data).show(showAnim,
|
|
431
431
|
inst.options.showOptions || {}, duration, postProcess);
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
inst._mainDiv[showAnim || 'show']((showAnim ? duration : 0), postProcess);
|
|
435
|
+
}
|
|
436
|
+
if (inst._input[0].type != 'hidden') {
|
|
437
|
+
inst._input[0].focus();
|
|
438
|
+
}
|
|
439
|
+
plugin._curInst = inst;
|
|
440
|
+
},
|
|
441
441
|
|
|
442
442
|
/** Generate the keypad content.
|
|
443
443
|
@private
|
|
444
444
|
@param inst {object} The instance settings. */
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
445
|
+
_updateKeypad: function(inst) {
|
|
446
|
+
var borders = this._getBorders(inst._mainDiv);
|
|
447
|
+
inst._mainDiv.empty().append(this._generateHTML(inst)).
|
|
448
|
+
removeClass().addClass(inst.options.keypadClass +
|
|
449
|
+
(inst.options.useThemeRoller ? ' ui-widget ui-widget-content' : '') +
|
|
450
|
+
(inst.options.isRTL ? ' ' + this._rtlClass : '') + ' ' +
|
|
451
|
+
(inst._inline ? this._inlineClass : this._mainDivClass));
|
|
452
|
+
if ($.isFunction(inst.options.beforeShow)) {
|
|
453
|
+
inst.options.beforeShow.apply((inst._input ? inst._input[0] : null),
|
|
454
|
+
[inst._mainDiv, inst]);
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
457
|
|
|
458
458
|
/** Retrieve the size of left and top borders for an element.
|
|
459
459
|
@private
|
|
460
460
|
@param elem {jQuery} The element of interest.
|
|
461
461
|
@return {number[]} The left and top borders. */
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
462
|
+
_getBorders: function(elem) {
|
|
463
|
+
var convert = function(value) {
|
|
464
|
+
return {thin: 1, medium: 3, thick: 5}[value] || value;
|
|
465
|
+
};
|
|
466
|
+
return [parseFloat(convert(elem.css('border-left-width'))),
|
|
467
|
+
parseFloat(convert(elem.css('border-top-width')))];
|
|
468
|
+
},
|
|
469
469
|
|
|
470
470
|
/** Check positioning to remain on screen.
|
|
471
471
|
@private
|
|
@@ -473,181 +473,181 @@
|
|
|
473
473
|
@param offset {object} The current offset.
|
|
474
474
|
@param isFixed {boolean} True if the text field is fixed in position.
|
|
475
475
|
@return {object} The updated offset. */
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
476
|
+
_checkOffset: function(inst, offset, isFixed) {
|
|
477
|
+
var pos = inst._input ? this._findPos(inst._input[0]) : null;
|
|
478
|
+
var browserWidth = window.innerWidth || document.documentElement.clientWidth;
|
|
479
|
+
var browserHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
480
|
+
var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
|
|
481
|
+
var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
|
|
482
|
+
// recalculate width as otherwise set to 100%
|
|
483
|
+
var width = 0;
|
|
484
|
+
inst._mainDiv.find(':not(div)').each(function() {
|
|
485
|
+
width = Math.max(width, this.offsetLeft + $(this).outerWidth(true));
|
|
486
|
+
});
|
|
487
|
+
inst._mainDiv.css('width', width + 1);
|
|
488
|
+
// reposition keypad panel horizontally if outside the browser window
|
|
489
|
+
if (inst.options.isRTL ||
|
|
490
|
+
(offset.left + inst._mainDiv.outerWidth() - scrollX) > browserWidth) {
|
|
491
|
+
offset.left = Math.max((isFixed ? 0 : scrollX),
|
|
492
|
+
pos[0] + (inst._input ? inst._input.outerWidth() : 0) -
|
|
493
|
+
(isFixed ? scrollX : 0) - inst._mainDiv.outerWidth());
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
offset.left = Math.max((isFixed ? 0 : scrollX), offset.left - (isFixed ? scrollX : 0));
|
|
497
|
+
}
|
|
498
|
+
// reposition keypad panel vertically if outside the browser window
|
|
499
|
+
if ((offset.top + inst._mainDiv.outerHeight() - scrollY) > browserHeight) {
|
|
500
|
+
offset.top = Math.max((isFixed ? 0 : scrollY),
|
|
501
|
+
pos[1] - (isFixed ? scrollY : 0) - inst._mainDiv.outerHeight());
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
offset.top = Math.max((isFixed ? 0 : scrollY), offset.top - (isFixed ? scrollY : 0));
|
|
505
|
+
}
|
|
506
|
+
return offset;
|
|
507
|
+
},
|
|
508
508
|
|
|
509
509
|
/** Find an object's position on the screen.
|
|
510
510
|
@private
|
|
511
511
|
@param obj {Element} The element to find the position for.
|
|
512
512
|
@return {number[]} The element's position. */
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
513
|
+
_findPos: function(obj) {
|
|
514
|
+
while (obj && (obj.type == 'hidden' || obj.nodeType != 1)) {
|
|
515
|
+
obj = obj.nextSibling;
|
|
516
|
+
}
|
|
517
|
+
var position = $(obj).offset();
|
|
518
|
+
return [position.left, position.top];
|
|
519
|
+
},
|
|
520
520
|
|
|
521
521
|
/** Hide the keypad from view.
|
|
522
522
|
@param elem {Element} The text field attached to the keypad.
|
|
523
523
|
@param duration {string} The duration over which to close the keypad.
|
|
524
524
|
@example $(selector).keypad('hide') */
|
|
525
525
|
hide: function(elem, duration) {
|
|
526
|
-
|
|
527
|
-
if (!inst || (elem && inst != $.data(elem, this.
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
526
|
+
var inst = this._curInst;
|
|
527
|
+
if (!inst || (elem && inst != $.data(elem, this.name))) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
if (this._keypadShowing) {
|
|
531
|
+
duration = (duration != null ? duration : inst.options.duration);
|
|
532
|
+
var showAnim = inst.options.showAnim;
|
|
533
|
+
if ($.effects && ($.effects[showAnim] || ($.effects.effect && $.effects.effect[showAnim]))) {
|
|
534
534
|
inst._mainDiv.hide(showAnim, inst.options.showOptions || {}, duration);
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
inst._mainDiv[(showAnim == 'slideDown' ? 'slideUp' :
|
|
538
|
+
(showAnim == 'fadeIn' ? 'fadeOut' : 'hide'))](showAnim ? duration : 0);
|
|
539
|
+
}
|
|
535
540
|
}
|
|
536
|
-
|
|
537
|
-
inst.
|
|
538
|
-
(
|
|
541
|
+
if ($.isFunction(inst.options.onClose)) {
|
|
542
|
+
inst.options.onClose.apply((inst._input ? inst._input[0] : null), // trigger custom callback
|
|
543
|
+
[inst._input.val(), inst]);
|
|
539
544
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
this.
|
|
548
|
-
}
|
|
549
|
-
if (inst._inline) {
|
|
550
|
-
inst._input.val('');
|
|
551
|
-
}
|
|
552
|
-
this._curInst = null;
|
|
553
|
-
},
|
|
545
|
+
if (this._keypadShowing) {
|
|
546
|
+
this._keypadShowing = false;
|
|
547
|
+
this._lastField = null;
|
|
548
|
+
}
|
|
549
|
+
if (inst._inline) {
|
|
550
|
+
inst._input.val('');
|
|
551
|
+
}
|
|
552
|
+
this._curInst = null;
|
|
553
|
+
},
|
|
554
554
|
|
|
555
555
|
/** Handle keystrokes.
|
|
556
556
|
@private
|
|
557
557
|
@param event {Event} The key event. */
|
|
558
558
|
_doKeyDown: function(event) {
|
|
559
559
|
if (event.keyCode == 9) { // Tab out
|
|
560
|
-
|
|
560
|
+
plugin.mainDiv.stop(true, true);
|
|
561
561
|
plugin.hide();
|
|
562
|
-
|
|
563
|
-
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
564
|
|
|
565
565
|
/** Close keypad if clicked elsewhere.
|
|
566
566
|
@private
|
|
567
567
|
@param event {Event} The mouseclick details. */
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
568
|
+
_checkExternalClick: function(event) {
|
|
569
|
+
if (!plugin._curInst) {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
var target = $(event.target);
|
|
573
573
|
if (target.closest('.' + plugin._mainDivClass).length === 0 &&
|
|
574
574
|
!target.hasClass(plugin._getMarker()) &&
|
|
575
575
|
target.closest('.' + plugin._triggerClass).length === 0 &&
|
|
576
|
-
|
|
576
|
+
plugin._keypadShowing) {
|
|
577
577
|
plugin.hide();
|
|
578
|
-
|
|
579
|
-
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
580
|
|
|
581
581
|
/** Toggle between upper and lower case.
|
|
582
582
|
@private
|
|
583
583
|
@param inst {object} The instance settings. */
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
584
|
+
_shiftKeypad: function(inst) {
|
|
585
|
+
inst.ucase = !inst.ucase;
|
|
586
|
+
this._updateKeypad(inst);
|
|
587
|
+
inst._input.focus(); // for further typing
|
|
588
|
+
},
|
|
589
589
|
|
|
590
590
|
/** Erase the text field.
|
|
591
591
|
@private
|
|
592
592
|
@param inst {object} The instance settings. */
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
593
|
+
_clearValue: function(inst) {
|
|
594
|
+
this._setValue(inst, '', 0);
|
|
595
|
+
this._notifyKeypress(inst, plugin.DEL);
|
|
596
|
+
},
|
|
597
597
|
|
|
598
598
|
/** Erase the last character.
|
|
599
599
|
@private
|
|
600
600
|
@param inst {object} The instance settings. */
|
|
601
|
-
|
|
601
|
+
_backValue: function(inst) {
|
|
602
602
|
var elem = inst._input[0];
|
|
603
|
-
|
|
604
|
-
|
|
603
|
+
var value = inst._input.val();
|
|
604
|
+
var range = [value.length, value.length];
|
|
605
605
|
range = (inst._input.prop('readonly') || inst._input.prop('disabled') ? range :
|
|
606
606
|
(elem.setSelectionRange /* Mozilla */ ? [elem.selectionStart, elem.selectionEnd] :
|
|
607
607
|
(elem.createTextRange /* IE */ ? this._getIERange(elem) : range)));
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
608
|
+
this._setValue(inst, (value.length == 0 ? '' :
|
|
609
|
+
value.substr(0, range[0] - 1) + value.substr(range[1])), range[0] - 1);
|
|
610
|
+
this._notifyKeypress(inst, plugin.BS);
|
|
611
|
+
},
|
|
612
612
|
|
|
613
613
|
/** Update the text field with the selected value.
|
|
614
614
|
@private
|
|
615
615
|
@param inst {object} The instance settings.
|
|
616
616
|
@param value {string} The new character to add. */
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
617
|
+
_selectValue: function(inst, value) {
|
|
618
|
+
this.insertValue(inst._input[0], value);
|
|
619
|
+
this._setValue(inst, inst._input.val());
|
|
620
|
+
this._notifyKeypress(inst, value);
|
|
621
|
+
},
|
|
622
622
|
|
|
623
623
|
/** Update the text field with the selected value.
|
|
624
624
|
@param input {string|Element|jQuery} The jQuery selector, input field, or jQuery collection.
|
|
625
625
|
@param value {string} The new character to add.
|
|
626
626
|
@example $.keypad.insertValue(field, 'abc'); */
|
|
627
|
-
|
|
628
|
-
|
|
627
|
+
insertValue: function(input, value) {
|
|
628
|
+
input = (input.jquery ? input : $(input));
|
|
629
629
|
var elem = input[0];
|
|
630
|
-
|
|
631
|
-
|
|
630
|
+
var newValue = input.val();
|
|
631
|
+
var range = [newValue.length, newValue.length];
|
|
632
632
|
range = (input.attr('readonly') || input.attr('disabled') ? range :
|
|
633
633
|
(elem.setSelectionRange /* Mozilla */ ? [elem.selectionStart, elem.selectionEnd] :
|
|
634
634
|
(elem.createTextRange /* IE */ ? this._getIERange(elem) : range)));
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
if (input.is(':visible')) {
|
|
638
|
-
input.focus(); // for further typing
|
|
639
|
-
}
|
|
640
|
-
if (elem.setSelectionRange) { // Mozilla
|
|
635
|
+
input.val(newValue.substr(0, range[0]) + value + newValue.substr(range[1]));
|
|
636
|
+
pos = range[0] + value.length;
|
|
641
637
|
if (input.is(':visible')) {
|
|
642
|
-
|
|
638
|
+
input.focus(); // for further typing
|
|
639
|
+
}
|
|
640
|
+
if (elem.setSelectionRange) { // Mozilla
|
|
641
|
+
if (input.is(':visible')) {
|
|
642
|
+
elem.setSelectionRange(pos, pos);
|
|
643
|
+
}
|
|
643
644
|
}
|
|
644
|
-
}
|
|
645
645
|
else if (elem.createTextRange) { // IE
|
|
646
646
|
range = elem.createTextRange();
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
647
|
+
range.move('character', pos);
|
|
648
|
+
range.select();
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
651
|
|
|
652
652
|
/** Get the coordinates for the selected area in the text field in IE.
|
|
653
653
|
@private
|
|
@@ -655,37 +655,37 @@
|
|
|
655
655
|
@return {number[]} The start and end positions of the selection. */
|
|
656
656
|
_getIERange: function(elem) {
|
|
657
657
|
elem.focus();
|
|
658
|
-
|
|
659
|
-
|
|
658
|
+
var selectionRange = document.selection.createRange().duplicate();
|
|
659
|
+
// Use two ranges: before and selection
|
|
660
660
|
var beforeRange = this._getIETextRange(elem);
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
}
|
|
673
|
-
else {
|
|
674
|
-
range.moveEnd('character', -1);
|
|
675
|
-
if (range.text == origText) {
|
|
676
|
-
text += '\r\n';
|
|
661
|
+
beforeRange.setEndPoint('EndToStart', selectionRange);
|
|
662
|
+
// Check each range for trimmed newlines by shrinking the range by one
|
|
663
|
+
// character and seeing if the text property has changed. If it has not
|
|
664
|
+
// changed then we know that IE has trimmed a \r\n from the end.
|
|
665
|
+
var checkCRLF = function(range) {
|
|
666
|
+
var origText = range.text;
|
|
667
|
+
var text = origText;
|
|
668
|
+
var finished = false;
|
|
669
|
+
while (true) {
|
|
670
|
+
if (range.compareEndPoints('StartToEnd', range) == 0) {
|
|
671
|
+
break;
|
|
677
672
|
}
|
|
678
673
|
else {
|
|
679
|
-
|
|
674
|
+
range.moveEnd('character', -1);
|
|
675
|
+
if (range.text == origText) {
|
|
676
|
+
text += '\r\n';
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
break;
|
|
680
|
+
}
|
|
680
681
|
}
|
|
681
682
|
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
},
|
|
683
|
+
return text;
|
|
684
|
+
};
|
|
685
|
+
var beforeText = checkCRLF(beforeRange);
|
|
686
|
+
var selectionText = checkCRLF(selectionRange);
|
|
687
|
+
return [beforeText.length, beforeText.length + selectionText.length];
|
|
688
|
+
},
|
|
689
689
|
|
|
690
690
|
/** Create an IE text range for the text field.
|
|
691
691
|
@private
|
|
@@ -694,189 +694,191 @@
|
|
|
694
694
|
_getIETextRange: function(elem) {
|
|
695
695
|
var isInput = (elem.nodeName.toLowerCase() == 'input');
|
|
696
696
|
var range = (isInput ? elem.createTextRange() : document.body.createTextRange());
|
|
697
|
-
|
|
697
|
+
if (!isInput) {
|
|
698
698
|
range.moveToElementText(elem); // Selects all the text for a textarea
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
699
|
+
}
|
|
700
|
+
return range;
|
|
701
|
+
},
|
|
702
702
|
|
|
703
703
|
/** Set the text field to the selected value, and trigger any on change event.
|
|
704
704
|
@private
|
|
705
705
|
@param inst {object} The instance settings.
|
|
706
706
|
@param value {string} The new value for the text field. */
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
707
|
+
_setValue: function(inst, value) {
|
|
708
|
+
var maxlen = inst._input.attr('maxlength');
|
|
709
|
+
if (maxlen > -1) {
|
|
710
|
+
value = value.substr(0, maxlen);
|
|
711
|
+
}
|
|
712
|
+
inst._input.val(value);
|
|
713
|
+
if (!$.isFunction(inst.options.onKeypress)) {
|
|
714
|
+
inst._input.trigger('change'); // fire the change event
|
|
715
|
+
}
|
|
716
|
+
},
|
|
717
717
|
|
|
718
718
|
/** Notify clients of a keypress.
|
|
719
719
|
@private
|
|
720
720
|
@param inst {object} The instance settings.
|
|
721
721
|
@param key {string} The character pressed. */
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
722
|
+
_notifyKeypress: function(inst, key) {
|
|
723
|
+
if ($.isFunction(inst.options.onKeypress)) { // trigger custom callback
|
|
724
|
+
inst.options.onKeypress.apply((inst._input ? inst._input[0] : null),
|
|
725
|
+
[key, inst._input.val(), inst]);
|
|
726
|
+
}
|
|
727
|
+
},
|
|
728
728
|
|
|
729
729
|
/** Generate the HTML for the current state of the keypad.
|
|
730
730
|
@private
|
|
731
731
|
@param inst {object} The instance settings.
|
|
732
732
|
@return {jQuery} The HTML for this keypad. */
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
733
|
+
_generateHTML: function(inst) {
|
|
734
|
+
var html = (!inst.options.prompt ? '' : '<div class="' + this._promptClass +
|
|
735
|
+
(inst.options.useThemeRoller ? ' ui-widget-header ui-corner-all' : '') + '">' +
|
|
736
|
+
inst.options.prompt + '</div>');
|
|
737
|
+
var layout = this._randomiseLayout(inst);
|
|
738
|
+
for (var i = 0; i < layout.length; i++) {
|
|
739
|
+
html += '<div class="' + this._rowClass + '">';
|
|
740
|
+
var keys = layout[i].split(inst.options.separator);
|
|
741
|
+
for (var j = 0; j < keys.length; j++) {
|
|
742
|
+
if (inst.ucase) {
|
|
743
|
+
keys[j] = inst.options.toUpper(keys[j]);
|
|
744
|
+
}
|
|
745
|
+
var keyDef = this._specialKeys[keys[j].charCodeAt(0)];
|
|
746
|
+
if (keyDef) {
|
|
747
|
+
html += (keyDef.action ? '<button type="button" class="' +
|
|
748
|
+
this._specialClass + ' ' + this._namePrefixClass + keyDef.name +
|
|
749
|
+
(inst.options.useThemeRoller ? ' ui-corner-all ui-state-default' +
|
|
750
|
+
(keyDef.noHighlight ? '' : ' ui-state-highlight') : '') +
|
|
751
|
+
'" title="' + inst.options[keyDef.name + 'Status'] + '">' +
|
|
752
|
+
(inst.options[keyDef.name + 'Text'] || ' ') + '</button>' :
|
|
753
|
+
'<div class="' + this._namePrefixClass + keyDef.name + '"></div>');
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
html += '<button type="button" class="' + this._keyClass +
|
|
757
|
+
(inst.options.useThemeRoller ? ' ui-corner-all ui-state-default' : '') +
|
|
758
|
+
'">' + (keys[j] == ' ' ? ' ' : keys[j]) + '</button>';
|
|
759
|
+
}
|
|
759
760
|
}
|
|
761
|
+
html += '</div>';
|
|
760
762
|
}
|
|
761
|
-
html
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
763
|
+
html = $(html);
|
|
764
|
+
var thisInst = inst;
|
|
765
|
+
var activeClasses = this._keyDownClass +
|
|
766
|
+
(inst.options.useThemeRoller ? ' ui-state-active' : '');
|
|
767
|
+
html.find('button').mousedown(function() { $(this).addClass(activeClasses); }).
|
|
768
|
+
mouseup(function() { $(this).removeClass(activeClasses); }).
|
|
769
|
+
mouseout(function() { $(this).removeClass(activeClasses); }).
|
|
770
|
+
filter('.' + this._keyClass).
|
|
771
|
+
click(function() { plugin._selectValue(thisInst, $(this).text()); });
|
|
772
|
+
$.each(this._specialKeys, function(i, keyDef) {
|
|
773
|
+
html.find('.' + plugin._namePrefixClass + keyDef.name).click(function() {
|
|
774
|
+
keyDef.action.apply(thisInst._input, [thisInst]);
|
|
775
|
+
});
|
|
773
776
|
});
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
},
|
|
777
|
+
return html;
|
|
778
|
+
},
|
|
777
779
|
|
|
778
780
|
/** Check whether characters should be randomised, and, if so, produce the randomised layout.
|
|
779
781
|
@private
|
|
780
782
|
@param inst {object} The instance settings.
|
|
781
783
|
@return {string[]} The layout with any requested randomisations applied. */
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
784
|
+
_randomiseLayout: function(inst) {
|
|
785
|
+
if (!inst.options.randomiseNumeric && !inst.options.randomiseAlphabetic &&
|
|
786
|
+
!inst.options.randomiseOther && !inst.options.randomiseAll) {
|
|
787
|
+
return inst.options.layout;
|
|
788
|
+
}
|
|
789
|
+
var numerics = [];
|
|
790
|
+
var alphas = [];
|
|
791
|
+
var others = [];
|
|
792
|
+
var newLayout = [];
|
|
793
|
+
// Find characters of different types
|
|
794
|
+
for (var i = 0; i < inst.options.layout.length; i++) {
|
|
795
|
+
newLayout[i] = '';
|
|
796
|
+
var keys = inst.options.layout[i].split(inst.options.separator);
|
|
797
|
+
for (var j = 0; j < keys.length; j++) {
|
|
798
|
+
if (this._isControl(keys[j])) {
|
|
799
|
+
continue;
|
|
800
|
+
}
|
|
801
|
+
if (inst.options.randomiseAll) {
|
|
802
|
+
others.push(keys[j]);
|
|
803
|
+
}
|
|
804
|
+
else if (inst.options.isNumeric(keys[j])) {
|
|
805
|
+
numerics.push(keys[j]);
|
|
806
|
+
}
|
|
807
|
+
else if (inst.options.isAlphabetic(keys[j])) {
|
|
808
|
+
alphas.push(keys[j]);
|
|
809
|
+
}
|
|
810
|
+
else {
|
|
811
|
+
others.push(keys[j]);
|
|
812
|
+
}
|
|
810
813
|
}
|
|
811
814
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
this._shuffle(numerics);
|
|
816
|
-
}
|
|
817
|
-
if (inst.options.randomiseAlphabetic) {
|
|
818
|
-
this._shuffle(alphas);
|
|
819
|
-
}
|
|
820
|
-
if (inst.options.randomiseOther || inst.options.randomiseAll) {
|
|
821
|
-
this._shuffle(others);
|
|
822
|
-
}
|
|
823
|
-
var n = 0;
|
|
824
|
-
var a = 0;
|
|
825
|
-
var o = 0;
|
|
826
|
-
// And replace them in the layout
|
|
827
|
-
for (var i = 0; i < inst.options.layout.length; i++) {
|
|
828
|
-
var keys = inst.options.layout[i].split(inst.options.separator);
|
|
829
|
-
for (var j = 0; j < keys.length; j++) {
|
|
830
|
-
newLayout[i] += (this._isControl(keys[j]) ? keys[j] :
|
|
831
|
-
(inst.options.randomiseAll ? others[o++] :
|
|
832
|
-
(inst.options.isNumeric(keys[j]) ? numerics[n++] :
|
|
833
|
-
(inst.options.isAlphabetic(keys[j]) ? alphas[a++] :
|
|
834
|
-
others[o++])))) + inst.options.separator;
|
|
815
|
+
// Shuffle them
|
|
816
|
+
if (inst.options.randomiseNumeric) {
|
|
817
|
+
this._shuffle(numerics);
|
|
835
818
|
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
819
|
+
if (inst.options.randomiseAlphabetic) {
|
|
820
|
+
this._shuffle(alphas);
|
|
821
|
+
}
|
|
822
|
+
if (inst.options.randomiseOther || inst.options.randomiseAll) {
|
|
823
|
+
this._shuffle(others);
|
|
824
|
+
}
|
|
825
|
+
var n = 0;
|
|
826
|
+
var a = 0;
|
|
827
|
+
var o = 0;
|
|
828
|
+
// And replace them in the layout
|
|
829
|
+
for (var i = 0; i < inst.options.layout.length; i++) {
|
|
830
|
+
var keys = inst.options.layout[i].split(inst.options.separator);
|
|
831
|
+
for (var j = 0; j < keys.length; j++) {
|
|
832
|
+
newLayout[i] += (this._isControl(keys[j]) ? keys[j] :
|
|
833
|
+
(inst.options.randomiseAll ? others[o++] :
|
|
834
|
+
(inst.options.isNumeric(keys[j]) ? numerics[n++] :
|
|
835
|
+
(inst.options.isAlphabetic(keys[j]) ? alphas[a++] :
|
|
836
|
+
others[o++])))) + inst.options.separator;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return newLayout;
|
|
840
|
+
},
|
|
839
841
|
|
|
840
842
|
/** Is a given character a control character?
|
|
841
843
|
@private
|
|
842
844
|
@param ch {string} The character to test.
|
|
843
845
|
@return {boolean} True if a control character, false if not. */
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
846
|
+
_isControl: function(ch) {
|
|
847
|
+
return ch < ' ';
|
|
848
|
+
},
|
|
847
849
|
|
|
848
850
|
/** Is a given character alphabetic?
|
|
849
851
|
@param ch {string} The character to test.
|
|
850
852
|
@return {boolean} True if alphabetic, false if not. */
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
853
|
+
isAlphabetic: function(ch) {
|
|
854
|
+
return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
|
|
855
|
+
},
|
|
854
856
|
|
|
855
857
|
/** Is a given character numeric?
|
|
856
858
|
@param ch {string} The character to test.
|
|
857
859
|
@return {boolean} True if numeric, false if not. */
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
860
|
+
isNumeric: function(ch) {
|
|
861
|
+
return (ch >= '0' && ch <= '9');
|
|
862
|
+
},
|
|
861
863
|
|
|
862
864
|
/** Convert a character to upper case.
|
|
863
865
|
@param ch {string} The character to convert.
|
|
864
866
|
@return {string} Its uppercase version. */
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
867
|
+
toUpper: function(ch) {
|
|
868
|
+
return ch.toUpperCase();
|
|
869
|
+
},
|
|
868
870
|
|
|
869
871
|
/** Randomise the contents of an array.
|
|
870
872
|
@private
|
|
871
873
|
@param values {string[]} The array to rearrange. */
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
874
|
+
_shuffle: function(values) {
|
|
875
|
+
for (var i = values.length - 1; i > 0; i--) {
|
|
876
|
+
var j = Math.floor(Math.random() * values.length);
|
|
877
|
+
var ch = values[i];
|
|
878
|
+
values[i] = values[j];
|
|
879
|
+
values[j] = ch;
|
|
880
|
+
}
|
|
878
881
|
}
|
|
879
|
-
}
|
|
880
882
|
});
|
|
881
883
|
|
|
882
884
|
var plugin = $.keypad;
|
|
@@ -904,14 +906,15 @@
|
|
|
904
906
|
plugin.SPACE + 'zxcvbnm,.?' + plugin.SPACE + plugin.HALF_SPACE + '-0+',
|
|
905
907
|
'' + plugin.TAB + plugin.ENTER + plugin.SPACE_BAR + plugin.SHIFT +
|
|
906
908
|
plugin.HALF_SPACE + plugin.BACK + plugin.CLEAR],
|
|
907
|
-
$.extend(plugin.regionalOptions[''],
|
|
909
|
+
$.extend(plugin.regionalOptions[''],
|
|
910
|
+
{alphabeticLayout: plugin.qwertyAlphabetic, fullLayout: plugin.qwertyLayout,
|
|
908
911
|
isAlphabetic: plugin.isAlphabetic, isNumeric: plugin.isNumeric, toUpper: plugin.toUpper});
|
|
909
912
|
plugin.setDefaults($.extend({layout: plugin.numericLayout}, plugin.regionalOptions['']));
|
|
910
913
|
|
|
911
914
|
// Add the keypad division and external click check
|
|
912
915
|
$(function() {
|
|
913
|
-
|
|
914
|
-
|
|
916
|
+
$(document.body).append(plugin.mainDiv).
|
|
917
|
+
on('mousedown.' + pluginName, plugin._checkExternalClick);
|
|
915
918
|
});
|
|
916
919
|
|
|
917
920
|
})(jQuery);
|