From be5ad56fe4d2984ff1c7af9811037d0f65db5322 Mon Sep 17 00:00:00 2001 From: Lex Lim Date: Thu, 21 Nov 2024 14:49:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9Tile=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/PreviewPageListWidget.php | 35 ++++++++++++------- .../ext.isekai.previewPageList.js | 8 ++++- modules/tile/ext.isekai.tile.css | 1 + 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/includes/PreviewPageListWidget.php b/includes/PreviewPageListWidget.php index 02a5c85..749cb33 100644 --- a/includes/PreviewPageListWidget.php +++ b/includes/PreviewPageListWidget.php @@ -21,11 +21,13 @@ class PreviewPageListWidget { $pageListHtml = []; foreach ($pageList as $pageTitle) { $title = Title::newFromText($pageTitle); - $pageListHtml[] = Html::rawElement('a', ['class' => 'isekai-list-item', 'href' => $title->getLocalURL()], - Html::rawElement('div', ['class' => 'isekai-list-item-content'], - Html::element('div', ['class' => 'isekai-list-item-title'], $title->getPrefixedText()) - ) - ); + if ($title) { + $pageListHtml[] = Html::rawElement('a', ['class' => 'isekai-list-item', 'href' => $title->getLocalURL()], + Html::rawElement('div', ['class' => 'isekai-list-item-content'], + Html::element('div', ['class' => 'isekai-list-item-title'], $title->getPrefixedText()) + ) + ); + } } return @@ -61,6 +63,7 @@ class PreviewPageListWidget { $lazyLoad = true; } + $resultHtml = null; switch ($loader) { case 'pages': $pageList = explode("\n", trim($text)); @@ -68,18 +71,21 @@ class PreviewPageListWidget { return trim($page); }, $pageList); - return Html::openElement('div', [ + $resultHtml = Html::openElement('div', [ 'class' => self::CONTAINER_CLASS_NAME, 'data-loader' => $loader, 'data-autofocus' => $autoFocus, 'data-lazyload' => $lazyLoad, ]) . - Html::element('script', [ + Html::openElement('script', [ 'type' => 'application/json', 'data-pages' => true, - ], json_encode($pageList)) . + ]) . + json_encode($pageList) . + Html::closeElement('script') . self::buildFallbackPageList($pageList) . Html::closeElement('div'); + break; case 'category': $category = $params['category'] ?? null; if (!$category) { @@ -118,7 +124,7 @@ class PreviewPageListWidget { ]); } - return Html::openElement('div', [ + $resultHtml = Html::openElement('div', [ 'class' => self::CONTAINER_CLASS_NAME, 'data-loader' => $loader, 'data-category' => $categoryTitleText, @@ -127,10 +133,15 @@ class PreviewPageListWidget { ]) . self::buildFallbackPageList($pageList) . Html::closeElement('div'); + break; + } + + if (!$resultHtml) { + $resultHtml = Html::element('span', [ + 'class' => 'error' + ], wfMessage('isekai-preview-page-list-error-invalid-loader', $loader)->parse()); } - return Html::element('span', [ - 'class' => 'error' - ], wfMessage('isekai-preview-page-list-error-invalid-loader', $loader)->parse()); + return $resultHtml; } } \ No newline at end of file diff --git a/modules/previewPageList/ext.isekai.previewPageList.js b/modules/previewPageList/ext.isekai.previewPageList.js index a0e8540..c78a03d 100644 --- a/modules/previewPageList/ext.isekai.previewPageList.js +++ b/modules/previewPageList/ext.isekai.previewPageList.js @@ -138,6 +138,11 @@ class CategoryPageListLoader extends BasePageListLoader { } } +function htmlDecode(input) { + var doc = new DOMParser().parseFromString(input, "text/html"); + return doc.documentElement.textContent; +} + let previewPageList = document.querySelectorAll('.isekai-preview-page-list-card'); if (previewPageList.length > 0) { const App = require("./PreviewPageList.vue"); @@ -154,7 +159,8 @@ if (previewPageList.length > 0) { let pagesJsonEl = document.querySelector('script[type="application/json"][data-pages]'); let pageList = []; if (pagesJsonEl) { - pageList = JSON.parse(pagesJsonEl.innerText); + let jsonStr = htmlDecode(pagesJsonEl.innerText); + pageList = JSON.parse(jsonStr); } props.pageListLoader = new PresetPageListLoader(pageList); break; diff --git a/modules/tile/ext.isekai.tile.css b/modules/tile/ext.isekai.tile.css index f3da602..e325fb7 100644 --- a/modules/tile/ext.isekai.tile.css +++ b/modules/tile/ext.isekai.tile.css @@ -1186,6 +1186,7 @@ width: 100%; float: left; overflow: visible; + justify-content: center; } .tiles-group::before { content: attr(data-group-title);