Skip to content

Commit 2a6e454

Browse files
committed
switched to opening a modal if clicked then a new tab to be consistent with regular image
1 parent 7d086b1 commit 2a6e454

File tree

4 files changed

+89
-33
lines changed

4 files changed

+89
-33
lines changed

docs/syntax/images.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ The image carousel directive builds upon the image directive.
131131
::::{carousel}
132132

133133
:id: nested-carousel-example
134-
:fixed-height: small ## small, medium, auto (auto is default if fixed-height is not specified)
134+
:max-height: small ## small, medium, none (none is default if max-height is not specified)
135135

136136
:::{image} images/apm.png
137137
:alt: First image description
@@ -148,7 +148,7 @@ The image carousel directive builds upon the image directive.
148148
::::{carousel}
149149

150150
:id: nested-carousel-example
151-
:fixed-height: small
151+
:max-height: small
152152

153153
:::{image} images/apm.png
154154
:alt: First image description

src/Elastic.Documentation.Site/Assets/image-carousel.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ class ImageCarousel {
6868
indicator.addEventListener('click', () => this.goToSlide(index))
6969
})
7070

71+
// Handle image clicks for modal
72+
this.slides.forEach(slide => {
73+
const imageLink = slide.querySelector('.carousel-image-reference')
74+
if (imageLink) {
75+
imageLink.addEventListener('click', (e) => {
76+
e.preventDefault()
77+
const modalId = imageLink.getAttribute('data-modal-id')
78+
if (modalId) {
79+
const modal = document.getElementById(modalId)
80+
if (modal) {
81+
modal.style.display = 'flex'
82+
}
83+
}
84+
})
85+
}
86+
})
87+
7188
// Keyboard navigation
7289
document.addEventListener('keydown', (e) => {
7390
if (!this.isInViewport()) return
@@ -202,19 +219,22 @@ export function initImageCarousel(): void {
202219
carousels.forEach((carouselElement) => {
203220
const carousel = carouselElement as HTMLElement
204221

205-
// Get the existing track
222+
// Skip if carousel already has slides (server-rendered)
223+
const existingSlides = carousel.querySelectorAll('.carousel-slide')
224+
if (existingSlides.length > 0) {
225+
// Just initialize the existing carousel
226+
new ImageCarousel(carousel)
227+
return
228+
}
229+
230+
// Get the existing track for dynamic carousels
206231
let track = carousel.querySelector('.carousel-track')
207232
if (!track) {
208233
track = document.createElement('div')
209234
track.className = 'carousel-track'
210235
carousel.appendChild(track)
211236
}
212237

213-
// Clean up any existing slides - this prevents duplicates
214-
const existingSlides = Array.from(
215-
track.querySelectorAll('.carousel-slide')
216-
)
217-
218238
// Find all image links that might be related to this carousel
219239
const section = findSectionForCarousel(carousel)
220240
if (!section) return

src/Elastic.Documentation.Site/Assets/markdown/image-carousel.css

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@
2828
display: flex;
2929
justify-content: center;
3030
align-items: center;
31+
text-decoration: none;
32+
}
33+
34+
.carousel-image-reference::after {
35+
display: none !important;
3136
}
3237

3338
.carousel-image-reference img {
3439
max-width: 100%;
3540
height: auto;
3641
display: block;
37-
box-sizing: border-box;
3842
margin: 0 auto;
3943
}
4044

@@ -60,11 +64,11 @@
6064
}
6165

6266
.carousel-prev {
63-
left: 10px;
67+
left: 0;
6468
}
6569

6670
.carousel-next {
67-
right: 10px;
71+
right: 0;
6872
}
6973

7074
.carousel-indicators {
@@ -92,21 +96,6 @@
9296
background-color: black;
9397
}
9498

95-
/* Small carousel styles */
96-
.carousel-container[data-max-height][style*="350px"] .carousel-control {
97-
top: 150px;
98-
}
99-
100-
/* Medium carousel styles */
101-
.carousel-container[data-max-height][style*="750px"] .carousel-control {
102-
top: 200px;
103-
}
104-
105-
/* None (no max-height) carousel styles */
106-
.carousel-container[data-none-height] .carousel-control {
107-
top: 500px;
108-
}
109-
11099
/* Max height carousel styles */
111100
.carousel-container[data-max-height] {
112101
padding-bottom: 40px; /* Space for indicators */
@@ -120,21 +109,48 @@
120109
.carousel-container[data-max-height] .carousel-image-reference img {
121110
max-height: var(--carousel-max-height);
122111
width: auto;
123-
height: auto;
124-
display: block;
125-
margin: 0 auto;
126112
}
127113

128114
/* None height carousel styles - images at natural size */
129115
.carousel-container[data-none-height] {
130116
padding-bottom: 40px; /* Space for indicators */
131117
}
132118

133-
.carousel-container[data-none-height] .carousel-image-reference img {
134-
max-width: 100%;
119+
/* Override modal styles for image carousels */
120+
.modal .modal-content {
121+
max-width: 95vw !important;
122+
max-height: 95vh !important;
123+
width: auto !important;
124+
height: auto !important;
125+
padding: 0 !important;
126+
background: transparent !important;
127+
box-shadow: none !important;
128+
}
129+
130+
.modal .modal-content img {
131+
max-width: 95vw;
132+
max-height: 95vh;
133+
width: auto;
135134
height: auto;
135+
object-fit: contain;
136136
display: block;
137-
margin: 0 auto;
137+
}
138+
139+
/* Ensure the close button is visible */
140+
.modal .modal-close {
141+
background: rgba(0, 0, 0, 0.7);
142+
border-radius: 50%;
143+
width: 40px;
144+
height: 40px;
145+
display: flex;
146+
align-items: center;
147+
justify-content: center;
148+
top: -20px;
149+
right: -20px;
150+
}
151+
152+
.modal .modal-close a {
153+
color: white;
138154
}
139155
@media (max-width: 768px) {
140156
.carousel-control {

src/Elastic.Markdown/Myst/Directives/Image/ImageCarouselView.cshtml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{
2222
var image = Model.Images[i];
2323
<div class="carousel-slide" data-index="@i" @(i == 0 ? "data-active=true" : "")>
24-
<a class="carousel-image-reference" href="@image.ImageUrl" target="_blank">
24+
<a class="carousel-image-reference reference internal image-reference" href="javascript:void(0)" data-modal-id="modal-@(image.UniqueImageId)">
2525
<img title="@image.Title" alt="@(image.Alt ?? "")" src="@image.ImageUrl" style="@image.Style" />
2626
</a>
2727
</div>
@@ -52,3 +52,23 @@
5252
</div>
5353
}
5454
</div>
55+
56+
@* Add modal for each image *@
57+
@for (int i = 0; i < Model.Images.Count; i++)
58+
{
59+
var image = Model.Images[i];
60+
<div id="modal-@(image.UniqueImageId)" class="modal"
61+
onclick="document.querySelector('#modal-@(image.UniqueImageId) .modal-content').contains(event.target) ? void(0) : document.getElementById('modal-@(image.UniqueImageId)').style.display='none'">
62+
<div class="modal-content">
63+
<span class="modal-close">
64+
<a href="javascript:void(0);" class="close-button"
65+
onclick="document.getElementById('modal-@(image.UniqueImageId)').style.display='none'">
66+
&times;
67+
</a>
68+
</span>
69+
<a class="reference internal image-reference" href="@image.ImageUrl" target="_blank">
70+
<img title="@image.Title" alt="@(image.Alt ?? "")" src="@image.ImageUrl" />
71+
</a>
72+
</div>
73+
</div>
74+
}

0 commit comments

Comments
 (0)