From 2d305fef03c8351c807b5e88c8fd4f1d0fcb3c4a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 3 Jun 2013 18:59:02 +0200 Subject: [PATCH] Added ability to disable auto-focus of search results --- wcfsetup/install/files/js/WCF.Search.Message.js | 4 ++-- wcfsetup/install/files/js/WCF.js | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.Search.Message.js b/wcfsetup/install/files/js/WCF.Search.Message.js index 7203a571ea..ea05a2d206 100644 --- a/wcfsetup/install/files/js/WCF.Search.Message.js +++ b/wcfsetup/install/files/js/WCF.Search.Message.js @@ -43,8 +43,8 @@ WCF.Search.Message.KeywordList = WCF.Search.Base.extend({ this._searchInput = $(searchInput).keyup($.proxy(this._keyUp, this)).keydown($.proxy(function(event) { // block form submit if (event.which === 13) { - // ... unless there are no suggestions - if (this._itemCount) { + // ... unless there are no suggestions or suggestions are optional and none is selected + if (this._itemCount && this._itemIndex !== -1) { event.preventDefault(); } } diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 715599cc2d..83b32fb4dd 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -5253,7 +5253,7 @@ WCF.Search.Base = Class.extend({ * @param object event */ _keyDown: function(event) { - if (event.which === 13) { + if (event.which === 13 && this._itemIndex !== -1) { event.preventDefault(); } }, @@ -5447,13 +5447,16 @@ WCF.Search.Base = Class.extend({ WCF.CloseOverlayHandler.addCallback('WCF.Search.Base', $.proxy(function() { this._clearList(); }, this)); - if (!WCF.Dropdown.getDropdownMenu(this._searchInput.parents('.dropdown').wcfIdentify()).hasClass('dropdownOpen')) { - WCF.Dropdown.toggleDropdown(this._searchInput.parents('.dropdown').wcfIdentify()); + var $containerID = this._searchInput.parents('.dropdown').wcfIdentify(); + if (!WCF.Dropdown.getDropdownMenu($containerID).hasClass('dropdownOpen')) { + WCF.Dropdown.toggleDropdown($containerID); } // pre-select first item this._itemIndex = -1; - this._selectNextItem(); + if (!WCF.Dropdown.getDropdown($containerID).data('disableAutoFocus')) { + this._selectNextItem(); + } }, /** -- 2.20.1