Fixed a few issues related to the site search feature
authorAlexander Ebert <ebert@woltlab.com>
Fri, 20 May 2016 14:39:50 +0000 (16:39 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 20 May 2016 14:39:57 +0000 (16:39 +0200)
wcfsetup/install/files/js/WoltLab/WCF/Ui/Page/Header/Fixed.js
wcfsetup/install/files/js/WoltLab/WCF/Ui/Search/Input.js
wcfsetup/install/files/lib/form/SearchForm.class.php

index 7767452fb6ec33b35406739054f2872edb90544c..8f7fd79ddd63714496238ee429cc411d3da35b29 100644 (file)
@@ -56,7 +56,6 @@ define(['Core', 'EventHandler', 'Ui/Alignment', 'Ui/CloseOverlay', 'Ui/Screen',
                _initSearchBar: function() {
                        var searchContainer = elById('pageHeaderSearch');
                        searchContainer.addEventListener(WCF_CLICK_EVENT, function(event) {
-                               event.preventDefault();
                                event.stopPropagation();
                        });
                        
index ad9b046acd7476c2d642929b978bc05117bba209..93dd9f75d468521994e78f57939a2403b9c81926 100644 (file)
@@ -66,13 +66,13 @@ define(['Ajax', 'Core', 'EventKey', 'Dom/Util', 'Ui/SimpleDropdown'], function(A
                 * @protected
                 */
                _keydown: function(event) {
-                       if (this._activeItem !== null || this._options.preventSubmit) {
+                       if ((this._activeItem !== null && UiSimpleDropdown.isOpen(this._dropdownContainerId)) || this._options.preventSubmit) {
                                if (EventKey.Enter(event)) {
                                        event.preventDefault();
                                }
                        }
                        
-                       if (EventKey.ArrowUp(event) || EventKey.ArrowDown(event)) {
+                       if (EventKey.ArrowUp(event) || EventKey.ArrowDown(event) || EventKey.Escape(event)) {
                                event.preventDefault();
                        }
                },
@@ -86,6 +86,10 @@ define(['Ajax', 'Core', 'EventKey', 'Dom/Util', 'Ui/SimpleDropdown'], function(A
                _keyup: function(event) {
                        // handle dropdown keyboard navigation
                        if (this._activeItem !== null) {
+                               if (!UiSimpleDropdown.isOpen(this._dropdownContainerId)) {
+                                       return;
+                               }
+                               
                                if (EventKey.ArrowUp(event)) {
                                        event.preventDefault();
                                        
@@ -103,6 +107,13 @@ define(['Ajax', 'Core', 'EventKey', 'Dom/Util', 'Ui/SimpleDropdown'], function(A
                                }
                        }
                        
+                       // close list on escape
+                       if (EventKey.Escape(event)) {
+                               UiSimpleDropdown.close(this._dropdownContainerId);
+                               
+                               return;
+                       }
+                       
                        var value = this._element.value.trim();
                        if (this._lastValue === value) {
                                // value did not change, e.g. previously it was "Test" and now it is "Test ",
index c6d88d82d923f7d3a5e01bd4c8646da699461770..3a2030fd5af5bf8ff06161444e07604bd78c60f9 100644 (file)
@@ -156,10 +156,19 @@ class SearchForm extends AbstractCaptchaForm {
                if (isset($_REQUEST['types']) && is_array($_REQUEST['types'])) {
                        $this->selectedObjectTypes = $_REQUEST['types'];
                        
-                       // validate given values
-                       foreach ($this->selectedObjectTypes as $objectTypeName) {
-                               if (SearchEngine::getInstance()->getObjectType($objectTypeName) === null) {
-                                       throw new IllegalLinkException();
+                       // handle special selection to search in all areas
+                       if (isset($this->selectedObjectTypes[0]) && $this->selectedObjectTypes[0] === 'everywhere') {
+                               $this->selectedObjectTypes = [];
+                               foreach (SearchEngine::getInstance()->getAvailableObjectTypes() as $typeName => $typeObject) {
+                                       $this->selectedObjectTypes[] = $typeName;
+                               }
+                       }
+                       else {
+                               // validate given values
+                               foreach ($this->selectedObjectTypes as $objectTypeName) {
+                                       if (SearchEngine::getInstance()->getObjectType($objectTypeName) === null) {
+                                               throw new IllegalLinkException();
+                                       }
                                }
                        }
                }
@@ -207,7 +216,10 @@ class SearchForm extends AbstractCaptchaForm {
                        case 'subject':
                        case 'time':
                        case 'username': break;
+                       
+                       /** @noinspection PhpMissingBreakStatementInspection */
                        case 'relevance': if (!$this->submit || !empty($this->query)) break;
+                       
                        default: 
                                if (!$this->submit || !empty($this->query)) $this->sortField = 'relevance';
                                else $this->sortField = 'time';