Skip to content

Commit 8ff1df0

Browse files
authored
Merge pull request #6035 from WoltLab/fancybox
New image viewer
2 parents 1209e1c + 4b4d266 commit 8ff1df0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+258
-1893
lines changed

.github/workflows/javascript.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ jobs:
6868
- name: "Check '@ckeditor/ckeditor5-inspector'"
6969
run: |
7070
diff -wu wcfsetup/install/files/js/3rdParty/ckeditor/ckeditor5-inspector/inspector.js node_modules/@ckeditor/ckeditor5-inspector/build/inspector.js
71+
- name: "Check '@fancyapps/ui'"
72+
run: |
73+
diff -wu wcfsetup/install/files/js/3rdParty/fancybox/fancybox.umd.js node_modules/@fancyapps/ui/dist/fancybox/fancybox.umd.js

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
WoltLab Suite Core is a free CMS and web-framework, designed for awesome websites and communities.
44
Cutting-edge technologies and strict object-oriented programming makes it the ideal choice for developers and communities, and is actively maintained and improved by WoltLab.
55

6-
# About CKEditor 5
6+
## About CKEditor 5
77

88
CKEditor 5 is a WYISWYG editor created by CKSource Holding sp. z o.o, Copyright (c) 2003-2023.
99

@@ -12,6 +12,15 @@ You may use this instance of CKEditor 5 with any plugin or app built on top of W
1212

1313
If you would like to use CKEditor 5 yourself and are not building on top of WoltLab Suite Core then please visit https://ckeditor.com/pricing/ to learn more.
1414

15+
## About Fancybox
16+
17+
Fancybox is a lightbox alternative created by Jānis Skarnelis.
18+
19+
This repository includes a build artifact of Fancybox that is comerically licensed to WoltLab GmbH.
20+
You may use this instance of Fancybox with any plugin or app built on top of WoltLab Suite Core only.
21+
22+
If you would like to use Fancybox yourself and are not building on top of WoltLab Suite Core then please visit https://fancyapps.com/pricing/ to learn more.
23+
1524
## License
1625

1726
This library is free software; you can redistribute it and/or

com.woltlab.wcf/acpTemplateDelete.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,6 @@
154154
<template>__audioAttachmentBBCode</template>
155155
<template>__multiPageCondition</template>
156156
<template>__multilineItemListFormField</template>
157+
<template>imageViewer</template>
157158
</delete>
158159
</data>

com.woltlab.wcf/fileDelete.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,7 @@
12911291
<file>js/WCF.Comment.min.js</file>
12921292
<file>js/WCF.Core.min.js</file>
12931293
<file>js/WCF.ImageViewer.min.js</file>
1294+
<file>js/WCF.ImageViewer.js</file>
12941295
<file>js/WCF.Label.min.js</file>
12951296
<file>js/WCF.Like.js</file>
12961297
<file>js/WCF.Like.min.js</file>

com.woltlab.wcf/templateDelete.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,6 @@
116116
<template>__multiPageCondition</template>
117117
<template>__multilineItemListFormField</template>
118118
<template>email_notification_userRegistration</template>
119+
<template>imageViewer</template>
119120
</delete>
120121
</data>

com.woltlab.wcf/templates/attachments.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
{content}
88
{foreach from=$attachmentList->getGroupedObjects($objectID) item=attachment}
99
{if $attachment->showAsImage() && !$attachment->isEmbedded()}
10-
<li class="attachmentThumbnail" data-attachment-id="{@$attachment->attachmentID}">
11-
<a href="{$attachment->getLink()}"{if $attachment->canDownload()} class="jsImageViewer jsTooltip" title="{lang}wcf.attachment.image.title{/lang}"{/if}>
10+
<li class="attachmentThumbnail" data-attachment-id="{$attachment->attachmentID}">
11+
<a href="{$attachment->getLink()}"{if $attachment->canDownload()} data-fancybox="message-{$attachmentList->getObjectTypeName()}-{$objectID}" data-caption="{$attachment->filename}" aria-title="{lang}wcf.attachment.image.title{/lang}"{/if}>
1212
<div class="attachmentThumbnailContainer">
1313
<span class="attachmentThumbnailImage">
1414
{if $attachment->hasThumbnail()}
@@ -44,7 +44,7 @@
4444
<ul class="attachmentMetaData inlineList">
4545
<li>
4646
{icon name='file-lines'}
47-
{@$attachment->filesize|filesize}
47+
{$attachment->filesize|filesize}
4848
</li>
4949
<li>
5050
{icon name='up-right-and-down-left-from-center'}

com.woltlab.wcf/templates/headIncludeJavaScript.tpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ window.addEventListener('pageshow', function(event) {
138138
</script>
139139

140140
{js application='wcf' file='WCF.ColorPicker' bundle='WCF.Combined' hasTiny=true}
141-
{js application='wcf' file='WCF.ImageViewer' bundle='WCF.Combined' hasTiny=true}
142141
{js application='wcf' file='WCF.Label' bundle='WCF.Combined' hasTiny=true}
143142
{js application='wcf' file='WCF.Location' bundle='WCF.Combined' hasTiny=true}
144143
{js application='wcf' file='WCF.Message' bundle='WCF.Combined' hasTiny=true}
@@ -181,5 +180,5 @@ window.addEventListener('pageshow', function(event) {
181180
});
182181
</script>
183182

184-
{include file='imageViewer'}
183+
{include file='shared_imageViewer'}
185184
{include file='headIncludeJsonLd'}

com.woltlab.wcf/templates/imageViewer.tpl

Lines changed: 0 additions & 21 deletions
This file was deleted.

com.woltlab.wcf/templates/shared_bbcode_wsm.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{if $media->isImage}
55
{if $thumbnailSize != 'original'}
66
{if !$removeLinks}
7-
<a href="{$mediaLink}" class="embeddedAttachmentLink jsImageViewer">
7+
<a href="{$mediaLink}" data-caption="{$media->title}" class="embeddedAttachmentLink" data-fancybox="message-{$activeMessageObjectType}-{$activeMessageID}">
88
{/if}
99
<img src="{$thumbnailLink}" alt="{$media->altText}" title="{$media->title}" width="{@$media->getThumbnailWidth($thumbnailSize)}" height="{@$media->getThumbnailHeight($thumbnailSize)}" loading="lazy">
1010
{if !$removeLinks}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{if !$__imageViewerLoaded|isset}
2+
<script data-eager="true">
3+
{
4+
let stylesheet = document.getElementById("fancybox-stylesheet");
5+
if (stylesheet === null) {
6+
stylesheet = document.createElement("link");
7+
stylesheet.rel = "stylesheet";
8+
stylesheet.type = "text/css";
9+
stylesheet.href = "{$__wcf->getPath()}style/fancybox.css";
10+
stylesheet.id = "fancybox-stylesheet";
11+
12+
document.querySelector('link[rel="stylesheet"]').before(stylesheet);
13+
}
14+
}
15+
</script>
16+
17+
{assign var=__imageViewerLoaded value=true}
18+
{/if}

com.woltlab.wcf/templates/shared_uploadFieldComponent.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{foreach from=$uploadFieldFiles item=file}
1414
<li class="box64 uploadedFile" data-unique-file-id="{$file->getUniqueFileId()}">
1515
{if $file->isImage()}
16-
<a href="{$file->getImage()}" class="jsImageViewer">
16+
<a href="{$file->getImage()}" data-fancybox data-caption="{$file->getFilename()}">
1717
<img src="{$file->getImage()}" width="{$file->getWidth()}" height="{$file->getHeight()}" loading="lazy" alt="" class="formUploadHandlerContentListImage">
1818
</a>
1919
{else}

extra/migrate-shared-template.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
'articleBBCodeTag' => 'shared_bbcode_wsa',
130130
'__multiPageCondition' => 'shared_multiPageCondition',
131131
'__multilineItemListFormField' => 'shared_multilineItemListFormField',
132+
'imageViewer' => 'shared_imageViewer',
132133
];
133134
if ($argc !== 2) {
134135
echo "ERROR: Expected a single argument to the directory that should be used to recursively replace template includes.\n";

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"dependencies": {
1717
"@ckeditor/ckeditor5-inspector": "^4.1.0",
18+
"@fancyapps/ui": "^5.0.36",
1819
"@googlemaps/markerclusterer": "2.5.3",
1920
"@types/facebook-js-sdk": "^3.3.12",
2021
"@types/google.maps": "^3.58.1",

ts/WoltLabSuite/Core/Bootstrap.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ export function setup(options: BoostrapOptions): void {
176176
void import("./Component/File/Upload").then(({ setup }) => setup());
177177
});
178178

179+
whenFirstSeen("[data-fancybox]", () => {
180+
void import("./Component/Image/Viewer").then(({ setup }) => setup());
181+
});
182+
whenFirstSeen(".jsImageViewer", () => {
183+
console.warn("The class `jsImageViewer` is deprecated. Use the attribute `data-fancybox` instead.");
184+
void import("./Component/Image/Viewer").then(({ setupLegacy }) => setupLegacy());
185+
});
186+
179187
// Move the reCAPTCHA widget overlay to the `pageOverlayContainer`
180188
// when widget form elements are placed in a dialog.
181189
const observer = new MutationObserver((mutations) => {

ts/WoltLabSuite/Core/Component/Attachment/Entry.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313

1414
type FileProcessorData = {
1515
attachmentID: number;
16+
messageObjectID: number | null;
1617
};
1718

1819
function fileInitializationCompleted(element: HTMLElement, file: WoltlabCoreFileElement, editor: HTMLElement): void {
@@ -59,8 +60,10 @@ function fileInitializationCompleted(element: HTMLElement, file: WoltlabCoreFile
5960
if (file.link !== undefined && file.filename !== undefined) {
6061
const link = document.createElement("a");
6162
link.href = file.link!;
62-
link.classList.add("jsImageViewer");
63+
link.dataset.fancybox =
64+
"attachments" + (data.messageObjectID ? `-${(data as FileProcessorData).messageObjectID}` : "");
6365
link.title = file.filename;
66+
link.dataset.caption = file.filename;
6467
link.textContent = file.filename;
6568

6669
const filename = element.querySelector(".fileList__item__filename")!;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Fancybox } from "@fancyapps/ui";
2+
import { userSlideType } from "@fancyapps/ui/types/Carousel/types";
3+
import { OptionsType } from "@fancyapps/ui/types/Fancybox/options";
4+
5+
const LOCALES = ["cs", "de", "en", "es", "fr", "it", "lv", "pl", "sk"];
6+
7+
export function setup() {
8+
void getDefaultConfig().then((config) => {
9+
Fancybox.bind("[data-fancybox]", config);
10+
});
11+
}
12+
13+
export function setupLegacy() {
14+
void getDefaultConfig().then((config) => {
15+
Fancybox.bind(".jsImageViewer", {
16+
...config,
17+
groupAll: true,
18+
});
19+
});
20+
}
21+
22+
export async function createFancybox(userSlides?: Array<userSlideType>): Promise<Fancybox> {
23+
return new Fancybox(userSlides, await getDefaultConfig());
24+
}
25+
26+
async function getDefaultConfig(): Promise<Partial<OptionsType>> {
27+
return {
28+
l10n: await getLocalization(),
29+
Html: {
30+
videoAutoplay: false,
31+
},
32+
};
33+
}
34+
35+
export async function getLocalization(): Promise<Record<string, string>> {
36+
let locale = document.documentElement.lang;
37+
38+
if (!LOCALES.includes(locale)) {
39+
locale = "en";
40+
}
41+
42+
return (await import(`@fancyapps/ui/l10n/${locale}`))[locale];
43+
}

ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ export class FileProcessor {
263263
filenameLink.href = element.link;
264264
filenameLink.title = element.filename;
265265
filenameLink.textContent = element.filename;
266-
filenameLink.classList.add("jsImageViewer");
266+
filenameLink.dataset.fancybox = "";
267+
filenameLink.dataset.caption = element.filename;
267268

268269
// Insert a hidden image element that will be used by the image viewer as the preview image
269270
const previewImage = document.createElement("img");

ts/WoltLabSuite/Core/Ui/File/Upload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class FileUpload extends Upload<FileUploadOptions> implements FileUploadHandler
177177

178178
if (fileData.image !== null) {
179179
const a = document.createElement("a");
180-
a.classList.add("jsImageViewer");
180+
a.dataset.fancybox = "";
181181
a.href = fileData.image;
182182
const image = document.createElement("img");
183183
image.classList.add("formUploadHandlerContentListImage");

wcfsetup/install/files/acp/templates/attachmentList.tpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{include file='header' pageTitle='wcf.acp.attachment.list'}
22

3-
<script data-relocate="true" src="{@$__wcf->getPath()}js/WCF.ImageViewer.js?v={@LAST_UPDATE_TIME}"></script>
4-
{include file='imageViewer'}
3+
{include file='shared_imageViewer'}
54
<script data-relocate="true">
65
require(['WoltLabSuite/Core/Ui/User/Search/Input'], (UiUserSearchInput) => {
76
new UiUserSearchInput(document.getElementById('username'));
@@ -113,7 +112,7 @@
113112
<td class="columnID columnAttachmentID">{@$attachment->attachmentID}</td>
114113
<td class="columnTitle columnFilename">
115114
<div class="box64">
116-
<a href="{$attachment->getLink()}"{if $attachment->isImage} class="jsImageViewer" title="{$attachment->filename}"{/if}>
115+
<a href="{$attachment->getLink()}"{if $attachment->isImage} data-fancybox="attachments" data-caption="{$attachment->filename}"{/if}>
117116
{if $attachment->tinyThumbnailType}
118117
<img src="{$attachment->getThumbnailLink('tiny')}" class="attachmentTinyThumbnail" alt="">
119118
{else}

wcfsetup/install/files/acp/templates/imageViewer.tpl

Lines changed: 0 additions & 21 deletions
This file was deleted.

wcfsetup/install/files/acp/templates/styleAdd.tpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
});
3232
</script>
3333

34-
<script data-relocate="true" src="{@$__wcf->getPath()}js/WCF.ImageViewer.js?v={@LAST_UPDATE_TIME}"></script>
35-
36-
{include file="imageViewer"}
34+
{include file='shared_imageViewer'}
3735

3836
<header class="contentHeader">
3937
<div class="contentHeaderTitle">

wcfsetup/install/files/js/.buildOrder

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
WCF.Assets
66
WCF
77
WCF.ColorPicker
8-
WCF.ImageViewer
98
WCF.Label
109
WCF.Location
1110
WCF.Message

wcfsetup/install/files/js/3rdParty/fancybox/fancybox.umd.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/3rdParty/fancybox/l10n/cs.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/3rdParty/fancybox/l10n/de.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/3rdParty/fancybox/l10n/en.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/3rdParty/fancybox/l10n/es.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)