From d8ec2ccb233007975bae0ce841009db778ee4c01 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Fri, 15 Jul 2016 15:36:36 +0200 Subject: [PATCH] Fix chosen touch events handler to get it working for both iOS and Android --- api/js/jquery/chosen/chosen.jquery.js | 30 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/api/js/jquery/chosen/chosen.jquery.js b/api/js/jquery/chosen/chosen.jquery.js index 93cc387da9..94a432c82c 100644 --- a/api/js/jquery/chosen/chosen.jquery.js +++ b/api/js/jquery/chosen/chosen.jquery.js @@ -433,7 +433,19 @@ } return true; }; + AbstractChosen.prototype.search_results_touchstart = function(evt) { + this.touch_started = true; + }; + AbstractChosen.prototype.search_results_touchmove = function(evt) { + this.touch_started = false; + }; + + AbstractChosen.prototype.search_results_touchend = function(evt) { + if (this.touch_started) { + return this.search_results_mouseup(evt); + } + }; AbstractChosen.default_multiple_text = "Select Some Options"; AbstractChosen.default_single_text = "Select an Option"; @@ -565,13 +577,8 @@ _this.mouse_leave(evt); }); this.container.bind('touchstart', function(evt) { - _this.container_mousedown(evt); - return evt.preventDefault(); - }); - this.container.bind('touchend', function(evt) { - _this.mouse_leave(evt); - return evt.preventDefault(); - }); + _this.container_mousedown(evt); + }); this.search_results.mouseup(function(evt) { _this.search_results_mouseup(evt); }); @@ -581,11 +588,14 @@ this.search_results.mouseout(function(evt) { _this.search_results_mouseout(evt); }); - this.search_results.bind('touchstart', function(evt) { - _this.search_results_mouseover(evt); + this.search_results.bind('touchstart', function(evt) { + _this.search_results_touchstart(evt); }); + this.search_results.bind('touchmove', function(evt) { + _this.search_results_touchmove(evt); + }); this.search_results.bind('touchend', function(evt) { - _this.search_results_mouseup(evt); + _this.search_results_touchend(evt); }); this.search_results.bind('mousewheel DOMMouseScroll', function(evt) { _this.search_results_mousewheel(evt);