Skip to content

Commit

Permalink
primefaces#3885 Refactor mobile checks to DomHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Jan 4, 2023
1 parent f33d614 commit fbde4b1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
4 changes: 1 addition & 3 deletions components/lib/chips/Chips.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ export const Chips = React.memo(
event.preventDefault();
} else if (props.separator === ',') {
// GitHub #3885 Android Opera gives strange code 229 for comma
const ANDROID_COMMA = 229;

if (event.key === props.separator || event.which === ANDROID_COMMA) {
if (event.key === props.separator || (DomHandler.isAndroid() && event.which === 229)) {
addItem(event, inputValue, true);
}
}
Expand Down
9 changes: 3 additions & 6 deletions components/lib/inputmask/InputMask.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,11 @@ export const InputMask = React.memo(
pos,
begin,
end;
let iPhone = /iphone/i.test(DomHandler.getUserAgent());

oldVal.current = elementRef.current.value;

//backspace, delete, and escape get special treatment
if (k === 8 || k === 46 || (iPhone && k === 127)) {
if (k === 8 || k === 46 || (DomHandler.isIOS() && k === 127)) {
pos = caret();
begin = pos.begin;
end = pos.end;
Expand Down Expand Up @@ -256,7 +255,7 @@ export const InputMask = React.memo(
writeBuffer();
next = seekNext(p);

if (/android/i.test(DomHandler.getUserAgent())) {
if (DomHandler.isAndroid()) {
//Path for CSP Violation on FireFox OS 1.1
let proxy = () => {
caret(next);
Expand Down Expand Up @@ -494,9 +493,7 @@ export const InputMask = React.memo(
'*': '[A-Za-z0-9]'
};

let ua = DomHandler.getUserAgent();

androidChrome.current = /chrome/i.test(ua) && /android/i.test(ua);
androidChrome.current = DomHandler.isChrome() && DomHandler.isAndroid();

let maskTokens = props.mask.split('');

Expand Down
4 changes: 4 additions & 0 deletions components/lib/utils/DomHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ export default class DomHandler {
return /(android)/i.test(navigator.userAgent);
}

static isChrome() {
return /(chrome)/i.test(navigator.userAgent);
}

static isTouchDevice() {
return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
}
Expand Down
9 changes: 3 additions & 6 deletions components/lib/utils/Mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,11 @@ export function mask(el, options) {
pos,
begin,
end;
let iPhone = /iphone/i.test(DomHandler.getUserAgent());

oldVal = el.value;

//backspace, delete, and escape get special treatment
if (k === 8 || k === 46 || (iPhone && k === 127)) {
if (k === 8 || k === 46 || (DomHandler.isIOS() && k === 127)) {
pos = caret();
begin = pos.begin;
end = pos.end;
Expand Down Expand Up @@ -243,7 +242,7 @@ export function mask(el, options) {
writeBuffer();
next = seekNext(p);

if (/android/i.test(DomHandler.getUserAgent())) {
if (DomHandler.isAndroid()) {
//Path for CSP Violation on FireFox OS 1.1
let proxy = () => {
caret(next);
Expand Down Expand Up @@ -453,9 +452,7 @@ export function mask(el, options) {
'*': '[A-Za-z0-9]'
};

let ua = DomHandler.getUserAgent();

androidChrome = /chrome/i.test(ua) && /android/i.test(ua);
androidChrome = DomHandler.isChrome() && DomHandler.isAndroid();

let maskTokens = options.mask.split('');

Expand Down

0 comments on commit fbde4b1

Please sign in to comment.