From a96695da3a3168cd2921bcb6264c04fed568d9c8 Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 18 Mar 2026 13:45:39 -0400 Subject: [PATCH] Added a helper class for useragent utilities. --- src/helpers/session-helper.js | 45 +++++++++++++++++++++++++++++++++ src/helpers/useragent-helper.js | 42 ++++++++++++++++++++++++++++++ src/mixins/base-mixin.js | 28 -------------------- src/store/index.js | 4 +-- 4 files changed, 89 insertions(+), 30 deletions(-) create mode 100644 src/helpers/useragent-helper.js diff --git a/src/helpers/session-helper.js b/src/helpers/session-helper.js index a82e1618..47185a25 100644 --- a/src/helpers/session-helper.js +++ b/src/helpers/session-helper.js @@ -47,3 +47,48 @@ export function getDateForSavedSessionTimeout() { currentDate.setDate(currentDate.getDate() + applicationConfig.SAVED_SESSION_TIMEOUT_DAYS); return currentDate.toUTCString(); } + + +/* +Function to return the iOS version of the device. +*/ + +export function getiOSversion() { + if (/iP(hone|od|ad)/.test(navigator.platform)) { + // supports iOS 2.0 and later: + var v = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/); + return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)]; + } +} + +/* +Function to return true/false if the user agent is a mobile device or not. +*/ + +export function isMobileDevice() { + const userAgent = navigator.userAgent; + return ( + userAgent.includes("Android") || + userAgent.includes("Mobile") || + userAgent.includes("iPod") || + userAgent.includes("iPhone") || + userAgent.includes("IEMobile") || + userAgent.includes("BlackBerry") || + userAgent.includes("webOS") + ); +} + +/* +Function to return true/false if the user is using an apple browser on a device. +*/ + +export function isAppleBrowser() { + const userAgent = navigator.userAgent; + return ( + userAgent.includes("iPod") || + userAgent.includes("iPad") || + userAgent.includes("iPhone") || + userAgent.includes("Mac") + ); +} + diff --git a/src/helpers/useragent-helper.js b/src/helpers/useragent-helper.js new file mode 100644 index 00000000..d1db7efe --- /dev/null +++ b/src/helpers/useragent-helper.js @@ -0,0 +1,42 @@ +/* +Function to return the iOS version of the device. +*/ + +export function getiOSversion() { + if (/iP(hone|od|ad)/.test(navigator.platform)) { + // supports iOS 2.0 and later: + var v = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/); + return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)]; + } +} + +/* +Function to return true/false if the user agent is a mobile device or not. +*/ + +export function isMobileDevice() { + const userAgent = navigator.userAgent; + return ( + userAgent.includes("Android") || + userAgent.includes("Mobile") || + userAgent.includes("iPod") || + userAgent.includes("iPhone") || + userAgent.includes("IEMobile") || + userAgent.includes("BlackBerry") || + userAgent.includes("webOS") + ); +} + +/* +Function to return true/false if the user is using an apple browser on a device. +*/ + +export function isAppleBrowser() { + const userAgent = navigator.userAgent; + return ( + userAgent.includes("iPod") || + userAgent.includes("iPad") || + userAgent.includes("iPhone") || + userAgent.includes("Mac") + ); +} \ No newline at end of file diff --git a/src/mixins/base-mixin.js b/src/mixins/base-mixin.js index dcf83070..ac36cbf0 100644 --- a/src/mixins/base-mixin.js +++ b/src/mixins/base-mixin.js @@ -43,34 +43,6 @@ export default { scrollToPageBottom() { const container = document.getElementsByClassName('fade-on-route-transition')[0]; container.scrollTo({ top: container.scrollHeight, left: 0, behavior: 'smooth' }); - }, - getiOSversion() { - if (/iP(hone|od|ad)/.test(navigator.platform)) { - // supports iOS 2.0 and later: - var v = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/); - return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)]; - } - }, - isMobileDevice() { - const userAgent = navigator.userAgent; - return ( - userAgent.includes("Android") || - userAgent.includes("Mobile") || - userAgent.includes("iPod") || - userAgent.includes("iPhone") || - userAgent.includes("IEMobile") || - userAgent.includes("BlackBerry") || - userAgent.includes("webOS") - ); - }, - isAppleBrowser() { - const userAgent = navigator.userAgent; - return ( - userAgent.includes("iPod") || - userAgent.includes("iPad") || - userAgent.includes("iPhone") || - userAgent.includes("Mac") - ); } }, computed: { diff --git a/src/store/index.js b/src/store/index.js index f43ace52..6622f9b3 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -24,9 +24,9 @@ import { import { buildURLSearchParams, getPartNumbersListForQueryString } from '@/helpers/querystring-helper'; import { getTopLevelGlassPartsWithRecal } from '@/helpers/recal-helper'; import { getDateForSavedSessionTimeout } from '@/helpers/session-helper'; +import { isMobileDevice } from '@/helpers/useragent-helper'; import issPageValues from '@/router/router-constants/issPage-values'; import CoverageStatuses from '@/constants/coverage-statuses'; -import baseMixin from '@/mixins/base-mixin'; const storeId = 'main'; @@ -2645,7 +2645,7 @@ export const useMainStore = defineStore({ actionName: actionName ?? "", referralSequenceNumber: referralSequenceNumber ?? "", referralNumber: referralNumber ?? "", - applicationName: baseMixin.methods.isMobileDevice() ? "ISS Mobile" : "ISS", + applicationName: isMobileDevice() ? "ISS Mobile" : "ISS", workOrderId: workOrderId ?? "", workOrderNumber: workOrderNumber ?? "", conceptVariation: conceptVariation,