Joeytje50 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/184126
Change subject: Add feature: <tab>s that show up in every tab
......................................................................
Add feature: <tab>s that show up in every tab
Using index="*" for a <tab> tag will now make it show up
for every single tab. This is useful when nesting
toggle boxes or dropdown menus inside tab menus.
Also fixed a bug that made it impossible to use
{{#tab:#1|cont}} syntax, because index="#1" would be set.
Change-Id: Iff726f885bbd4b55d66dc0d2055e64eb7344cb4d
---
M Tabs.body.php
M ext.tabs.css
2 files changed, 40 insertions(+), 22 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Tabs
refs/changes/26/184126/1
diff --git a/Tabs.body.php b/Tabs.body.php
index 7aa8d9f..501337a 100644
--- a/Tabs.body.php
+++ b/Tabs.body.php
@@ -66,42 +66,47 @@
}
// 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) {
- $index = 0; // indices do nothing for non-nested tabs,
so don't even bother doing the computations.
+ $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)) {
$index = intval($attr['index']); // if the index is
given, and it isn't greater than the current index + 1.
- } elseif (isset($attr['name']) && array_search($attr['name'],
$names) !== false)
+ } elseif (isset($attr['index']) && $attr['index'] == '*') {
+ $index = 0; //use wildcard index: this tab's contents
shows up for every single tab;
+ //this makes it possible to have a dropdown box inside
a <tabs> box, which shows up for every tab.
+ } elseif (isset($attr['name']) && array_search($attr['name'],
$names) !== false) {
$index = array_search($attr['name'], $names)+1; // if
index is not defined, but the name is, use the index of the tabname.
- else {
+ } else {
$index = count($names)+1; // index of this tab in this
scope. Plus one because tabs are 1-based, arrays are 0-based.
}
$classPrefix = '';
- if ($nested) // Note: This is defined seperately for
toggleboxes, because of the different classes required.
+ if ($nested) {// Note: This is defined seperately for
toggleboxes, because of the different classes required.
$classPrefix .= "tabs-content tabs-content-$index";
-
- if (!isset($attr['class']))
- $attr['class'] = $classPrefix; // only the prefix if no
classes have been defined
- else
- $attr['class'] = trim("$classPrefix
".htmlspecialchars($attr['class']));
-
- if (isset($names[$index-1])) {// if array $names already has a
name defined at position $index, use that.
- $name = $names[$index-1]; // minus 1 because tabs are
1-based, arrays 0-based.
- } else {// otherwise, use the entered name, or the $index with
a "Tab " prefix if it is not defined or empty.
- $name = trim(isset($attr['name']) && $attr['name'] ?
$attr['name'] : wfMessage('tabs-tab-label', $index));
}
-
+ if (isset($attr['class'])) {
+ $attr['class'] = trim("$classPrefix
".htmlspecialchars($attr['class']));
+ } else {
+ $attr['class'] = $classPrefix; // only the prefix if no
classes have been defined
+ }
+ if ($index !== 0) {
+ if (isset($names[$index-1])) { // if array $names
already has a name defined at position $index, use that.
+ $name = $names[$index-1]; // minus 1 because
tabs are 1-based, arrays 0-based.
+ } else { // otherwise, use the entered name, or the
$index with a "Tab " prefix if it is not defined or empty.
+ $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.
$container = $this->renderBox($input, $attr, $parser);
} else { // this runs when the tab is nested inside a <tabs>
tag.
- if (array_search($name, $names) === false) // append
name if it's not already in the list.
+ if ($index !== 0 && array_search($name, $names) ===
false) {// append name if it's not already in the list.
$names[] = $name;
-
- if (isset($attr['block']))
+ }
+ if (isset($attr['block'])) {
$ib = 'tabs-block ';
- elseif (isset($attr['inline']))
+ } elseif (isset($attr['inline'])) {
$ib = 'tabs-inline ';
- else
+ } else {
$ib = '';
+ }
$attr['class'] = $ib.$attr['class'];
$container = array(
'',
@@ -109,7 +114,10 @@
'div',
$this->getSafeAttrs($attr)
);
- $parser->tabsData['labels'][intval($index)] = $name; //
Store the index and the name so this can be used within the <tabs> hook to
create labels
+ if ($index !== 0) {
+ // Store the index and the name so this can be
used within the <tabs> hook to create labels
+ $parser->tabsData['labels'][intval($index)] =
$name;
+ }
}
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.
@@ -280,7 +288,7 @@
$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 #
- $attr = "index=\"$index_i\"";
+ $attr = 'index="'.substr($index_i,1).'"';
$isname = false;
} elseif ($index_i) {
// only assign a name if the name attribute
isn't just whitespace
diff --git a/ext.tabs.css b/ext.tabs.css
index 7329c3d..b00564b 100644
--- a/ext.tabs.css
+++ b/ext.tabs.css
@@ -91,6 +91,15 @@
display: inline-block;
vertical-align: bottom;
}
+.tabs-tabbox .tabs-content-0 {
+ display: inline-block;
+}
+.tabs-tabbox .tabs-block.tabs-content-0 {
+ display: block;
+}
+.tabs-tabbox .tabs-inline.tabs-content-0 {
+ display: inline;
+}
.tabs-plain > .tabs-label {
border: 1px solid #AAA;
border-radius: 8px;
@@ -105,6 +114,7 @@
.tabs-togglebox > .tabs-container {
display: inline-block; /* this is to make the box the minimal width it
needs to be */
+ width: inherit;
padding: 0;
border-radius: 8px;
}
--
To view, visit https://gerrit.wikimedia.org/r/184126
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iff726f885bbd4b55d66dc0d2055e64eb7344cb4d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Tabs
Gerrit-Branch: master
Gerrit-Owner: Joeytje50 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits