diff --git a/extension.json b/extension.json index f74c68e..7a4d151 100644 --- a/extension.json +++ b/extension.json @@ -91,7 +91,6 @@ ], "es6": true, "dependencies": [ - "oojs", "oojs-ui-core", "oojs-ui.styles.icons-movement", "vue" @@ -149,6 +148,18 @@ "desktop", "mobile" ] + }, + "ext.isekai.buttonLink": { + "scripts": [ + "buttonLink/ext.isekai.buttonLink.js" + ], + "dependencies": [ + "oojs-ui-core" + ], + "targets": [ + "desktop", + "mobile" + ] } }, "ResourceFileModulePaths": { diff --git a/includes/ButtonLinkWidget.php b/includes/ButtonLinkWidget.php new file mode 100644 index 0000000..63d36b2 --- /dev/null +++ b/includes/ButtonLinkWidget.php @@ -0,0 +1,66 @@ +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']; + } +} \ No newline at end of file diff --git a/includes/Widgets.php b/includes/Widgets.php index 8e10a8c..16f5927 100644 --- a/includes/Widgets.php +++ b/includes/Widgets.php @@ -17,6 +17,7 @@ class Widgets { $parser->setHook('discoverbox', [DiscoverWidget::class, 'create']); $parser->setHook('feedlist', [FeedListWidget::class, 'create']); $parser->setHook('previewcard', [PreviewCardWidget::class, 'create']); + $parser->setHook('buttonlink', [ButtonLinkWidget::class, 'create']); $parser->setHook('tile', [TileWidget::class, 'create']); $parser->setHook('tilegroup', [TileGroupWidget::class, 'create']); diff --git a/modules/buttonLink/ext.isekai.buttonLink.js b/modules/buttonLink/ext.isekai.buttonLink.js new file mode 100644 index 0000000..38e0d66 --- /dev/null +++ b/modules/buttonLink/ext.isekai.buttonLink.js @@ -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); + }); +}); \ No newline at end of file