From 95de6ad7b9636bb2dd091e8d8ec182770a582568 Mon Sep 17 00:00:00 2001 From: Jake Harding Date: Fri, 7 Mar 2014 21:45:37 -0800 Subject: [PATCH] Prevent clicks on scroll bar from closing dropdown in ie. Fixes #705. --- src/typeahead/typeahead.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index f835d995..5dc5957f 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -28,6 +28,29 @@ var Typeahead = (function() { $input = this.$node.find('.tt-input'); $hint = this.$node.find('.tt-hint'); + // #705: if there's scrollable overflow, ie doesn't support + // blur cancellations when the scrollbar is clicked + // + // #351: preventDefault won't cancel blurs in ie <= 8 + $input.on('blur.tt', function($e) { + var active, isActive, hasActive; + + active = document.activeElement; + isActive = $menu.is(active); + hasActive = $menu.has(active).length > 0; + + if (_.isMsie() && (isActive || hasActive)) { + $e.preventDefault(); + // stop immediate in order to prevent Input#_onBlur from + // getting exectued + $e.stopImmediatePropagation(); + _.defer(function() { $input.focus(); }); + } + }); + + // #351: prevents input blur due to clicks within dropdown menu + $menu.on('mousedown.tt', function($e) { $e.preventDefault(); }); + this.eventBus = o.eventBus || new EventBus({ el: $input }); this.dropdown = new Dropdown({ menu: $menu, datasets: o.datasets }) @@ -50,19 +73,6 @@ var Typeahead = (function() { .onSync('rightKeyed', this._onRightKeyed, this) .onSync('queryChanged', this._onQueryChanged, this) .onSync('whitespaceChanged', this._onWhitespaceChanged, this); - - // #351: prevents input blur on menu click - $menu.on('mousedown.tt', function($e) { - if (_.isMsie() && _.isMsie() < 9) { - $input[0].onbeforedeactivate = function() { - window.event.returnValue = false; - $input[0].onbeforedeactivate = null; - }; - } - - // ie 9+ and other browsers - $e.preventDefault(); - }); } // instance methods