Skip to content

Commit

Permalink
Merge pull request #3010 from pjackson28/numpadpunctuationsymbolsfix
Browse files Browse the repository at this point in the history
Datalist polyfill and various plugins: Added support for number key input through the numpad, punctuation and other symbols (fixes #3005).
  • Loading branch information
Paul Jackson authored and Paul Jackson committed Sep 16, 2013
2 parents 7aa0853 + 9bb7fac commit 0655ecc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
35 changes: 19 additions & 16 deletions src/js/polyfills/datalist.js
Expand Up @@ -10,7 +10,7 @@
* Datalist polyfill (Autocomplete for text input fields)
* @author: Paul Jackson (TBS)
*/

/*global pe:false*/
(function ($) {
"use strict";
$.fn.datalist = function () {
Expand Down Expand Up @@ -94,22 +94,23 @@

elm.on('keyup keydown click vclick touchstart focus', function (e) {
var type = e.type,
keycode = e.keyCode,
keyCode = e.keyCode,
dest;
if (type === 'keyup') {
if (!(e.ctrlKey || e.altKey || e.metaKey)) {
if ((keycode > 47 && keycode < 58) || (keycode > 64 && keycode < 91) || keycode === 32 || keycode === 8) { // Number keys, letter keys, spacebar or backspace
// 0 - 9, a - z keys, punctuation, symbols, spacebar and backspace
if ((keyCode > 47 && keyCode < 91) || (keyCode > 95 && keyCode < 112) || (keyCode > 185 && keyCode < 223) || keyCode === 32 || keyCode === 8) {
showOptions(elm.val());
}
}
} else if (type === 'keydown') {
if (!(e.ctrlKey || e.metaKey)) {
if (!e.altKey && !autolist.hasClass('al-hide')) {
if (keycode === 27) { // escape key
if (keyCode === 27) { // escape key
closeOptions();
return false;
} else if ((keycode === 38 || keycode === 40) && elm.attr('aria-activedescendent') === "") { // up or down arrow (aria-activedescendent check for IE7)
if (keycode === 38) { // up arrow
} else if ((keyCode === 38 || keyCode === 40) && elm.attr('aria-activedescendent') === '') { // up or down arrow (aria-activedescendent check for IE7)
if (keyCode === 38) { // up arrow
dest = autolist.find('a').last();
} else { // down arrow
dest = autolist.find('a').eq(0);
Expand All @@ -119,7 +120,8 @@
return false;
}
} else {
if (keycode === 38 || keycode === 40) { // up or down arrow (with or without alt)
// up or down arrow (with or without alt)
if (keyCode === 38 || keyCode === 40) {
showOptions('');
return false;
}
Expand All @@ -137,7 +139,7 @@

autolist.on('keyup keydown click vclick touchstart', 'a, span', function (e) {
var type = e.type,
keycode = e.keyCode,
keyCode = e.keyCode,
target = $(e.target),
visible_options,
index,
Expand All @@ -146,11 +148,12 @@
value;
if (type === 'keyup') {
if (!(e.ctrlKey || e.altKey || e.metaKey)) {
if ((keycode > 47 && keycode < 58) || (keycode > 64 && keycode < 91) || keycode === 32) { // Number keys, letter keys or spacebar
elm.val(val + String.fromCharCode(keycode));
// 0 - 9, a - z keys, punctuation, symbols and spacebar
if ((keyCode > 47 && keyCode < 91) || (keyCode > 95 && keyCode < 112) || (keyCode > 185 && keyCode < 223) || keyCode === 32) {
elm.val(val + String.fromCharCode(keyCode));
pe.focus(elm);
showOptions(elm.val());
} else if (keycode === 8) { // Backspace
} else if (keyCode === 8) { // Backspace
if (elm.val().length > 0) {
elm.val(val.substring(0, val.length - 1));
showOptions(elm.val());
Expand All @@ -160,7 +163,7 @@
}
} else if (type === 'keydown') {
if (!(e.ctrlKey || e.altKey || e.metaKey)) {
if (keycode === 13) { // enter key
if (keyCode === 13) { // enter key
value = target.find('span.al-value').html();
if (value.length === 0) {
value = target.find('span.al-label').html();
Expand All @@ -169,15 +172,15 @@
pe.focus(elm);
closeOptions();
return false;
} else if (keycode === 9 || keycode === 27) { // escape key
} else if (keyCode === 9 || keyCode === 27) { // escape key
pe.focus(elm);
closeOptions();
return false;
} else if (keycode === 38 || keycode === 40) { // up or down arrow
} else if (keyCode === 38 || keyCode === 40) { // up or down arrow
visible_options = autolist.find('a');
if (visible_options.length !== 0) {
index = visible_options.index(target);
if (keycode === 38) { // up arrow
if (keyCode === 38) { // up arrow
dest = ((index - 1) === -1 ? visible_options.last() : visible_options.eq(index - 1));
} else { // down arrow
dest = ((index + 1) === visible_options.length ? visible_options.eq(0) : visible_options.eq(index + 1));
Expand Down Expand Up @@ -210,4 +213,4 @@
});
};
$('input[list]').datalist();
}(jQuery));
}(jQuery));
10 changes: 5 additions & 5 deletions src/js/workers/menubar.js
Expand Up @@ -203,7 +203,7 @@
_id = $.map(/\bknav-(\d+)-(\d+)-(\d+)/.exec(_elm.attr('class')), function (n) {
return parseInt(n, 10);
}),
keycode = e.keyCode,
keyCode = e.keyCode,
type = e.type,
keychar,
sublink,
Expand All @@ -216,7 +216,7 @@
switch (type) {
case 'keydown':
if (!(e.ctrlKey || e.altKey || e.metaKey)) {
switch (keycode) {
switch (keyCode) {
case 13: // enter key
case 32: // spacebar
if (level === 0 && _elm.attr('aria-haspopup') === 'true') {
Expand Down Expand Up @@ -245,9 +245,9 @@
_elm.trigger('item-next');
return false;
default:
// 0 - 9 and a - z keys
if (keycode > 47 && keycode < 91) {
keychar = String.fromCharCode(keycode).toLowerCase();
// 0 - 9, a - z keys, punctuation and symbols
if ((keyCode > 47 && keyCode < 91) || (keyCode > 95 && keyCode < 112) || (keyCode > 185 && keyCode < 223)) {
keychar = String.fromCharCode(keyCode).toLowerCase();
sublink = (_id[2] !== 0 || _id[3] !== 0);
elmtext = _elm.text();
matches = _activemenu.find('.mb-sm-open a').filter(function () {
Expand Down
4 changes: 2 additions & 2 deletions src/js/workers/share.js
Expand Up @@ -258,8 +258,8 @@
}
return false;
default:
// 0 - 9 and a - z keys (go to the next link that starts with that key)
if ((keyCode > 47 && keyCode < 58) || (keyCode > 64 && keyCode < 91)) {
// 0 - 9, a - z keys, punctuation and symbols
if ((keyCode > 47 && keyCode < 91) || (keyCode > 95 && keyCode < 112) || (keyCode > 185 && keyCode < 223)) {
keychar = String.fromCharCode(e.keyCode).toLowerCase();
elmtext = target.text();
matches = $popupLinks.filter(function () {
Expand Down
10 changes: 5 additions & 5 deletions src/js/workers/slideout.js
Expand Up @@ -176,6 +176,7 @@
// Handles specialized keyboard input
keyhandler = function (e) {
var target = $(e.target),
keyCode = e.keyCode,
menuitem = target.is('[role="menuitem"]'),
tocLink,
keychar,
Expand Down Expand Up @@ -253,10 +254,10 @@
}
return false;
default:
// 0 - 9 and a - z keys
if ((e.keyCode > 47 && e.keyCode < 58) || (e.keyCode > 64 && e.keyCode < 91)) {
keychar = String.fromCharCode(e.keyCode).toLowerCase();
elmtext = $(e.target).text();
// 0 - 9, a - z keys, punctuation and symbols
if ((keyCode > 47 && keyCode < 91) || (keyCode > 95 && keyCode < 112) || (keyCode > 185 && keyCode < 223)) {
keychar = String.fromCharCode(keyCode).toLowerCase();
elmtext = target.text();
matches = elm.find('a').filter(function () {
return ($(this).text().substring(0, 1).toLowerCase() === keychar || $(this).text() === elmtext);
});
Expand Down Expand Up @@ -357,4 +358,3 @@
return _pe;
}
(jQuery));

0 comments on commit 0655ecc

Please sign in to comment.