Skip to content

Commit fa2938c

Browse files
Replace mobile check with hover support detection
1 parent feb2103 commit fa2938c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

assets/js/chatmkModal.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
*/
55

66
/**
7-
* Check if user is on a mobile device
7+
* Check if device supports hover (desktop) - if not, it's likely a touch device
88
*/
9-
function isMobileDevice() {
10-
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ||
11-
(window.innerWidth <= 768);
9+
function supportsHover() {
10+
return window.matchMedia('(hover: hover)').matches;
1211
}
1312

1413
/**
@@ -59,9 +58,9 @@ function openChatMKModal() {
5958
modal.style.display = 'block';
6059
modal.classList.add('is-active');
6160

62-
// Focus on the input field only on desktop
61+
// Focus on the input field only on devices that support hover (desktop)
6362
const input = modal.querySelector('#chatmk-input');
64-
if (input && !isMobileDevice()) {
63+
if (input && supportsHover()) {
6564
setTimeout(() => input.focus(), 100);
6665
}
6766

@@ -184,11 +183,11 @@ function newChatMKConversation() {
184183
messagesContainer.insertBefore(welcomeMessage, messagesContainer.firstChild);
185184
}
186185

187-
// Clear input and focus only on desktop
186+
// Clear input and focus only on devices that support hover (desktop)
188187
const input = document.getElementById('chatmk-input');
189188
if (input) {
190189
input.value = '';
191-
if (!isMobileDevice()) {
190+
if (supportsHover()) {
192191
input.focus();
193192
}
194193
}

0 commit comments

Comments
 (0)