DEV: Clean up `sniff-capabilities` (#14938)

DEV: Clean up sniff-capabilities (#14938)

Drop jQuery, remove unused caps (canPasteImages and highRes), enable canVibrate for Firefox (per the old comment), and other minor changes.

diff --git a/app/assets/javascripts/discourse/app/pre-initializers/sniff-capabilities.js b/app/assets/javascripts/discourse/app/pre-initializers/sniff-capabilities.js
index 80d7e4b..7567fa5 100644
--- a/app/assets/javascripts/discourse/app/pre-initializers/sniff-capabilities.js
+++ b/app/assets/javascripts/discourse/app/pre-initializers/sniff-capabilities.js
@@ -1,62 +1,41 @@
-/*global safari:true*/
-
-// Initializes an object that lets us know about our capabilities.
+// Initializes an object that lets us know about browser's capabilities
 export default {
   name: "sniff-capabilities",
-  initialize(container, application) {
-    const $html = $("html"),
-      touch = navigator.maxTouchPoints > 1 || "ontouchstart" in window,
-      caps = { touch };
-
-    // Store the touch ability in our capabilities object
-    $html.addClass(
-      touch ? "touch discourse-touch" : "no-touch discourse-no-touch"
-    );
-
-    // Detect Devices
-    if (navigator) {
-      const ua = navigator.userAgent;
-      if (ua) {
-        caps.isAndroid = ua.indexOf("Android") !== -1;
-        caps.isWinphone = ua.indexOf("Windows Phone") !== -1;
-
-        caps.isOpera = !!window.opera || ua.indexOf(" OPR/") >= 0;
-        caps.isFirefox = typeof InstallTrigger !== "undefined";
-        caps.isSafari =
-          Object.prototype.toString
-            .call(window.HTMLElement)
-            .indexOf("Constructor") > 0 ||
-          (function (p) {
-            return p.toString() === "[object SafariRemoteNotification]";
-          })(!window["safari"] || safari.pushNotification);
-        caps.isChrome = !!window.chrome && !caps.isOpera;
-
-        caps.canPasteImages = caps.isChrome || caps.isFirefox;
-      }
-
-      caps.isIpadOS =
-        ua.indexOf("Mac OS") !== -1 &&
-        !/iPhone|iPod/.test(navigator.userAgent) &&
-        touch;
-
-      caps.isIOS =
-        (/iPhone|iPod/.test(navigator.userAgent) || caps.isIpadOS) &&
-        !window.MSStream;
 
-      caps.hasContactPicker =
-        "contacts" in navigator && "ContactsManager" in window;
+  initialize(_, app) {
+    const html = document.querySelector("html");
+    const touch = navigator.maxTouchPoints > 1 || "ontouchstart" in window;
+    const ua = navigator.userAgent;
+    const caps = { touch };
 
-      caps.canVibrate = "vibrate" in navigator && !caps.isFirefox; // Remove Firefox condition when https://arewefenixyet.com/ lands
+    if (touch) {
+      html.classList.add("touch", "discourse-touch");
+    } else {
+      html.classList.add("no-touch", "discourse-no-touch");
     }
 
-    // We consider high res a device with 1280 horizontal pixels. High DPI tablets like
-    // iPads should report as 1024.
-    caps.highRes = window.screen.width >= 1280;
+    caps.isAndroid = ua.includes("Android");
+    caps.isWinphone = ua.includes("Windows Phone");
+    caps.isOpera = !!window.opera || ua.includes(" OPR/");
+    caps.isFirefox = typeof InstallTrigger !== "undefined";
+    caps.isChrome = !!window.chrome && !caps.isOpera;
+    caps.isSafari =
+      /Constructor/.test(window.HTMLElement) ||
+      window.safari?.pushNotification.toString() ===
+        "[object SafariRemoteNotification]";
+    caps.isIpadOS = ua.includes("Mac OS") && !/iPhone|iPod/.test(ua) && touch;
+    caps.isIOS =
+      (/iPhone|iPod/.test(navigator.userAgent) || caps.isIpadOS) &&
+      !window.MSStream;
+
+    caps.hasContactPicker =
+      "contacts" in navigator && "ContactsManager" in window;
+    caps.canVibrate = "vibrate" in navigator;
 
     // Inject it
-    application.register("capabilities:main", caps, { instantiate: false });
-    application.inject("view", "capabilities", "capabilities:main");
-    application.inject("controller", "capabilities", "capabilities:main");
-    application.inject("component", "capabilities", "capabilities:main");
+    app.register("capabilities:main", caps, { instantiate: false });
+    app.inject("view", "capabilities", "capabilities:main");
+    app.inject("controller", "capabilities", "capabilities:main");
+    app.inject("component", "capabilities", "capabilities:main");
   },
 };

GitHub sha: 985d079e4798219f178293eeb6aabce943bc9a15

This commit appears in #14938 which was approved by jjaffeux. It was merged by CvX.