tabs: don't change tab selection if panel does not contain item #279

This commit is contained in:
Sören Weber 2022-06-22 22:16:22 +02:00
parent 47e9eb8ced
commit 5118f1982e
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589
2 changed files with 5 additions and 4 deletions

View file

@ -46,10 +46,10 @@ echo "Hello World!"
| **groupId** | `default` | Arbitrary name of the group the tab view belongs to.<br/><br/>Tab views with the same **groupId** sychronize their selected tab. This sychronization applies to the whole site! |
| _**&lt;content&gt;**_ | _&lt;empty&gt;_ | 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

View file

@ -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