Skip to content

Commit a1fc15b

Browse files
authored
Merge pull request #480 from WoltLab/6.2-fancybox
6.2 Document new Image Viewer
2 parents 6da4d3d + 4e49ab9 commit a1fc15b

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Image Viewer
2+
3+
The Image Viewer component enables interactive image viewing in a modal, using the [Fancybox](https://fancyapps.com/fancybox/) library.
4+
It supports automatic or manual opening and grouping of images.
5+
6+
Not only images, but also Videos, YouTube Videos, PDFs, HTML, [...](https://fancyapps.com/fancybox/) are supported and can be displayed in the modal.
7+
The appropriate `data-type` can be set, the system tries to determine this if it has not been set.
8+
For example, the following can be used:
9+
10+
- `image` - Image
11+
- `pdf` - PDF file
12+
- `html5video` - HTML5 video
13+
- `youtube` - YouTube video
14+
- `vimeo` - Vimeo video
15+
16+
## Open Image Viewer Automatically
17+
18+
The following code example adds an image to the global modal and groups it with all other images that are not explicitly grouped:
19+
20+
```smarty
21+
<a href="{$imageLink}" data-caption="{$caption}" data-fancybox>
22+
<img src="{$thumbnailUrl}" width="…" height="…" alt="">
23+
</a>
24+
```
25+
26+
If you want to display several images in a group, you can group them using the `data-fancybox` attribute. Images with the same group name are then displayed together:
27+
28+
```smarty
29+
<a href="{$imageLink}" data-caption="{$caption}" data-fancybox="fooBar">
30+
<img src="{$thumbnailUrl}" width="…" height="…" alt="">
31+
</a>
32+
```
33+
34+
## Grouping content from the same message
35+
36+
To ensure that images are only grouped from the same message in the same modal, `data-fancybox="message-{$messageObjectType}-{$messageObjectID}"` is used in the BBCode.
37+
38+
```php
39+
final class FooBBCode extends AbstractBBCode
40+
{
41+
#[\Override]
42+
public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser): string
43+
{
44+
$objectID = (!empty($openingTag['attributes'][0])) ? \intval($openingTag['attributes'][0]) : 0;
45+
if (!$objectID) {
46+
return '';
47+
}
48+
49+
$foo = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.foo', $objectID);
50+
if ($foo === null) {
51+
return ContentNotVisibleView::forNotAvailable();
52+
}
53+
54+
if (!$foo->isAccessible()) {
55+
return ContentNotVisibleView::forNoPermission();
56+
}
57+
58+
if ($parser->getOutputType() == 'text/html') {
59+
return WCF::getTPL()->fetch('shared_bbcode_foo', 'wcf', [
60+
'imageLink' => $foo->getLink(),
61+
'caption' => $foo->getTitle(),
62+
'activeMessageID' => MessageEmbeddedObjectManager::getInstance()->getActiveMessageID(),
63+
'activeMessageObjectType' => MessageEmbeddedObjectManager::getInstance()->getActiveMessageObjectType(),
64+
], true);
65+
} elseif ($parser->getOutputType() == 'text/simplified-html') {
66+
return StringUtil::getAnchorTag($foo->getLink(), $foo->getTitle());
67+
} else {
68+
return StringUtil::encodeHTML($foo->getLink());
69+
}
70+
}
71+
}
72+
```
73+
74+
```smarty title="shared_bbcode_foo.tpl"
75+
<a href="{$imageLink}" data-caption="{$caption}" data-fancybox="message-{$activeMessageObjectType}-{$activeMessageObjectID}">
76+
<img src="{$thumbnailUrl}" width="…" height="…" alt="">
77+
</a>
78+
```
79+
80+
## Open Image Viewer Manually
81+
82+
The Image Viewer can also be created dynamically using the function `WoltLabSuite/Core/Component/Image/Viewer::createFancybox()`.
83+
The contents of the modal are passed directly to the function.
84+
85+
### Example
86+
87+
The following code example creates a button that opens the Image Viewer with two images:
88+
89+
```html
90+
91+
<button type="button" id="openImageViewer">Open Image Viewer</button>
92+
93+
<script data-relocate="true">
94+
require(['WoltLabSuite/Core/Component/Image/Viewer'], ({ createFancybox }) => {
95+
document.getElementById("openImageViewer").addEventListener("click", () => {
96+
void createFancybox([
97+
{
98+
src: "https://example.com/image1.jpg",
99+
caption: "Image 1",
100+
type: "image",
101+
},
102+
{
103+
src: "https://example.com/image2.jpg",
104+
caption: "Image 2",
105+
type: "image",
106+
},
107+
]);
108+
});
109+
});
110+
</script>
111+
```

docs/migration/wsc61/deprecations_removals.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ With version 6.2, we have deprecated certain components and removed several othe
66

77
### PHP
88

9+
#### Classes
10+
11+
- `wcf\data\IImageViewerAction` ([WoltLab/WCF#6035](https://github.com/WoltLab/WCF/pull/6035/))
12+
913
#### Methods
1014

1115
- `wcf\util\DateUtil::format()` ([WoltLab/WCF#6042](https://github.com/WoltLab/WCF/pull/6042/))
@@ -71,6 +75,7 @@ With version 6.2, we have deprecated certain components and removed several othe
7175

7276
### JavaScript
7377

78+
- `WCF.ImageViewer` ([WoltLab/WCF#6035](https://github.com/WoltLab/WCF/pull/6035/))
7479
- `WCF.ACP.Cronjob.LogList` ([WoltLab/WCF#6077](https://github.com/WoltLab/WCF/pull/6077))
7580
- `WCF.Moderation.Queue.MarkAsRead`
7681
- `WCF.Moderation.Queue.MarkAllAsRead`

docs/migration/wsc61/templates.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Migrating from WoltLab Suite 6.1 - Templates
2+
3+
## Image Viewer
4+
5+
The previous image viewer `WCF.ImageViewer` used the CSS class `.jsImageViewer` to open the image viewer.
6+
From now on this is done via the attribute `data-fancybox`, which opens the new [Image Viewer](../../javascript/components_image_viewer.md).
7+
Grouping is supported through the attribute `data-fancybox="foo"`.
8+
9+
#### Previous Code Example
10+
11+
```smarty
12+
<a href="{$link}" class="jsImageViewer" title="{$title}">
13+
<img src="{$thumbnailUrl}" width="…" height="…" alt="">
14+
</a>
15+
```
16+
17+
#### New Code Example
18+
19+
```smarty
20+
<a href="{$link}" data-caption="{$title}" data-fancybox>
21+
<img src="{$thumbnailUrl}" width="…" height="…" alt="">
22+
</a>
23+
```

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ nav:
6666
- 'Dialog': 'javascript/components_dialog.md'
6767
- 'Google Maps': 'javascript/components_google_maps.md'
6868
- 'Guest Token': 'javascript/components_guest_token.md'
69+
- 'Image Viewer': 'javascript/components_image_viewer.md'
6970
- 'Notices': 'javascript/components_notice.md'
7071
- 'Pagination': 'javascript/components_pagination.md'
7172
- 'RPC API': 'javascript/components_rpc_api.md'
@@ -128,6 +129,7 @@ nav:
128129
- 'Migration':
129130
- 'From WoltLab Suite 6.1':
130131
- 'Deprecations and Removals': 'migration/wsc61/deprecations_removals.md'
132+
- 'Templates': 'migration/wsc61/templates.md'
131133
- 'From WoltLab Suite 6.0':
132134
- 'PHP API': 'migration/wsc60/php.md'
133135
- 'Templates': 'migration/wsc60/templates.md'

0 commit comments

Comments
 (0)