From 02113fc22a376b47cd008e0bc38cba8905e075f6 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Mon, 6 Jan 2025 11:28:38 +1000 Subject: [PATCH] DEV: Add isTablet to capabilities service (#30562) We already had isIpadOS, but for some themes and components we really need to do different things if the user is on a tablet, including Android tablets. isTablet and isTabletScreen have been introduced to the capabilities service. isTablet is true if the screen size is a tablet, touch is detected, or we have already detected iPad OS, or the device matches tablet UAs isTabletScreen checks both portrait and landscape dimensions of 1280x600 which should cover most cases. --- .../javascripts/discourse/app/services/capabilities.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/assets/javascripts/discourse/app/services/capabilities.js b/app/assets/javascripts/discourse/app/services/capabilities.js index 37b40bd8d2f..5564628b70c 100644 --- a/app/assets/javascripts/discourse/app/services/capabilities.js +++ b/app/assets/javascripts/discourse/app/services/capabilities.js @@ -9,6 +9,14 @@ class Capabilities { isAndroid = ua.includes("Android"); isWinphone = ua.includes("Windows Phone"); isIpadOS = ua.includes("Mac OS") && !/iPhone|iPod/.test(ua) && this.touch; + isTabletScreen = + this.touch && + ((window.innerWidth >= 600 && window.innerWidth <= 1280) || + (window.innerHeight >= 600 && window.innerHeight <= 1280)); + isTablet = + this.isTabletScreen || + this.isIpadOS || + /iPad|Android(?!.*Mobile)|Tablet/.test(ua); isIOS = (/iPhone|iPod/.test(ua) || this.isIpadOS) && !window.MSStream; isApple =