From d1318d72476e97b68e6241aab4319c1b6136e88d Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Thu, 27 Jun 2024 18:32:31 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20preview=20button=20eligibilit?= =?UTF-8?q?y=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/Renderer/PreviewButtonManager.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/ppcp-button/resources/js/modules/Renderer/PreviewButtonManager.js b/modules/ppcp-button/resources/js/modules/Renderer/PreviewButtonManager.js index 5277d9d8a..dd201cffe 100644 --- a/modules/ppcp-button/resources/js/modules/Renderer/PreviewButtonManager.js +++ b/modules/ppcp-button/resources/js/modules/Renderer/PreviewButtonManager.js @@ -184,6 +184,10 @@ class PreviewButtonManager { return; } + if (!this.shouldInsertPreviewButton(id)) { + return; + } + if (!this.buttons[id]) { this._addButton(id, ppcpConfig); } else { @@ -192,6 +196,22 @@ class PreviewButtonManager { } } + /** + * Determines if the preview box supports the current button. + * + * When this function returns false, this manager instance does not create a new preview button. + * + * @param {string} previewId - ID of the inner preview box container. + * @return {boolean} True if the box is eligible for the preview button, false otherwise. + */ + shouldInsertPreviewButton(previewId) { + const container = document.querySelector(previewId); + const box = container.closest('.ppcp-preview'); + const limit = box.dataset.ppcpPreviewBlock ?? 'all'; + + return ('all' === limit) || (this.methodName === limit); + } + /** * Applies a new configuration to an existing preview button. */