Joeytje50 has uploaded a new change for review. https://gerrit.wikimedia.org/r/184188
Change subject: Add nested="" attribute to tab tag ...................................................................... Add nested="" attribute to tab tag now it is possible to make nested toggle boxes or dropdowns have content that depends on the selected tab; simply put a {{#tab:}} or {{#tag:tab}} with |nested=true as last argument inside the toggle/dropdown box. Change-Id: I413ebfc42213ae6e88cd87343cc620fc62016571 --- M README.md M Tabs.body.php M Tabs.php 3 files changed, 33 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Tabs refs/changes/88/184188/1 diff --git a/README.md b/README.md index aedad16..d895546 100644 --- a/README.md +++ b/README.md @@ -360,6 +360,17 @@ |dropdown=true}} ===== Toggle boxes and dropdowns in tab boxes ===== + +If you want to place a toggle box or a dropdown inside a tab navigation, and want the toggle box to show up for every tab as opposed to just the tab it's nested in, first a parent <code><tab></code> tab must be made, with <code>index="*"</code>, so that the toggle box won't be recognised as a seperate tab content. + +If you want to place a toggle box or dropdown menu inside a tab menu, you can simply place a <code><tab></code> tag inside the <code><tab></code> tag that functions as a tab. This will restrict toggle boxes and dropdowns to visibility in just one tab though. So, if you want to have a toggle box or dropdown that's visible in every tab, encase it in a <code><tab></code> tag with an <code>index="*"</code> set to it. + +That way, the outer <code><tab></code> tag will be recognised as a tab container, and the inner one will be recognised as a toggle box or dropdown menu, as desired. The toggle box or dropdown must then also use the [[#General usage information|parser function syntax]]. + +If you want the contents of the toggle box inside the tab menu to be able to change depending on the selected tab, you should use the <code>nested="true"</code> attribute on the tag. This can be done by setting the very last argument of the <code>#tab:</code> parser function or the <code>#tag:tab</code> parser function to <code>nested=true</code>. + +See this demo for an example of how to make this work: + <tabs> <tab name="Toggle box"> This first tab has a toggle box nested inside it @@ -369,6 +380,9 @@ This second tab has a dropdown nested inside it {{#tag:tab|This dropdown is created via the <code>#tag:tab</code> parser function, since it's not possible to define attributes such as <code>dropdown</code> via the <code>#tab:</code> parser function.|dropdown=true}} </tab> +<tab index="*" block> +{{#tag:tab|This toggle box shows up inside {{#tab:|every|each of the|nested=true}} tab{{#tag:tab|s|index=2|nested=true}}, because the containing tab tag has got its index attribute set to <code>index="*"</code>. It also has a <code>block</code> attribute.|openname=Open|closename=Close}} +</tab> </tabs> ===== Toggle boxes in dropdowns ===== diff --git a/Tabs.body.php b/Tabs.body.php index 7383443..677360c 100644 --- a/Tabs.body.php +++ b/Tabs.body.php @@ -60,14 +60,15 @@ $form = $parser->tabsData['tabCount'] === 0 ? $this->insertCSSJS($parser) : ''; // init styles, set the return <form> tag as $form. ++$parser->tabsData['tabCount']; $names = &$parser->tabsData['tabNames']; + $nestAttr = isset($attr['nested']); //adding this attribute will restrict functionality, but allow nested tabs inside toggleboxes $nested = $parser->tabsData['nested']; if (isset($attr['name'])) { $attr['name'] = trim(htmlspecialchars($attr['name'])); // making the name attr safe to use } // Default value for the tab's given index: index attribute's value, or else the index of the tab with the same name as name attribute, or else the tab index - if (!$nested) { + if (!$nested && !$nestAttr) { $index = -1; // indices do nothing for non-nested tabs, so don't even bother doing the computations. - } elseif (isset($attr['index']) && intval($attr['index']) <= count($names)) { + } elseif (isset($attr['index']) && (intval($attr['index']) <= count($names) || $nestAttr)) { $index = intval($attr['index']); // if the index is given, and it isn't greater than the current index + 1. } elseif (isset($attr['index']) && $attr['index'] == '*') { $index = 0; //use wildcard index: this tab's contents shows up for every single tab; @@ -79,7 +80,7 @@ } $classPrefix = ''; - if ($nested) {// Note: This is defined seperately for toggleboxes, because of the different classes required. + if ($nested || $nestAttr) {// Note: This is defined seperately for toggleboxes, because of the different classes required. $classPrefix .= "tabs-content tabs-content-$index"; } if (isset($attr['class'])) { @@ -94,7 +95,7 @@ $name = trim(isset($attr['name']) && $attr['name'] ? $attr['name'] : wfMessage('tabs-tab-label', $index)); } } - if (!$nested) { // This runs when the tab is not nested inside a <tabs> tag. + if (!$nested && !$nestAttr) { // This runs when the tab is not nested inside a <tabs> tag. $container = $this->renderBox($input, $attr, $parser); } else { // this runs when the tab is nested inside a <tabs> tag. if ($index !== 0 && array_search($name, $names) === false) {// append name if it's not already in the list. @@ -120,7 +121,6 @@ } } if ($input === null) return ''; // return empty string if the tag is self-closing. This can be used to pre-define tabs for referring to via the index later. - $parser->tabsData['nested'] = false; // temporary $newstr = $parser->recursiveTagParse($input); $parser->tabsData['nested'] = $nested; // revert @@ -281,10 +281,17 @@ $args = max(func_num_args(), count($index)+2); $argcount = func_num_args(); $output = ''; - // start with 1, since that'll be the default index="" for the first tab: + $nested = false; + // start with 1, since that'll be the default index="" for the first tab. for ($i = 1; $i+1 < $args; $i++) { - // arg 0 will be $parser, arg 1 will be the list of names/indices. Start fetching arguments with arg 2. Empty string if this argument is not defined. + // $i+1 is used in this loop because the arguments are ($parser, $index, PARAM_1, PARAM_2, ...); + // so to get PARAM_n, you must do func_get_arg(n+1). $val = $i+1 < $argcount ? func_get_arg($i+1) : ''; + if (preg_match("/^nested=/", trim($val)) && $i+2 == $argcount) { + //if the last parameter has |nested=true then make all tabs nested + $nested = true; + continue; //there may still be self-closing tags to define based on name. So, continue the loop. + } $index_i = isset($index[$i-1]) ? trim($index[$i-1]) : ''; if (preg_match('/^#\d+$/',$index_i) && intval(substr($index_i,1)) > 0) { //only assign an index if the attribute is just digits, preceded by # @@ -311,6 +318,10 @@ $output .= "<tab $attr />"; } //otherwise, just don't append anything to the output. } + if ($nested) { + //if the last parameter was |nested=true, then convert all tabs to nested tabs. + $output = preg_replace("/<tab /", '<tab nested ', $output); + } return array( $output, 'noparse' => false ); } diff --git a/Tabs.php b/Tabs.php index 28d83cf..f33b2fe 100644 --- a/Tabs.php +++ b/Tabs.php @@ -30,7 +30,7 @@ 'author' => 'Joeytje50', 'url' => 'https://www.mediawiki.org/wiki/Extension:Tabs', 'descriptionmsg' => 'tabs-desc', - 'version' => 1.2, + 'version' => 1.3, 'license-name' => 'GPLv2+' ); -- To view, visit https://gerrit.wikimedia.org/r/184188 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I413ebfc42213ae6e88cd87343cc620fc62016571 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Tabs Gerrit-Branch: master Gerrit-Owner: Joeytje50 <joeytj...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits