From f0adbc3c283684081af9dd92d196e29c862170cd Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Thu, 2 May 2024 20:04:24 +0200 Subject: [PATCH] WI world search allows quick-select --- public/css/world-info.css | 11 +++++++++++ public/scripts/world-info.js | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/public/css/world-info.css b/public/css/world-info.css index f7de3222a..df1917504 100644 --- a/public/css/world-info.css +++ b/public/css/world-info.css @@ -196,3 +196,14 @@ .WIEntryHeaderTitleMobile { display: none; } + +#world_info+span.select2-container .select2-selection__choice__display { + cursor: pointer; + margin-left: 1px; /* Fix weird alignment on the left side */ +} + +#world_info+span.select2-container .select2-selection__choice__display:hover { + background-color: #f1f1f1; + color: #333; + outline: none; + } diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index efd8782a3..24e29ca38 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -379,6 +379,7 @@ function setWorldInfoSettings(settings, data) { }); $('#world_info_sort_order').val(localStorage.getItem(SORT_ORDER_KEY) || '0'); + $('#world_info').trigger('change'); $('#world_editor_select').trigger('change'); eventSource.on(event_types.CHAT_CHANGED, () => { @@ -3114,6 +3115,23 @@ jQuery(() => { allowClear: true, closeOnSelect: false, }); + + // Subscribe world loading to the select2 multiselect items (We need to target the specific select2 control) + $('#world_info + span.select2-container').on('click', function (event) { + if ($(event.target).hasClass('select2-selection__choice__display')) { + event.preventDefault(); + + // select2 still bubbles the event to open the dropdown. So we close it here + $('#world_info').select2('close'); + + const name = $(event.target).text(); + const selectedIndex = world_names.indexOf(name); + if (selectedIndex !== -1) { + $('#world_editor_select').val(selectedIndex).trigger('change'); + console.log('Quick selection of world', name); + } + } + }); } $('#WorldInfo').on('scroll', () => {