autonumeric
Advanced tools
Comparing version 3.0.0-beta.10 to 3.0.0-beta.11
### Change log for autoNumeric: | ||
### "3.0.0-beta.11" | ||
+ Fix issue #320 Use `event.key` instead of `event.keyCode` and `event.which` since those two attributes are deprecated | ||
### "3.0.0-beta.10" | ||
@@ -4,0 +7,0 @@ + Add lots of pre-defined options. |
@@ -80,3 +80,7 @@ ## How to contribute? | ||
Your commit must not contain any generated files (ie. files in the `/dist/` directory or logs).<br> | ||
Please try to break down your pull requests and commits into small and manageable entities, in order: | ||
- to make them easier to process, and more importantly | ||
- to keep each logical set of changes in its own commit. | ||
Additionally, your commits must not contain any generated files (ie. files built in the `/dist/` directory, or logs).<br> | ||
*Note: Generated `dist` files (ie. `autoNumeric.js` and `autoNumeric.min.js`) are built and force-added to the git repository only once for each official release on `master`.* |
{ | ||
"name": "autonumeric", | ||
"version": "3.0.0-beta.10", | ||
"version": "3.0.0-beta.11", | ||
"description": "autoNumeric is a standalone Javascript library that provides live *as-you-type* formatting for international numbers and currencies. It supports most International numeric formats and currencies including those used in Europe, Asia, and North and South America.", | ||
@@ -5,0 +5,0 @@ "main": "src/main.js", |
@@ -105,4 +105,4 @@ ## What is [autoNumeric](http://www.decorplanit.com/plugin/)? | ||
autoNumeric can be used in two ways ; | ||
- with event listeners when used on `<input>` elements making them reactive (in a *read/write* mode), or | ||
- without event listeners when used on other DOM elements types, essentially acting as a *format-once-and-forget*-*read only* mode. | ||
- with event listeners when used on `<input>` elements or on `contenteditable`-enabled elements making them reactive (in a *read/write* mode), or | ||
- without event listeners when used on DOM elements not having the `contenteditable` attribute set to `true`, essentially acting as a *format-once-and-forget*-*read only* mode. | ||
@@ -112,3 +112,3 @@ #### On `<input>` elements | ||
Only the following supported `<input>` types are supported : | ||
Please note than due to browser constraints, only the following supported `<input>` *types* are supported : | ||
- `text`, | ||
@@ -128,2 +128,17 @@ - `tel`, | ||
#### On `contenteditable`-enabled elements | ||
Any element in the following `allowedTagList` that support the `contenteditable` attribute can be initialized by autoNumeric. | ||
This means that anywhere on a page, on any DOM element, you can harness the power of autoNumeric which will allow you to mask the user inputs. | ||
Given the following html code...: | ||
```html | ||
<p id="editableDom" contenteditable="true">12345678.9012</p> | ||
``` | ||
you can initialize this `<p>` element with autoNumeric: | ||
```js | ||
new AutoNumeric('#editableDom').french(); | ||
``` | ||
...and it will act exactly like an `<input>` element controlled by autoNumeric. | ||
#### On other DOM elements | ||
@@ -571,3 +586,4 @@ | ||
Again, be sure to check the [CONTRIBUTING](CONTRIBUTING.md) file for more details. | ||
Again, be sure to check the [CONTRIBUTING](CONTRIBUTING.md) file for more details.<br> | ||
Also, feel free to follow our RSS feeds on [master](https://github.com/BobKnothe/autoNumeric/commits/master.atom) and [next](https://github.com/BobKnothe/autoNumeric/commits/next.atom) to keep up with the latest commits. | ||
@@ -574,0 +590,0 @@ ### Dependencies |
@@ -32,3 +32,3 @@ /** | ||
* Object that store the helper enumerations | ||
* @type {{allowedTagList: [*], keyCode: {Backspace: number, Tab: number, Enter: number, Shift: number, Ctrl: number, Alt: number, PauseBreak: number, CapsLock: number, Esc: number, Space: number, PageUp: number, PageDown: number, End: number, Home: number, LeftArrow: number, UpArrow: number, RightArrow: number, DownArrow: number, Insert: number, Delete: number, num0: number, num1: number, num2: number, num3: number, num4: number, num5: number, num6: number, num7: number, num8: number, num9: number, a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number, u: number, v: number, w: number, x: number, y: number, z: number, Windows: number, RightClick: number, numpad0: number, numpad1: number, numpad2: number, numpad3: number, numpad4: number, numpad5: number, numpad6: number, numpad7: number, numpad8: number, numpad9: number, MultiplyNumpad: number, PlusNumpad: number, MinusNumpad: number, DotNumpad: number, SlashNumpad: number, F1: number, F2: number, F3: number, F4: number, F5: number, F6: number, F7: number, F8: number, F9: number, F10: number, F11: number, F12: number, NumLock: number, ScrollLock: number, MyComputer: number, MyCalculator: number, Semicolon: number, Equal: number, Comma: number, Hyphen: number, Dot: number, Slash: number, Backquote: number, LeftBracket: number, Backslash: number, RightBracket: number, Quote: number, Command: number}, keyName: {Unidentified: string, Alt: string, AltGr: string, CapsLock: string, Ctrl: string, Fn: string, FnLock: string, Hyper: string, Meta: string, Windows: string, Command: string, NumLock: string, ScrollLock: string, Shift: string, Super: string, Symbol: string, SymbolLock: string, Enter: string, Tab: string, Space: string, DownArrow: string, LeftArrow: string, RightArrow: string, UpArrow: string, End: string, Home: string, PageDown: string, PageUp: string, Backspace: string, Clear: string, Copy: string, CrSel: string, Cut: string, Delete: string, EraseEof: string, ExSel: string, Insert: string, Paste: string, Redo: string, Undo: string, Accept: string, Again: string, Attn: string, Cancel: string, ContextMenu: string, Esc: string, Execute: string, Find: string, Finish: string, Help: string, Pause: string, Play: string, Props: string, Select: string, ZoomIn: string, ZoomOut: string, BrightnessDown: string, BrightnessUp: string, Eject: string, LogOff: string, Power: string, PowerOff: string, PrintScreen: string, Hibernate: string, Standby: string, WakeUp: string, Compose: string, Dead: string, F1: string, F2: string, F3: string, F4: string, F5: string, F6: string, F7: string, F8: string, F9: string, F10: string, F11: string, F12: string, Print: string, num0: string, num1: string, num2: string, num3: string, num4: string, num5: string, num6: string, num7: string, num8: string, num9: string, a: string, b: string, c: string, d: string, e: string, f: string, g: string, h: string, i: string, j: string, k: string, l: string, m: string, n: string, o: string, p: string, q: string, r: string, s: string, t: string, u: string, v: string, w: string, x: string, y: string, z: string, Semicolon: string, Equal: string, Comma: string, Hyphen: string, Minus: string, Plus: string, Dot: string, Slash: string, Backquote: string, LeftBracket: string, RightBracket: string, Backslash: string, Quote: string, numpad0: string, numpad1: string, numpad2: string, numpad3: string, numpad4: string, numpad5: string, numpad6: string, numpad7: string, numpad8: string, numpad9: string, NumpadDot: string, NumpadDotAlt: string, NumpadMultiply: string, NumpadPlus: string, NumpadMinus: string, NumpadSlash: string, NumpadDotObsoleteBrowsers: string, NumpadMultiplyObsoleteBrowsers: string, NumpadPlusObsoleteBrowsers: string, NumpadMinusObsoleteBrowsers: string, NumpadSlashObsoleteBrowsers: string}}} | ||
* @type {{ allowedTagList: [string], keyCode: {}, fromCharCodeKeyCode: [string], keyName: {} }} | ||
*/ | ||
@@ -77,3 +77,5 @@ const AutoNumericEnum = { | ||
* Wrapper variable that hold named keyboard keys with their respective keyCode as seen in DOM events. | ||
* //TODO Replace every call to this object with a call to `keyName` | ||
* cf. https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode | ||
* | ||
* This deprecated information is used for obsolete browsers. | ||
* @deprecated | ||
@@ -84,9 +86,17 @@ */ | ||
Tab: 9, | ||
// No 10, 11 | ||
// 12 === NumpadEqual on Windows | ||
// 12 === NumLock on Mac | ||
Enter: 13, | ||
// 14 reserved, but not used | ||
// 15 does not exists | ||
Shift: 16, | ||
Ctrl: 17, | ||
Alt: 18, | ||
PauseBreak: 19, | ||
Pause: 19, | ||
CapsLock: 20, | ||
// 21, 22, 23, 24, 25 : Asiatic key codes | ||
// 26 does not exists | ||
Esc: 27, | ||
// 28, 29, 30, 31 : Convert, NonConvert, Accept and ModeChange keys | ||
Space: 32, | ||
@@ -139,4 +149,5 @@ PageUp: 33, | ||
z: 90, | ||
Windows: 91, | ||
RightClick: 93, | ||
OSLeft: 91, | ||
OSRight: 92, | ||
ContextMenu: 93, | ||
numpad0: 96, | ||
@@ -185,5 +196,12 @@ numpad1: 97, | ||
Command: 224, | ||
AltGraph: 225, | ||
}, | ||
/** | ||
* This object is the reverse of `keyCode`, and is used to translate the key code to named keys when no valid characters can be obtained by `String.fromCharCode`. | ||
* Note: this sparse array is initialized later in the source code. | ||
*/ | ||
fromCharCodeKeyCode: [], | ||
/** | ||
* Wrapper variable that hold named keyboard keys with their respective key name (as set in KeyboardEvent.key). | ||
@@ -205,5 +223,6 @@ * Those names are listed here : | ||
Hyper: 'Hyper', // 'OS' under Firefox | ||
Meta: 'Meta', // The Windows, Command or ⌘ key // 'OS' under Firefox and IE9 | ||
Windows: 'Meta', // This is a non-official key name | ||
Command: 'Meta', // This is a non-official key name | ||
Meta: 'Meta', | ||
OSLeft: 'OS', | ||
OSRight: 'OS', | ||
Command: 'OS', | ||
NumLock: 'NumLock', | ||
@@ -222,10 +241,10 @@ ScrollLock: 'ScrollLock', | ||
// Navigation keys | ||
DownArrow: 'ArrowDown', // 'Down' for Firefox <=36, and IE9 | ||
LeftArrow: 'ArrowLeft', // 'Left' for Firefox <=36, and IE9 | ||
UpArrow: 'ArrowUp', // 'Up' for Firefox <=36, and IE9 | ||
RightArrow: 'ArrowRight', // 'Right' for Firefox <=36, and IE9 | ||
UpArrow: 'ArrowUp', // 'Up' for Firefox <=36, and IE9 | ||
DownArrow: 'ArrowDown', // 'Down' for Firefox <=36, and IE9 | ||
End: 'End', | ||
Home: 'Home', | ||
PageUp: 'PageUp', | ||
PageDown: 'PageDown', | ||
PageUp: 'PageUp', | ||
@@ -370,5 +389,116 @@ // Editing keys | ||
NumpadSlashObsoleteBrowsers: 'Divide', | ||
// Special arrays for quicker tests | ||
_allFnKeys: ['F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12'], | ||
_someNonPrintableKeys: ['Tab', 'Enter', 'Shift', 'ShiftLeft', 'ShiftRight', 'Control', 'ControlLeft', 'ControlRight', 'Alt', 'AltLeft', 'AltRight', 'Pause', 'CapsLock', 'Escape'], | ||
_directionKeys: ['PageUp', 'PageDown', 'End', 'Home', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp'], | ||
}, | ||
}; | ||
// Here we populate the sparse array that uses the `event.keyCode` as index, and returns the corresponding key name (à la event.key) | ||
AutoNumericEnum.fromCharCodeKeyCode[0] = 'LaunchCalculator'; | ||
AutoNumericEnum.fromCharCodeKeyCode[8] = 'Backspace'; | ||
AutoNumericEnum.fromCharCodeKeyCode[9] = 'Tab'; | ||
AutoNumericEnum.fromCharCodeKeyCode[13] = 'Enter'; | ||
AutoNumericEnum.fromCharCodeKeyCode[16] = 'Shift'; | ||
AutoNumericEnum.fromCharCodeKeyCode[17] = 'Ctrl'; | ||
AutoNumericEnum.fromCharCodeKeyCode[18] = 'Alt'; | ||
AutoNumericEnum.fromCharCodeKeyCode[19] = 'Pause'; | ||
AutoNumericEnum.fromCharCodeKeyCode[20] = 'CapsLock'; | ||
AutoNumericEnum.fromCharCodeKeyCode[27] = 'Escape'; | ||
AutoNumericEnum.fromCharCodeKeyCode[32] = ' '; | ||
AutoNumericEnum.fromCharCodeKeyCode[33] = 'PageUp'; | ||
AutoNumericEnum.fromCharCodeKeyCode[34] = 'PageDown'; | ||
AutoNumericEnum.fromCharCodeKeyCode[35] = 'End'; | ||
AutoNumericEnum.fromCharCodeKeyCode[36] = 'Home'; | ||
AutoNumericEnum.fromCharCodeKeyCode[37] = 'ArrowLeft'; | ||
AutoNumericEnum.fromCharCodeKeyCode[38] = 'ArrowUp'; | ||
AutoNumericEnum.fromCharCodeKeyCode[39] = 'ArrowRight'; | ||
AutoNumericEnum.fromCharCodeKeyCode[40] = 'ArrowDown'; | ||
AutoNumericEnum.fromCharCodeKeyCode[45] = 'Insert'; | ||
AutoNumericEnum.fromCharCodeKeyCode[46] = 'Delete'; | ||
AutoNumericEnum.fromCharCodeKeyCode[48] = '0'; | ||
AutoNumericEnum.fromCharCodeKeyCode[49] = '1'; | ||
AutoNumericEnum.fromCharCodeKeyCode[50] = '2'; | ||
AutoNumericEnum.fromCharCodeKeyCode[51] = '3'; | ||
AutoNumericEnum.fromCharCodeKeyCode[52] = '4'; | ||
AutoNumericEnum.fromCharCodeKeyCode[53] = '5'; | ||
AutoNumericEnum.fromCharCodeKeyCode[54] = '6'; | ||
AutoNumericEnum.fromCharCodeKeyCode[55] = '7'; | ||
AutoNumericEnum.fromCharCodeKeyCode[56] = '8'; | ||
AutoNumericEnum.fromCharCodeKeyCode[57] = '9'; | ||
// [65, 'a'], | ||
// [66, 'b'], | ||
// [67, 'c'], | ||
// [68, 'd'], | ||
// [69, 'e'], | ||
// [70, 'f'], | ||
// [71, 'g'], | ||
// [72, 'h'], | ||
// [73, 'i'], | ||
// [74, 'j'], | ||
// [75, 'k'], | ||
// [76, 'l'], | ||
// [77, 'm'], | ||
// [78, 'n'], | ||
// [79, 'o'], | ||
// [80, 'p'], | ||
// [81, 'q'], | ||
// [82, 'r'], | ||
// [83, 's'], | ||
// [84, 't'], | ||
// [85, 'u'], | ||
// [86, 'v'], | ||
// [87, 'w'], | ||
// [88, 'x'], | ||
// [89, 'y'], | ||
// [90, 'z'], | ||
AutoNumericEnum.fromCharCodeKeyCode[91] = 'OS'; // Note: Firefox and Chrome reports 'OS' instead of 'OSLeft' | ||
AutoNumericEnum.fromCharCodeKeyCode[92] = 'OSRight'; | ||
AutoNumericEnum.fromCharCodeKeyCode[93] = 'ContextMenu'; | ||
AutoNumericEnum.fromCharCodeKeyCode[96] = '0'; | ||
AutoNumericEnum.fromCharCodeKeyCode[97] = '1'; | ||
AutoNumericEnum.fromCharCodeKeyCode[98] = '2'; | ||
AutoNumericEnum.fromCharCodeKeyCode[99] = '3'; | ||
AutoNumericEnum.fromCharCodeKeyCode[100] = '4'; | ||
AutoNumericEnum.fromCharCodeKeyCode[101] = '5'; | ||
AutoNumericEnum.fromCharCodeKeyCode[102] = '6'; | ||
AutoNumericEnum.fromCharCodeKeyCode[103] = '7'; | ||
AutoNumericEnum.fromCharCodeKeyCode[104] = '8'; | ||
AutoNumericEnum.fromCharCodeKeyCode[105] = '9'; | ||
AutoNumericEnum.fromCharCodeKeyCode[106] = '*'; | ||
AutoNumericEnum.fromCharCodeKeyCode[107] = '+'; | ||
AutoNumericEnum.fromCharCodeKeyCode[109] = '-'; | ||
AutoNumericEnum.fromCharCodeKeyCode[110] = '.'; | ||
AutoNumericEnum.fromCharCodeKeyCode[111] = '/'; | ||
AutoNumericEnum.fromCharCodeKeyCode[112] = 'F1'; | ||
AutoNumericEnum.fromCharCodeKeyCode[113] = 'F2'; | ||
AutoNumericEnum.fromCharCodeKeyCode[114] = 'F3'; | ||
AutoNumericEnum.fromCharCodeKeyCode[115] = 'F4'; | ||
AutoNumericEnum.fromCharCodeKeyCode[116] = 'F5'; | ||
AutoNumericEnum.fromCharCodeKeyCode[117] = 'F6'; | ||
AutoNumericEnum.fromCharCodeKeyCode[118] = 'F7'; | ||
AutoNumericEnum.fromCharCodeKeyCode[119] = 'F8'; | ||
AutoNumericEnum.fromCharCodeKeyCode[120] = 'F9'; | ||
AutoNumericEnum.fromCharCodeKeyCode[121] = 'F10'; | ||
AutoNumericEnum.fromCharCodeKeyCode[122] = 'F11'; | ||
AutoNumericEnum.fromCharCodeKeyCode[123] = 'F12'; | ||
AutoNumericEnum.fromCharCodeKeyCode[144] = 'NumLock'; | ||
AutoNumericEnum.fromCharCodeKeyCode[145] = 'ScrollLock'; | ||
AutoNumericEnum.fromCharCodeKeyCode[182] = 'MyComputer'; | ||
AutoNumericEnum.fromCharCodeKeyCode[183] = 'MyCalculator'; | ||
AutoNumericEnum.fromCharCodeKeyCode[186] = ';'; | ||
AutoNumericEnum.fromCharCodeKeyCode[187] = '='; | ||
AutoNumericEnum.fromCharCodeKeyCode[188] = ','; | ||
AutoNumericEnum.fromCharCodeKeyCode[189] = '-'; | ||
AutoNumericEnum.fromCharCodeKeyCode[190] = '.'; | ||
AutoNumericEnum.fromCharCodeKeyCode[191] = '/'; | ||
AutoNumericEnum.fromCharCodeKeyCode[192] = '`'; | ||
AutoNumericEnum.fromCharCodeKeyCode[219] = '['; | ||
AutoNumericEnum.fromCharCodeKeyCode[220] = '\\'; | ||
AutoNumericEnum.fromCharCodeKeyCode[221] = ']'; | ||
AutoNumericEnum.fromCharCodeKeyCode[222] = "'"; | ||
AutoNumericEnum.fromCharCodeKeyCode[224] = 'Meta'; | ||
AutoNumericEnum.fromCharCodeKeyCode[225] = 'AltGraph'; | ||
export default AutoNumericEnum; |
@@ -251,3 +251,3 @@ /** | ||
*/ | ||
static isInputElement(domElement) { //FIXME à terminer | ||
static isInputElement(domElement) { | ||
return this.isElement(domElement) && domElement.tagName.toLowerCase() === 'input'; | ||
@@ -290,2 +290,3 @@ } | ||
// `event.keyCode` and `event.which` are deprecated, `KeyboardEvent.key` (https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) must be used now | ||
// Also, do note that Firefox generate a 'keypress' event (e.keyCode === 0) for the keys that do not print a character (ie. 'Insert', 'Delete', 'Fn' keys, 'PageUp', 'PageDown' etc.). 'Shift' on the other hand does not generate a keypress event. | ||
return (typeof event.which === 'undefined')?event.keyCode:event.which; | ||
@@ -296,2 +297,3 @@ } | ||
* Return the character from the event key code. | ||
* If the KeyboardEvent does not represent a printable character, then the key name is used (ie. 'Meta', 'Shift', 'F1', etc.) | ||
* @example character(50) => '2' | ||
@@ -303,39 +305,129 @@ * | ||
static character(event) { | ||
if (typeof event.key === 'undefined' || event.key === 'Unidentified') { | ||
return String.fromCharCode(this.keyCodeNumber(event)); | ||
let result; | ||
if (event.key === 'Unidentified' || event.key === void(0) || this.isSeleniumBot()) { | ||
//XXX The selenium geckodriver do not understand `event.key`, hence when using it, we need to rely on the old deprecated `keyCode` attribute, cf. upstream issue https://github.com/mozilla/geckodriver/issues/440 | ||
// Use the old deprecated keyCode property, if the new `key` one is not supported | ||
const keyCode = this.keyCodeNumber(event); | ||
const potentialResult = AutoNumericEnum.fromCharCodeKeyCode[keyCode]; | ||
if (!AutoNumericHelper.isUndefinedOrNullOrEmpty(potentialResult)) { | ||
// Since `String.fromCharCode` do not return named keys for some keys ('Escape' and 'Enter' for instance), we convert the characters to the key names | ||
result = potentialResult; | ||
} else { | ||
result = String.fromCharCode(keyCode); | ||
} | ||
} else { | ||
// Special case for obsolete browsers like IE that return the old names | ||
let result; | ||
let browser; | ||
switch (event.key) { | ||
// Manages all the special cases for obsolete browsers that return the non-standard names | ||
case 'Add': | ||
result = AutoNumericEnum.keyName.NumpadPlus; | ||
break; | ||
case 'Apps': | ||
result = AutoNumericEnum.keyName.ContextMenu; | ||
break; | ||
case 'Crsel': | ||
result = AutoNumericEnum.keyName.CrSel; | ||
break; | ||
case 'Decimal': | ||
result = AutoNumericEnum.keyName.NumpadDot; | ||
break; | ||
case 'Del': | ||
browser = this.browser(); | ||
if ((browser.name = 'firefox' && browser.version <= 36) || | ||
(browser.name = 'ie' && browser.version <= 9)) { | ||
// Special workaround for the obsolete browser IE11 which output a 'Delete' key when using the numpad 'dot' one! This fixes issue #401 | ||
// This workaround break the usage of the 'Delete' key for Firefox <=36, and IE9, since those browser send 'Del' instead of 'Delete', therefore we only use it for those obsolete browsers | ||
result = AutoNumericEnum.keyName.Dot; | ||
} else { | ||
result = AutoNumericEnum.keyName.Delete; | ||
} | ||
break; | ||
case 'Divide': | ||
result = AutoNumericEnum.keyName.NumpadSlash; | ||
break; | ||
case 'Down': | ||
result = AutoNumericEnum.keyName.DownArrow; | ||
break; | ||
case 'Esc': | ||
result = AutoNumericEnum.keyName.Esc; | ||
break; | ||
case 'Exsel': | ||
result = AutoNumericEnum.keyName.ExSel; | ||
break; | ||
case 'Left': | ||
result = AutoNumericEnum.keyName.LeftArrow; | ||
break; | ||
case 'Meta': | ||
case 'Super': | ||
result = AutoNumericEnum.keyName.OSLeft; | ||
break; | ||
case 'Multiply': | ||
result = AutoNumericEnum.keyName.NumpadMultiply; | ||
break; | ||
case 'Add': | ||
result = AutoNumericEnum.keyName.NumpadPlus; | ||
case 'Right': | ||
result = AutoNumericEnum.keyName.RightArrow; | ||
break; | ||
case 'Spacebar': | ||
result = AutoNumericEnum.keyName.Space; | ||
break; | ||
case 'Subtract': | ||
result = AutoNumericEnum.keyName.NumpadMinus; | ||
break; | ||
case 'Divide': | ||
result = AutoNumericEnum.keyName.NumpadSlash; | ||
case 'Up': | ||
result = AutoNumericEnum.keyName.UpArrow; | ||
break; | ||
case 'Del': | ||
// Special workaround for the obsolete browser IE11 which output a 'Delete' key when using the numpad 'dot' one! This fixes issue #401 | ||
//FIXME This workaround will break the usage of the 'Delete' key for Firefox <=36, and IE9, since those browser send 'Del' instead of 'Delete' | ||
// As of version 2.0.9, when the character() function is called, it's never to test for the 'Delete' key name | ||
// The 'Del' does not throw the keypress event so right now this hack is acceptable (but could bite us back if we where to use the `character()` functions in other events. | ||
result = AutoNumericEnum.keyName.Dot; | ||
break; | ||
default: | ||
// The normal case | ||
result = event.key; | ||
} | ||
} | ||
return result; | ||
return result; | ||
} | ||
/** | ||
* Return an object containing the name and version of the current browser. | ||
* @example `browserVersion()` => { name: 'Firefox', version: '42' } | ||
* Based on http://stackoverflow.com/a/38080051/2834898 | ||
* | ||
* @returns {{ name: string, version: string }} | ||
*/ | ||
static browser() { | ||
const ua = navigator.userAgent; | ||
let tem; | ||
let M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; | ||
if (/trident/i.test(M[1])) { | ||
tem = /\brv[ :]+(\d+)/g.exec(ua) || []; | ||
return { name: 'ie', version: (tem[1] || '') }; | ||
} | ||
if (M[1] === 'Chrome') { | ||
tem = ua.match(/\b(OPR|Edge)\/(\d+)/); | ||
if (tem !== null) { | ||
return { name: tem[1].replace('OPR', 'opera'), version: tem[2] }; | ||
} | ||
} | ||
M = M[2]?[M[1], M[2]]:[navigator.appName, navigator.appVersion, '-?']; | ||
if ((tem = ua.match(/version\/(\d+)/i)) !== null) { | ||
M.splice(1, 1, tem[1]); | ||
} | ||
return { name: M[0].toLowerCase(), version: M[1] }; | ||
} | ||
/** | ||
* Check if the browser is controlled by Selenium. | ||
* Note: This only works within the geckodriver. | ||
* cf. http://stackoverflow.com/questions/33225947/can-a-website-detect-when-you-are-using-selenium-with-chromedriver | ||
* | ||
* @returns {boolean} | ||
*/ | ||
static isSeleniumBot() { | ||
// noinspection JSUnresolvedVariable | ||
return window.navigator.webdriver === true; | ||
} | ||
/** | ||
* Return `true` if the given string contains a negative sign : | ||
@@ -342,0 +434,0 @@ * - everywhere in the string (by default), or |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3086498
12520
625