From f15264e9771a2225f53b433db4711e636c944e0a Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Wed, 29 Jan 2020 14:24:15 -0300 Subject: [PATCH] FEATURE: Add Tactile feedback on likes --- .../discourse/pre-initializers/sniff-capabilities.js.es6 | 2 ++ app/assets/javascripts/discourse/widgets/post-menu.js.es6 | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/app/assets/javascripts/discourse/pre-initializers/sniff-capabilities.js.es6 b/app/assets/javascripts/discourse/pre-initializers/sniff-capabilities.js.es6 index 1e111506e8b..c8c35032ce2 100644 --- a/app/assets/javascripts/discourse/pre-initializers/sniff-capabilities.js.es6 +++ b/app/assets/javascripts/discourse/pre-initializers/sniff-capabilities.js.es6 @@ -46,6 +46,8 @@ export default { caps.hasContactPicker = "contacts" in navigator && "ContactsManager" in window; + + caps.canVibrate = "vibrate" in navigator; } // We consider high res a device with 1280 horizontal pixels. High DPI tablets like diff --git a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 b/app/assets/javascripts/discourse/widgets/post-menu.js.es6 index e7d51a1fa76..c833d8edf97 100644 --- a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-menu.js.es6 @@ -8,6 +8,7 @@ import { Promise } from "rsvp"; import ENV from "discourse-common/config/environment"; const LIKE_ACTION = 2; +const VIBRATE_DURATION = 5; function animateHeart($elem, start, end, complete) { if (ENV.environment === "test") { @@ -651,6 +652,10 @@ export default createWidget("post-menu", { return this.sendWidgetAction("showLogin"); } + if (this.capabilities.canVibrate) { + navigator.vibrate(VIBRATE_DURATION); + } + if (attrs.liked) { return this.sendWidgetAction("toggleLike"); }