This can be used to set whether the Big Preview is used for images. The big preview can only be used for images.
{unsafe:$fileProcessorHtmlElement}
{assign var="files" value=$field->getFiles()}
-{if $field->isSingleFileUpload() && $imageOnly}
+{if $field->isBigPreview()}
<div class="fileUpload__preview">
{if $field->getValue()}
{assign var="file" value=$files|reset}
new FileProcessor(
'{unsafe:$field->getPrefixedId()|encodeJS}',
{if $field->isSingleFileUpload()}true{else}false{/if},
- {if $imageOnly}true{else}false{/if},
+ {if $field->isBigPreview()}true{else}false{/if},
[{implode from=$actionButtons item=actionButton}{
title: '{unsafe:$actionButton['title']|encodeJS}',
icon: {if $actionButton['icon'] === null}undefined{else}'{unsafe:$actionButton['icon']->toHtml()|encodeJS}'{/if},
readonly #fieldId: string;
#replaceElement: WoltlabCoreFileElement | undefined = undefined;
readonly #fileInput: HTMLInputElement;
- readonly #imageOnly: boolean;
+ readonly #useBigPreview: boolean;
readonly #singleFileUpload: boolean;
readonly #extraButtons: ExtraButton[];
#uploadResolve: undefined | (() => void);
constructor(
fieldId: string,
singleFileUpload: boolean = false,
- imageOnly: boolean = false,
+ useBigPreview: boolean = false,
extraButtons: ExtraButton[] = [],
) {
this.#fieldId = fieldId;
- this.#imageOnly = imageOnly;
+ this.#useBigPreview = useBigPreview;
this.#singleFileUpload = singleFileUpload;
this.#extraButtons = extraButtons;
}
get classPrefix(): string {
- return this.showBigPreview ? "fileUpload__preview__" : "fileList__";
- }
-
- get showBigPreview(): boolean {
- return this.#singleFileUpload && this.#imageOnly;
+ return this.#useBigPreview ? "fileUpload__preview__" : "fileList__";
}
protected addButtons(container: HTMLElement, element: WoltlabCoreFileElement): void {
}
#unregisterFile(element: WoltlabCoreFileElement): void {
- if (this.showBigPreview) {
+ if (this.#useBigPreview) {
element.parentElement!.innerHTML = "";
} else {
element.parentElement!.parentElement!.remove();
#registerFile(element: WoltlabCoreFileElement, container: HTMLElement | null = null): void {
if (container === null) {
- if (this.showBigPreview) {
+ if (this.#useBigPreview) {
container = this.#container.querySelector(".fileUpload__preview");
if (container === null) {
container = document.createElement("div");
}
}
- if (!this.showBigPreview) {
+ if (!this.#useBigPreview) {
insertFileInformation(container, element);
}
this.#registerFile(this.#replaceElement);
this.#replaceElement = undefined;
- if (this.showBigPreview) {
+ if (this.#useBigPreview) {
// `this.#replaceElement` need a new container, otherwise the element will be marked as erroneous, too.
const tmpContainer = document.createElement("div");
tmpContainer.append(element);
}
#fileInitializationCompleted(element: WoltlabCoreFileElement, container: HTMLElement): void {
- if (this.showBigPreview) {
+ if (this.#useBigPreview) {
element.dataset.previewUrl = element.link!;
element.unbounded = true;
} else {
#fieldId;
#replaceElement = undefined;
#fileInput;
- #imageOnly;
+ #useBigPreview;
#singleFileUpload;
#extraButtons;
#uploadResolve;
- constructor(fieldId, singleFileUpload = false, imageOnly = false, extraButtons = []) {
+ constructor(fieldId, singleFileUpload = false, useBigPreview = false, extraButtons = []) {
this.#fieldId = fieldId;
- this.#imageOnly = imageOnly;
+ this.#useBigPreview = useBigPreview;
this.#singleFileUpload = singleFileUpload;
this.#extraButtons = extraButtons;
this.#container = document.getElementById(fieldId + "Container");
fileProcessors.set(fieldId, this);
}
get classPrefix() {
- return this.showBigPreview ? "fileUpload__preview__" : "fileList__";
- }
- get showBigPreview() {
- return this.#singleFileUpload && this.#imageOnly;
+ return this.#useBigPreview ? "fileUpload__preview__" : "fileList__";
}
addButtons(container, element) {
const buttons = document.createElement("ul");
return replaceButton;
}
#unregisterFile(element) {
- if (this.showBigPreview) {
+ if (this.#useBigPreview) {
element.parentElement.innerHTML = "";
}
else {
}
#registerFile(element, container = null) {
if (container === null) {
- if (this.showBigPreview) {
+ if (this.#useBigPreview) {
container = this.#container.querySelector(".fileUpload__preview");
if (container === null) {
container = document.createElement("div");
this.#container.querySelector(".fileList").append(container);
}
}
- if (!this.showBigPreview) {
+ if (!this.#useBigPreview) {
(0, Helper_1.insertFileInformation)(container, element);
}
(0, Helper_1.trackUploadProgress)(container, element);
if (this.#replaceElement !== undefined) {
this.#registerFile(this.#replaceElement);
this.#replaceElement = undefined;
- if (this.showBigPreview) {
+ if (this.#useBigPreview) {
// `this.#replaceElement` need a new container, otherwise the element will be marked as erroneous, too.
const tmpContainer = document.createElement("div");
tmpContainer.append(element);
});
}
#fileInitializationCompleted(element, container) {
- if (this.showBigPreview) {
+ if (this.#useBigPreview) {
element.dataset.previewUrl = element.link;
element.unbounded = true;
}
*/
private array $files = [];
private bool $singleFileUpload = false;
+ private bool $bigPreview = false;
private array $actionButtons = [];
#[\Override]
$this->context
),
'maxUploads' => $this->getFileProcessor()->getMaximumCount($this->context),
- 'imageOnly' => \array_diff(
- $this->getFileProcessor()->getAllowedFileExtensions($this->context),
- ImageUtil::IMAGE_EXTENSIONS
- ) === [],
'actionButtons' => $this->actionButtons,
];
}
return $this;
}
+
+ /**
+ * Returns whether the big preview is shown for images.
+ */
+ public function isBigPreview(): bool
+ {
+ return $this->bigPreview;
+ }
+
+ /**
+ * Sets whether the big preview is shown for images.
+ */
+ public function bigPreview(bool $bigPreview = true): self
+ {
+ if (
+ $this->bigPreview
+ && \array_diff(
+ $this->getFileProcessor()->getAllowedFileExtensions($this->context),
+ ImageUtil::IMAGE_EXTENSIONS
+ ) !== []
+ ) {
+ throw new \InvalidArgumentException(
+ "The big preview is only supported for images for the field '{$this->getId()}'."
+ );
+ }
+ $this->bigPreview = $bigPreview;
+
+ return $this;
+ }
}