File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change 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 / A n d r o i d | w e b O S | i P h o n e | i P a d | i P o d | B l a c k B e r r y | I E M o b i l e | O p e r a M i n i / 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 }
You can’t perform that action at this time.
0 commit comments