aterrien / jQuery-Knob

Nice, downward compatible, touchable, jQuery dial
http://anthonyterrien.com/knob/
MIT License
5.03k stars 1.24k forks source link

Numpad support period #294

Open davidhayes opened 9 years ago

davidhayes commented 9 years ago

Non-numeric keys enter, backspace, tab, minus, period, and arrow keys are supported, but the keys on the numpad themselves actually have different keycodes from those used in the code.

190 is the period key on the main keyboard, but 110 is the period key on the numpad. Likewise, 189 is the minus key on the main keyboard, but 109 is the minus key on the numpad.

To fix this, the code can be changed as such (easier than a fork and pull):

(kc !== 13)                     // enter
&& kc !== 8                     // bs
&& kc !== 9                     // tab
&& kc !== 189                   // -
&& (kc !== 190
 || s.$.val().match(/\./))   // . allowed once
&& e.preventDefault();

to

(kc !== 13)                     // enter
&& kc !== 8                     // bs
&& kc !== 9                     // tab
&& (kc !== 189 && kc !== 109)                   // -
&& ((kc !== 190 && kc !== 110)
 || s.$.val().match(/\./))   // . allowed once
&& e.preventDefault();