" . DOKU_LF;
switch ($type) {
case self::ENCLOSED_PILLS_TYPE:
case self::ENCLOSED_TABS_TYPE:
$html .= "" . DOKU_LF;
}
return $html;
}
/**
* @param $tagAttributes
* @return string - the opening HTML code of the tab navigational header
*/
public static function openNavigationalTabsElement(TagAttributes $tagAttributes): string
{
/**
* Unset non-html attributes
*/
$tagAttributes->removeComponentAttributeIfPresent(self::KEY_PANEL_ATTRIBUTES);
/**
* Type (Skin determination)
*/
$type = self::getComponentType($tagAttributes);
/**
* $skin (tabs or pills)
*/
$skin = self::TABS_TYPE;
switch ($type) {
case self::TABS_TYPE:
case self::ENCLOSED_TABS_TYPE:
$skin = self::TABS_SKIN;
break;
case self::PILLS_TYPE:
case self::ENCLOSED_PILLS_TYPE:
$skin = self::PILLS_SKIN;
break;
default:
LogUtility::warning("The tabs type ($type) has an unknown skin", self::TAG);
}
/**
* Creates the panel wrapper element
*/
$html = "";
switch ($type) {
case self::TABS_TYPE:
case self::PILLS_TYPE:
if (!$tagAttributes->hasAttribute(Spacing::SPACING_ATTRIBUTE)) {
$tagAttributes->addComponentAttributeValue(Spacing::SPACING_ATTRIBUTE, "mb-3");
}
$tagAttributes->addClassName("nav")
->addClassName("nav-$skin");
$tagAttributes->addOutputAttributeValue('role', 'tablist');
$html = $tagAttributes->toHtmlEnterTag("ul");
break;
case self::ENCLOSED_TABS_TYPE:
case self::ENCLOSED_PILLS_TYPE:
/**
* The HTML opening for cards
*/
$tagAttributes->addClassName("card");
$html = $tagAttributes->toHtmlEnterTag("div") .
"
";
$html .= "";
break;
}
return $html;
}
public static function handleExit($handler): array
{
$callStack = CallStack::createFromHandler($handler);
$openingTag = $callStack->moveToPreviousCorrespondingOpeningCall();
if ($openingTag === false) {
LogUtility::error("A tabs tag had no opening tag and was discarded");
return array(
PluginUtility::CONTEXT => "root",
PluginUtility::ATTRIBUTES => []
);
}
$previousOpeningTag = $callStack->previous();
$callStack->next();
$firstChild = $callStack->moveToFirstChildTag();
$context = null;
if ($firstChild !== false) {
/**
* Add the context to the opening and ending tag
*/
$context = $firstChild->getTagName();
$openingTag->setContext($context);
/**
* Does tabs enclosed Panel (new syntax)
*/
if ($context == PanelTag::PANEL_LOGICAL_MARKUP) {
/**
* We scan the tabs and derived:
* * the navigation tabs element (ie ul/li nav-tab)
* * the tab pane element
*/
/**
* This call will create the ul
*
* thanks to the {@link TabsTag::NAVIGATION_CONTEXT}
*/
$navigationalCalls[] = Call::createComboCall(
TabsTag::TAG,
DOKU_LEXER_ENTER,
$openingTag->getAttributes(),
TabsTag::NAVIGATION_CONTEXT,
null,
null,
null,
\syntax_plugin_combo_xmlblocktag::TAG
);
/**
* The tab pane elements
*/
$tabPaneCalls = [$openingTag, $firstChild];
/**
* Copy the stack
*/
$labelState = "label";
$nonLabelState = "non-label";
$scanningState = $nonLabelState;
while ($actual = $callStack->next()) {
if (
$actual->getTagName() == syntax_plugin_combo_label::TAG
&&
$actual->getState() == DOKU_LEXER_ENTER
) {
$scanningState = $labelState;
}
if ($labelState === $scanningState) {
$navigationalCalls[] = $actual;
} else {
$tabPaneCalls[] = $actual;
}
if (
$actual->getTagName() == syntax_plugin_combo_label::TAG
&&
$actual->getState() == DOKU_LEXER_EXIT
) {
$scanningState = $nonLabelState;
}
}
/**
* End navigational tabs
*/
$navigationalCalls[] = Call::createComboCall(
TabsTag::TAG,
DOKU_LEXER_EXIT,
$openingTag->getAttributes(),
TabsTag::NAVIGATION_CONTEXT,
null,
null,
null,
\syntax_plugin_combo_xmlblocktag::TAG
);
/**
* Rebuild
*/
$callStack->deleteAllCallsAfter($previousOpeningTag);
$callStack->appendCallsAtTheEnd($navigationalCalls);
$callStack->appendCallsAtTheEnd($tabPaneCalls);
}
}
return array(
PluginUtility::CONTEXT => $context,
PluginUtility::ATTRIBUTES => $openingTag->getAttributes()
);
}
public static function renderEnterXhtml(TagAttributes $tagAttributes, array $data): string
{
$context = $data[PluginUtility::CONTEXT];
switch ($context) {
/**
* When the tag tabs enclosed the panels
*/
case PanelTag::PANEL_LOGICAL_MARKUP:
return TabsTag::openTabPanelsElement($tagAttributes);
/**
* When the tag tabs are derived (new syntax)
*/
case TabsTag::NAVIGATION_CONTEXT:
/**
* Old syntax, when the tag had to be added specifically
*/
case syntax_plugin_combo_tab::TAG:
return TabsTag::openNavigationalTabsElement($tagAttributes);
default:
LogUtility::internalError("The context ($context) is unknown in enter", TabsTag::TAG);
return "";
}
}
public static function renderExitXhtml(TagAttributes $tagAttributes, array $data): string
{
$context = $data[PluginUtility::CONTEXT];
switch ($context) {
/**
* New syntax (tabpanel enclosing)
*/
case PanelTag::PANEL_LOGICAL_MARKUP:
return TabsTag::closeTabPanelsElement($tagAttributes);
/**
* Old syntax
*/
case syntax_plugin_combo_tab::TAG:
/**
* New syntax (Derived)
*/
case TabsTag::NAVIGATION_CONTEXT:
$tagAttributes = TagAttributes::createFromCallStackArray($data[PluginUtility::ATTRIBUTES]);
$type = TabsTag::getComponentType($tagAttributes);
return TabsTag::closeNavigationalHeaderComponent($type);
default:
LogUtility::log2FrontEnd("The context $context is unknown in exit", LogUtility::LVL_MSG_ERROR, TabsTag::TAG);
return "";
}
}
}