From f269514b6fdd1b14e73be1b1b4032f589873d872 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 28 Sep 2015 18:29:08 +1000 Subject: [PATCH] FIX: Android is bad at firing touchend, which makes quoting impossible --- .../discourse/views/quote-button.js.es6 | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/views/quote-button.js.es6 b/app/assets/javascripts/discourse/views/quote-button.js.es6 index aa9fb1404bb..60cb2463a75 100644 --- a/app/assets/javascripts/discourse/views/quote-button.js.es6 +++ b/app/assets/javascripts/discourse/views/quote-button.js.es6 @@ -34,7 +34,9 @@ export default Ember.View.extend({ // best we can do is debounce this so we dont keep locking up // the selection when we add the caret to measure where we place // the quote reply widget - if (navigator.userAgent.match(/Windows Phone/)) { + // + // Same hack applied to Android cause it has unreliable touchend + if (navigator.userAgent.match(/Windows Phone/) || navigator.userAgent.match(/Android/)) { onSelectionChanged = _.debounce(onSelectionChanged, 500); } @@ -58,12 +60,6 @@ export default Ember.View.extend({ view.selectText(e.target, controller); view.set('isMouseDown', false); }) - .on('touchstart.quote-button', function(){ - view.set('isTouchInProgress', true); - }) - .on('touchend.quote-button', function(){ - view.set('isTouchInProgress', false); - }) .on('selectionchange', function() { // there is no need to handle this event when the mouse is down // or if there a touch in progress @@ -71,6 +67,18 @@ export default Ember.View.extend({ // `selection.anchorNode` is used as a target onSelectionChanged(); }); + + // Android is dodgy, touchend often will not fire + // https://code.google.com/p/android/issues/detail?id=19827 + if (!navigator.userAgent.match(/Android/)) { + $(document) + .on('touchstart.quote-button', function(){ + view.set('isTouchInProgress', true); + }) + .on('touchend.quote-button', function(){ + view.set('isTouchInProgress', false); + }); + } }, selectText(target, controller) {