Add preview button eligibility check

This commit is contained in:
Philipp Stracker 2024-06-27 18:32:31 +02:00
parent d2f0cb1c31
commit d1318d7247
No known key found for this signature in database

View file

@ -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.
*/