From f29b4858453b564e15c2f1ef6a6d9e6c7c33bc52 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 20 May 2016 16:39:50 +0200 Subject: [PATCH] Fixed a few issues related to the site search feature --- .../js/WoltLab/WCF/Ui/Page/Header/Fixed.js | 1 - .../files/js/WoltLab/WCF/Ui/Search/Input.js | 15 ++++++++++++-- .../files/lib/form/SearchForm.class.php | 20 +++++++++++++++---- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Page/Header/Fixed.js b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Page/Header/Fixed.js index 7767452fb6..8f7fd79ddd 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Page/Header/Fixed.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Page/Header/Fixed.js @@ -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(); }); diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Search/Input.js b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Search/Input.js index ad9b046acd..93dd9f75d4 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Search/Input.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Search/Input.js @@ -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 ", diff --git a/wcfsetup/install/files/lib/form/SearchForm.class.php b/wcfsetup/install/files/lib/form/SearchForm.class.php index c6d88d82d9..3a2030fd5a 100644 --- a/wcfsetup/install/files/lib/form/SearchForm.class.php +++ b/wcfsetup/install/files/lib/form/SearchForm.class.php @@ -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'; -- 2.20.1