更改链接按钮的实现方式

master
落雨楓 1 year ago
parent f294122708
commit 5437b4f062

@ -3,6 +3,7 @@ namespace Isekai\Widgets;
use Title;
use Html;
use MediaWiki\MediaWikiServices;
class ButtonLinkWidget {
/**
@ -15,13 +16,13 @@ class ButtonLinkWidget {
public static function create($text, $params, \Parser $parser, \PPFrame $frame) {
$out = $parser->getOutput();
$out->addModules([
"ext.isekai.buttonLink"
"oojs-ui-core"
]);
if (!empty($params['page'])) {
$title = Title::newFromText($params['page']);
if ($title) {
$params['href'] = $title->getFullURL();
$params['href'] = $title->getLocalURL();
}
}
@ -61,15 +62,32 @@ class ButtonLinkWidget {
$flags[] = $type;
}
$flags = implode(' ', $flags);
$classList = ['oo-ui-widget', 'oo-ui-widget-enabled', 'oo-ui-buttonElement', 'oo-ui-labelElement', 'oo-ui-buttonWidget'];
$html = Html::element('a', [
'class' => 'isekai-buttonlink',
'href' => $params['href'] || '#',
'target' => $params['target'] || '_self',
'data-framed' => $framed ? 'true' : 'false',
'data-flags' => $flags
], $text);
if ($framed) {
$classList[] = 'oo-ui-buttonElement-framed';
} else {
$classList[] = 'oo-ui-buttonElement-frameless';
}
foreach ($flags as $flag) {
$classList[] = 'oo-ui-flaggedElement-' . $flag;
}
$html = Html::rawElement('span', ['class' => implode(' ', $classList)],
Html::rawElement('a', [
'class' => 'oo-ui-buttonElement-button',
'role' => 'button',
'tabindex' => '0',
'href' => $params['href'] ?? '#',
'target' => $params['target'] ?? '_self',
'rel' => 'nofollow'
],
Html::element('span', ['class' => 'oo-ui-iconElement-icon oo-ui-iconElement-noIcon']) .
Html::element('span', ['class' => 'oo-ui-labelElement-label'], $text) .
Html::element('span', ['class' => 'oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator'])
)
);
return [$html, "markerType" => 'nowiki'];
}

Loading…
Cancel
Save