增加链接按钮组件

master
落雨楓 2 years ago
parent 546a2095d0
commit 07183c8155

@ -91,7 +91,6 @@
], ],
"es6": true, "es6": true,
"dependencies": [ "dependencies": [
"oojs",
"oojs-ui-core", "oojs-ui-core",
"oojs-ui.styles.icons-movement", "oojs-ui.styles.icons-movement",
"vue" "vue"
@ -149,6 +148,18 @@
"desktop", "desktop",
"mobile" "mobile"
] ]
},
"ext.isekai.buttonLink": {
"scripts": [
"buttonLink/ext.isekai.buttonLink.js"
],
"dependencies": [
"oojs-ui-core"
],
"targets": [
"desktop",
"mobile"
]
} }
}, },
"ResourceFileModulePaths": { "ResourceFileModulePaths": {

@ -0,0 +1,66 @@
<?php
namespace Isekai\Widgets;
use Title;
use Html;
class ButtonLinkWidget {
/**
* @param string $text
* @param array $params
* @param \Parser $parser
* @param \PPFrame $frame
* @return string|string[]
*/
public static function create($text, $params, \Parser $parser, \PPFrame $frame) {
$out = $parser->getOutput();
$out->addModules([
"ext.isekai.buttonLink"
]);
if (isset($params['page'])) {
$title = Title::newFromText($params['page']);
if ($title) {
$params['href'] = $title->getFullURL();
}
}
$framed = true;
if (isset($params['frameless']) && $params['frameless']) {
$framed = false;
}
$flags = [];
$primary = true;
$type = 'progressive';
if (isset($params['default']) && $params['default']) {
$primary = false;
$type = null;
}
if (isset($params['secondary']) && $params['secondary']) {
$primary = false;
}
if (isset($params['destructive']) && $params['destructive']) {
$flags[] = 'destructive';
}
if ($primary) {
$flags[] = 'primary';
}
if ($type) {
$flags[] = $type;
}
$flags = implode(' ', $flags);
$html = Html::element('a', [
'class' => 'isekai-buttonlink',
'href' => $params['href'] ?? '#',
'target' => $params['target'] ?? '_self',
'data-framed' => $framed ? 'true' : 'false',
'data-flags' => $flags
], $text);
return [$html, "markerType" => 'nowiki'];
}
}

@ -17,6 +17,7 @@ class Widgets {
$parser->setHook('discoverbox', [DiscoverWidget::class, 'create']); $parser->setHook('discoverbox', [DiscoverWidget::class, 'create']);
$parser->setHook('feedlist', [FeedListWidget::class, 'create']); $parser->setHook('feedlist', [FeedListWidget::class, 'create']);
$parser->setHook('previewcard', [PreviewCardWidget::class, 'create']); $parser->setHook('previewcard', [PreviewCardWidget::class, 'create']);
$parser->setHook('buttonlink', [ButtonLinkWidget::class, 'create']);
$parser->setHook('tile', [TileWidget::class, 'create']); $parser->setHook('tile', [TileWidget::class, 'create']);
$parser->setHook('tilegroup', [TileGroupWidget::class, 'create']); $parser->setHook('tilegroup', [TileGroupWidget::class, 'create']);

@ -0,0 +1,25 @@
$(function() {
$('.isekai-buttonlink').each(function() {
var $this = $(this);
var opt = {
label: $this.text(),
href: $this.attr('href'),
target: $this.attr('target'),
}
if ($this.attr('data-framed') === 'true') {
opt.framed = true;
}
if ($this.attr('data-flags')) {
var flags = $this.attr('data-flags');
if (flags) {
opt.flags = flags.split(' ');
}
}
var $button = new OO.ui.ButtonWidget(opt);
$this.replaceWith($button.$element);
});
});
Loading…
Cancel
Save