Added ability to disable auto-focus of search results
authorAlexander Ebert <ebert@woltlab.com>
Mon, 3 Jun 2013 16:59:02 +0000 (18:59 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 3 Jun 2013 16:59:02 +0000 (18:59 +0200)
wcfsetup/install/files/js/WCF.Search.Message.js
wcfsetup/install/files/js/WCF.js

index 7203a571ea22abf3a11023919c0afac75dec44d4..ea05a2d206c31810414ba617e23119b126c0ed90 100644 (file)
@@ -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();
                                }
                        }
index 715599cc2deb3c6b721226ff13f835d9d49d943f..83b32fb4ddebba73b5ee98a2b94c320c2071ed64 100755 (executable)
@@ -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();
+               }
        },
        
        /**