Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New image viewer #6035

Open
wants to merge 25 commits into
base: 6.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fd7271e
Import fancyapps
Cyperghost Sep 17, 2024
0815a99
Merge branch 'refs/heads/6.2' into fancybox
Cyperghost Oct 23, 2024
4f0fe0a
Mark `IImageViewerAction` as deprecated
Cyperghost Oct 23, 2024
6801efd
Run `tsc`
Cyperghost Oct 23, 2024
cf0a957
Remove WCF.ImageViewer.js
Cyperghost Oct 23, 2024
8260782
Load localization for fancybox
Cyperghost Oct 23, 2024
030f0a1
Move template `imageViewer` to shared templates
Cyperghost Oct 23, 2024
c3729a4
Move ImageViewer setup to global Boostrap script
Cyperghost Oct 23, 2024
d212c40
Remove unused `imageViewer.scss`
Cyperghost Oct 23, 2024
298bc55
Move `fancybox.css` to the correct style folder
Cyperghost Oct 23, 2024
b974bb5
Remove using of `jsImageViewer` class and set `data-fancybox`
Cyperghost Oct 23, 2024
0946d22
Use `shared_imageViewer` instead of `imageViewer` template
Cyperghost Oct 23, 2024
eec03a3
Fix typo
Cyperghost Oct 23, 2024
e8f762e
Remove japanese locale
Cyperghost Oct 23, 2024
614f453
Use `data-caption` instead of `title`
Cyperghost Oct 23, 2024
301602a
Manual calling of `[data-fancybox=“attachments”]` is not necessary, F…
Cyperghost Oct 23, 2024
efa2572
Remove unused language variables `wcf.imageViewer.*`
Cyperghost Oct 23, 2024
d4166f6
Add a function that creates a new fancybox with given content, using …
Cyperghost Oct 23, 2024
a6769e0
Insert fancybox in the section to check whether the file is up to date
Cyperghost Oct 24, 2024
37d9ddd
Update com.woltlab.wcf/templates/shared_imageViewer.tpl
Cyperghost Nov 12, 2024
76c98c1
Support `.jsImageViewer` for backwards compatibility.
Cyperghost Nov 12, 2024
f713981
Use a different name for attachments that belong to a form so that th…
Cyperghost Nov 12, 2024
27e0dae
Merge remote-tracking branch 'origin/6.2' into fancybox
Cyperghost Nov 12, 2024
e3cf21b
Group images of a message together and not all from one page
Cyperghost Nov 12, 2024
1c283be
Remove `WCF.ImageViewer` from `.buildOrder`
Cyperghost Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ jobs:
- name: "Check '@ckeditor/ckeditor5-inspector'"
run: |
diff -wu wcfsetup/install/files/js/3rdParty/ckeditor/ckeditor5-inspector/inspector.js node_modules/@ckeditor/ckeditor5-inspector/build/inspector.js
- name: "Check '@fancyapps/ui'"
run: |
diff -wu wcfsetup/install/files/js/3rdParty/fancybox/fancybox.umd.js node_modules/@fancyapps/ui/dist/fancybox/fancybox.umd.js
1 change: 1 addition & 0 deletions com.woltlab.wcf/acpTemplateDelete.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,6 @@
<template>__audioAttachmentBBCode</template>
<template>__multiPageCondition</template>
<template>__multilineItemListFormField</template>
<template>imageViewer</template>
</delete>
</data>
1 change: 1 addition & 0 deletions com.woltlab.wcf/fileDelete.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,7 @@
<file>js/WCF.Comment.min.js</file>
<file>js/WCF.Core.min.js</file>
<file>js/WCF.ImageViewer.min.js</file>
<file>js/WCF.ImageViewer.js</file>
<file>js/WCF.Label.min.js</file>
<file>js/WCF.Like.js</file>
<file>js/WCF.Like.min.js</file>
Expand Down
1 change: 1 addition & 0 deletions com.woltlab.wcf/templateDelete.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@
<template>__multiPageCondition</template>
<template>__multilineItemListFormField</template>
<template>email_notification_userRegistration</template>
<template>imageViewer</template>
</delete>
</data>
2 changes: 1 addition & 1 deletion com.woltlab.wcf/templates/attachments.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{foreach from=$attachmentList->getGroupedObjects($objectID) item=attachment}
{if $attachment->showAsImage() && !$attachment->isEmbedded()}
<li class="attachmentThumbnail" data-attachment-id="{@$attachment->attachmentID}">
<a href="{$attachment->getLink()}"{if $attachment->canDownload()} class="jsImageViewer jsTooltip" title="{lang}wcf.attachment.image.title{/lang}"{/if}>
<a href="{$attachment->getLink()}"{if $attachment->canDownload()} data-fancybox="attachments" data-caption="{lang}wcf.attachment.image.title{/lang}"{/if}>
<div class="attachmentThumbnailContainer">
<span class="attachmentThumbnailImage">
{if $attachment->hasThumbnail()}
Expand Down
3 changes: 1 addition & 2 deletions com.woltlab.wcf/templates/headIncludeJavaScript.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ window.addEventListener('pageshow', function(event) {
</script>

{js application='wcf' file='WCF.ColorPicker' bundle='WCF.Combined' hasTiny=true}
{js application='wcf' file='WCF.ImageViewer' bundle='WCF.Combined' hasTiny=true}
{js application='wcf' file='WCF.Label' bundle='WCF.Combined' hasTiny=true}
{js application='wcf' file='WCF.Location' bundle='WCF.Combined' hasTiny=true}
{js application='wcf' file='WCF.Message' bundle='WCF.Combined' hasTiny=true}
Expand Down Expand Up @@ -180,5 +179,5 @@ window.addEventListener('pageshow', function(event) {
});
</script>

{include file='imageViewer'}
{include file='shared_imageViewer'}
{include file='headIncludeJsonLd'}
21 changes: 0 additions & 21 deletions com.woltlab.wcf/templates/imageViewer.tpl

This file was deleted.

2 changes: 1 addition & 1 deletion com.woltlab.wcf/templates/shared_bbcode_wsm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{if $media->isImage}
{if $thumbnailSize != 'original'}
{if !$removeLinks}
<a href="{$mediaLink}" class="embeddedAttachmentLink jsImageViewer">
<a href="{$mediaLink}" data-caption="{$media->title}" class="embeddedAttachmentLink" data-fancybox="message-{$activeMessageObjectType}-{$activeMessageID}">
{/if}
<img src="{$thumbnailLink}" alt="{$media->altText}" title="{$media->title}" width="{@$media->getThumbnailWidth($thumbnailSize)}" height="{@$media->getThumbnailHeight($thumbnailSize)}" loading="lazy">
{if !$removeLinks}
Expand Down
18 changes: 18 additions & 0 deletions com.woltlab.wcf/templates/shared_imageViewer.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{if !$__imageViewerLoaded|isset}
<script data-eager="true">
{
let stylesheet = document.getElementById("fancybox-stylesheet");
if (stylesheet === null) {
stylesheet = document.createElement("link");
stylesheet.rel = "stylesheet";
stylesheet.type = "text/css";
stylesheet.href = "{$__wcf->getPath()}style/fancybox.css";
stylesheet.id = "fancybox-stylesheet";

document.querySelector('link[rel="stylesheet"]').before(stylesheet);
}
}
</script>

{assign var=__imageViewerLoaded value=true}
{/if}
2 changes: 1 addition & 1 deletion com.woltlab.wcf/templates/shared_uploadFieldComponent.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{foreach from=$uploadFieldFiles item=file}
<li class="box64 uploadedFile" data-unique-file-id="{$file->getUniqueFileId()}">
{if $file->isImage()}
<a href="{$file->getImage()}" class="jsImageViewer">
<a href="{$file->getImage()}" data-fancybox data-caption="{$file->getFilename()}">
<img src="{$file->getImage()}" width="{$file->getWidth()}" height="{$file->getHeight()}" loading="lazy" alt="" class="formUploadHandlerContentListImage">
</a>
{else}
Expand Down
1 change: 1 addition & 0 deletions extra/migrate-shared-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
'articleBBCodeTag' => 'shared_bbcode_wsa',
'__multiPageCondition' => 'shared_multiPageCondition',
'__multilineItemListFormField' => 'shared_multilineItemListFormField',
'imageViewer' => 'shared_imageViewer',
];
if ($argc !== 2) {
echo "ERROR: Expected a single argument to the directory that should be used to recursively replace template includes.\n";
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"dependencies": {
"@ckeditor/ckeditor5-inspector": "^4.1.0",
"@fancyapps/ui": "^5.0.36",
"@googlemaps/markerclusterer": "2.3.2",
"@types/facebook-js-sdk": "^3.3.12",
"@types/google.maps": "^3.58.1",
Expand Down
8 changes: 8 additions & 0 deletions ts/WoltLabSuite/Core/Bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ export function setup(options: BoostrapOptions): void {
void import("./Component/File/Upload").then(({ setup }) => setup());
});

whenFirstSeen("[data-fancybox]", () => {
void import("./Component/Image/Viewer").then(({ setup }) => setup());
});
Cyperghost marked this conversation as resolved.
Show resolved Hide resolved
whenFirstSeen(".jsImageViewer", () => {
console.warn("The class `jsImageViewer` is deprecated. Use the attribute `data-fancybox` instead.");
void import("./Component/Image/Viewer").then(({ setupLegacy }) => setupLegacy());
});

// Move the reCAPTCHA widget overlay to the `pageOverlayContainer`
// when widget form elements are placed in a dialog.
const observer = new MutationObserver((mutations) => {
Expand Down
5 changes: 4 additions & 1 deletion ts/WoltLabSuite/Core/Component/Attachment/Entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {

type FileProcessorData = {
attachmentID: number;
messageObjectID: number | null;
};

function fileInitializationCompleted(element: HTMLElement, file: WoltlabCoreFileElement, editor: HTMLElement): void {
Expand Down Expand Up @@ -59,8 +60,10 @@ function fileInitializationCompleted(element: HTMLElement, file: WoltlabCoreFile
if (file.link !== undefined && file.filename !== undefined) {
const link = document.createElement("a");
link.href = file.link!;
link.classList.add("jsImageViewer");
link.dataset.fancybox =
"attachments" + (data.messageObjectID ? `-${(data as FileProcessorData).messageObjectID}` : "");
link.title = file.filename;
link.dataset.caption = file.filename;
link.textContent = file.filename;

const filename = element.querySelector(".fileList__item__filename")!;
Expand Down
43 changes: 43 additions & 0 deletions ts/WoltLabSuite/Core/Component/Image/Viewer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Fancybox } from "@fancyapps/ui";
import { userSlideType } from "@fancyapps/ui/types/Carousel/types";
import { OptionsType } from "@fancyapps/ui/types/Fancybox/options";

const LOCALES = ["cs", "de", "en", "es", "fr", "it", "lv", "pl", "sk"];

export function setup() {
void getDefaultConfig().then((config) => {
Fancybox.bind("[data-fancybox]", config);
});
}

export function setupLegacy() {
void getDefaultConfig().then((config) => {
Fancybox.bind(".jsImageViewer", {
...config,
groupAll: true,
});
});
}

export async function createFancybox(userSlides?: Array<userSlideType>): Promise<Fancybox> {
return new Fancybox(userSlides, await getDefaultConfig());
}

async function getDefaultConfig(): Promise<Partial<OptionsType>> {
return {
l10n: await getLocalization(),
Html: {
videoAutoplay: false,
},
};
}

export async function getLocalization(): Promise<Record<string, string>> {
let locale = document.documentElement.lang;

if (!LOCALES.includes(locale)) {
locale = "en";
}

return (await import(`@fancyapps/ui/l10n/${locale}`))[locale];
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ export class FileProcessor {
filenameLink.href = element.link;
filenameLink.title = element.filename;
filenameLink.textContent = element.filename;
filenameLink.classList.add("jsImageViewer");
filenameLink.dataset.fancybox = "";
filenameLink.dataset.caption = element.filename;

// Insert a hidden image element that will be used by the image viewer as the preview image
const previewImage = document.createElement("img");
Expand Down
2 changes: 1 addition & 1 deletion ts/WoltLabSuite/Core/Ui/File/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class FileUpload extends Upload<FileUploadOptions> implements FileUploadHandler

if (fileData.image !== null) {
const a = document.createElement("a");
a.classList.add("jsImageViewer");
a.dataset.fancybox = "";
a.href = fileData.image;
const image = document.createElement("img");
image.classList.add("formUploadHandlerContentListImage");
Expand Down
5 changes: 2 additions & 3 deletions wcfsetup/install/files/acp/templates/attachmentList.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{include file='header' pageTitle='wcf.acp.attachment.list'}

<script data-relocate="true" src="{@$__wcf->getPath()}js/WCF.ImageViewer.js?v={@LAST_UPDATE_TIME}"></script>
{include file='imageViewer'}
{include file='shared_imageViewer'}
<script data-relocate="true">
require(['WoltLabSuite/Core/Ui/User/Search/Input'], (UiUserSearchInput) => {
new UiUserSearchInput(document.getElementById('username'));
Expand Down Expand Up @@ -113,7 +112,7 @@
<td class="columnID columnAttachmentID">{@$attachment->attachmentID}</td>
<td class="columnTitle columnFilename">
<div class="box64">
<a href="{$attachment->getLink()}"{if $attachment->isImage} class="jsImageViewer" title="{$attachment->filename}"{/if}>
<a href="{$attachment->getLink()}"{if $attachment->isImage} data-fancybox="attachments" data-caption="{$attachment->filename}"{/if}>
{if $attachment->tinyThumbnailType}
<img src="{$attachment->getThumbnailLink('tiny')}" class="attachmentTinyThumbnail" alt="">
{else}
Expand Down
21 changes: 0 additions & 21 deletions wcfsetup/install/files/acp/templates/imageViewer.tpl

This file was deleted.

4 changes: 1 addition & 3 deletions wcfsetup/install/files/acp/templates/styleAdd.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
});
</script>

<script data-relocate="true" src="{@$__wcf->getPath()}js/WCF.ImageViewer.js?v={@LAST_UPDATE_TIME}"></script>

{include file="imageViewer"}
{include file='shared_imageViewer'}

<header class="contentHeader">
<div class="contentHeaderTitle">
Expand Down
1 change: 0 additions & 1 deletion wcfsetup/install/files/js/.buildOrder
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
WCF.Assets
WCF
WCF.ColorPicker
WCF.ImageViewer
WCF.Label
WCF.Location
WCF.Message
Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions wcfsetup/install/files/js/3rdParty/fancybox/l10n/cs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wcfsetup/install/files/js/3rdParty/fancybox/l10n/de.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wcfsetup/install/files/js/3rdParty/fancybox/l10n/en.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wcfsetup/install/files/js/3rdParty/fancybox/l10n/es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wcfsetup/install/files/js/3rdParty/fancybox/l10n/fr.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading