You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.2 KiB
PHP
73 lines
2.2 KiB
PHP
<?php
|
|
namespace Isekai\Widgets;
|
|
|
|
use MediaWiki\Parser\Parser;
|
|
use MediaWiki\Html\Html;
|
|
use PPFrame;
|
|
|
|
class MasonryItemWidget {
|
|
/**
|
|
* @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) {
|
|
// 获取父级瀑布流参数
|
|
$masonryParams = MasonryWidget::getMasonryParams();
|
|
|
|
$text = trim($text);
|
|
|
|
$content = $text = $parser->recursiveTagParse($text, $frame);
|
|
if (!$masonryParams) {
|
|
return '<span class="error">' . wfMessage('isekai-masonry-item-must-in-masonry')->parse() . '</span>' . $content;
|
|
}
|
|
|
|
$maxCol = $masonryParams['cols'];
|
|
|
|
$className = ['isekai-masonry-item'];
|
|
|
|
if (isset($params['col'])) {
|
|
$value = $params['col'];
|
|
$col = $value === 'full' ? $maxCol : min(12, intval($value));
|
|
$className[] = 'col-' . $col;
|
|
} else {
|
|
$className[] = 'col-1';
|
|
}
|
|
|
|
if (isset($params['xs-col'])) {
|
|
$value = $params['xs-col'];
|
|
$col = $value === 'full' ? $maxCol : min(12, intval($value));
|
|
$className[] = 'col-xs-' . $col;
|
|
}
|
|
|
|
if (isset($params['sm-col'])) {
|
|
$value = $params['sm-col'];
|
|
$col = $value === 'full' ? $maxCol : min(12, intval($value));
|
|
$className[] = 'col-sm-' . $col;
|
|
}
|
|
|
|
if (isset($params['md-col'])) {
|
|
$value = $params['md-col'];
|
|
$col = $value === 'full' ? $maxCol : min(12, intval($value));
|
|
$className[] = 'col-md-' . $col;
|
|
}
|
|
|
|
if (isset($params['lg-col'])) {
|
|
$value = $params['lg-col'];
|
|
$col = $value === 'full' ? $maxCol : min(12, intval($value));
|
|
$className[] = 'col-lg-' . $col;
|
|
}
|
|
|
|
if (isset($params['xl-col'])) {
|
|
$value = $params['xl-col'];
|
|
$col = $value === 'full' ? $maxCol : min(12, intval($value));
|
|
$className[] = 'col-xl-' . $col;
|
|
}
|
|
|
|
return Html::openElement('div', [
|
|
'class' => implode(' ', $className),
|
|
]) . $content . Html::closeElement('div');
|
|
}
|
|
} |