From 71662ae8c19193989ccc3be58bd942b29201f663 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 18 Aug 2012 00:33:26 +0200 Subject: [PATCH] Improved ACP search and dropdown menu WCF.Dropdown now supports two alignments, left and right (relative to the outer element bounding). If you're using the HTML of dropdowns but no the JS (e.g. custom handler), don't forget to use WCF.Dropdown.setAlignment()! --- wcfsetup/install/files/acp/js/WCF.ACP.js | 35 ++++++ .../install/files/acp/templates/header.tpl | 2 + wcfsetup/install/files/js/WCF.js | 46 ++++++- .../ACPSearchProviderAction.class.php | 34 +++++- .../search/acp/ACPSearchHandler.class.php | 49 +++++++- .../search/acp/ACPSearchResultList.class.php | 34 +++++- .../MenuItemACPSearchResultProvider.class.php | 28 ++--- .../OptionACPSearchResultProvider.class.php | 115 ++++++++++++++++-- wcfsetup/install/files/style/dropdown.less | 12 ++ 9 files changed, 321 insertions(+), 34 deletions(-) diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index 3bcb5f3968..66996a8850 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -871,3 +871,38 @@ WCF.ACP.Category.Delete = WCF.Action.Delete.extend({ }, this)); } }); + +/** + * Provides the search dropdown for ACP + * + * @see WCF.Search.Base + */ +WCF.ACP.Search = WCF.Search.Base.extend({ + /** + * @see WCF.Search.Base.init() + */ + init: function() { + this._className = 'wcf\\data\\acp\\search\\provider\\ACPSearchProviderAction'; + this._super('#search input[name=q]'); + }, + + /** + * @see WCF.Search.Base._createListItem() + */ + _createListItem: function(resultList) { + // add a divider between result lists + if (this._list.children('li').length > 0) { + $('').appendTo(this._list); + + // add menu items + for (var $i in resultList.items) { + var $item = resultList.items[$i]; + + $('
  • ' + $item.title + '
  • ').appendTo(this._list); + } + } +}); diff --git a/wcfsetup/install/files/acp/templates/header.tpl b/wcfsetup/install/files/acp/templates/header.tpl index f7d006980f..b1875b38d0 100644 --- a/wcfsetup/install/files/acp/templates/header.tpl +++ b/wcfsetup/install/files/acp/templates/header.tpl @@ -96,6 +96,8 @@ WCF.Dropdown.init(); + new WCF.ACP.Search(); + {event name='javascriptInit'} }); //]]> diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 4ae278cb58..e65602cc48 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -583,6 +583,8 @@ WCF.Dropdown = { else if ($containerID === $targetID) { $dropdown.addClass('dropdownOpen'); this._notifyCallbacks($dropdown, 'open'); + + this.setAlignment($dropdown); } } @@ -590,6 +592,39 @@ WCF.Dropdown = { return false; }, + /** + * Sets alignment for dropdown. + * + * @param jQuery dropdown + * @param jQuery dropdownMenu + */ + setAlignment: function(dropdown, dropdownMenu) { + if (dropdown) { + var $dropdownMenu = dropdown.children('.dropdownMenu:eq(0)'); + } + else { + var $dropdownMenu = dropdownMenu; + } + + // calculate if dropdown should be right-aligned if there is not enough space + var $dimensions = $dropdownMenu.getDimensions('outer'); + var $offsets = $dropdownMenu.getOffsets('offset'); + var $windowWidth = $(window).width(); + + if (($offsets.left + $dimensions.width) > $windowWidth) { + $dropdownMenu.css({ + left: 'auto', + right: '0px' + }).addClass('dropdownArrowRight'); + } + else { + $dropdownMenu.css({ + left: '0px', + right: 'auto' + }).removeClass('dropdownArrowRight'); + } + }, + /** * Closes all dropdowns. */ @@ -4015,8 +4050,14 @@ WCF.Search.Base = Class.extend({ if (excludedSearchValues) { this._excludedSearchValues = excludedSearchValues; } - this._searchInput = $(searchInput).keyup($.proxy(this._keyUp, this)); - this._searchInput.wrap(''); + + this._searchInput = $(searchInput); + if (!this._searchInput.length) { + console.debug("[WCF.Search.Base] Selector '" + searchInput + "' for search input is invalid, aborting."); + return; + } + + this._searchInput.keyup($.proxy(this._keyUp, this)).wrap(''); this._list = $('