From 5118f1982e73edb2356c87f354d303c96dcb1d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Wed, 22 Jun 2022 22:16:22 +0200 Subject: [PATCH] tabs: don't change tab selection if panel does not contain item #279 --- exampleSite/content/shortcodes/tabs.en.md | 4 ++-- static/js/theme.js | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/exampleSite/content/shortcodes/tabs.en.md b/exampleSite/content/shortcodes/tabs.en.md index 1d876075be..11c2f145d0 100644 --- a/exampleSite/content/shortcodes/tabs.en.md +++ b/exampleSite/content/shortcodes/tabs.en.md @@ -46,10 +46,10 @@ echo "Hello World!" | **groupId** | `default` | Arbitrary name of the group the tab view belongs to.

Tab views with the same **groupId** sychronize their selected tab. This sychronization applies to the whole site! | | _**<content>**_ | _<empty>_ | Arbitrary number of tabs defined with the `tab` sub-shortcode. | -{{% notice warning %}} +{{% notice note %}} When using tab views with different content sets, make sure to use a common `groupId` for equal sets of tabs but distinct `groupId` for different sets. -The tab selection is restored automatically based on the `groupId` and if it cannot find a tab item because it came from the `'default'` group on a different page then all tabs will be empty at first! +The tab selection is restored automatically based on the `groupId` and if it cannot find a tab item because it came from the `'default'` group on a different page then the first tab is selected instead. {{% /notice %}} ## Examples diff --git a/static/js/theme.js b/static/js/theme.js index 11fc55644a..58567bcd02 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -19,8 +19,9 @@ var psm; var pst; function switchTab(tabGroup, tabId) { - allTabItems = jQuery("[data-tab-group='"+tabGroup+"']"); - targetTabItems = jQuery("[data-tab-group='"+tabGroup+"'][data-tab-item='"+tabId+"']"); + var tabs = jQuery(".tab-panel").has("[data-tab-group='"+tabGroup+"'][data-tab-item='"+tabId+"']"); + var allTabItems = tabs.find("[data-tab-group='"+tabGroup+"']"); + var targetTabItems = tabs.find("[data-tab-group='"+tabGroup+"'][data-tab-item='"+tabId+"']"); // if event is undefined then switchTab was called from restoreTabSelection // so it's not a button event and we don't need to safe the selction or