Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 dist/assets/javascripts/bundle.42a60823.min.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions dist/assets/javascripts/bundle.6e5f0216.min.js

This file was deleted.

2 changes: 1 addition & 1 deletion dist/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.6e5f0216.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.42a60823.min.js' | url }}"></script>
{% for script in config.extra_javascript %}
{{ script | script_tag }}
{% endfor %}
Expand Down
44 changes: 27 additions & 17 deletions src/assets/javascripts/components/content/glightbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ import {
EMPTY,
Observable,
catchError,
forkJoin,
fromEvent,
map,
of,
shareReplay,
switchMap,
tap
switchMap
} from "rxjs"

import { Component } from "../../_"
Expand Down Expand Up @@ -66,16 +65,23 @@ let glightbox$: Observable<any>
*
* @returns GLightbox assets observable
*/
function fetchAssets(): Observable<void> {
function fetchScripts(): Observable<void> {
return typeof GLightbox === "undefined" || GLightbox instanceof Element
? forkJoin([
watchScript("https://unpkg.com/glightbox@3/dist/js/glightbox.min.js"),
watchStyles("https://unpkg.com/glightbox@3/dist/css/glightbox.min.css")
]).
pipe(catchError(() => EMPTY), map(() => undefined))
? watchScript("https://unpkg.com/glightbox@3/dist/js/glightbox.min.js")
.pipe(catchError(() => EMPTY), map(() => undefined))
: of(undefined)
}

/**
* Fetch GLightbox styles
*
* @returns GLightbox styles observable
*/
function fetchStyles(): Observable<void> {
return watchStyles("https://unpkg.com/glightbox@3/dist/css/glightbox.min.css")
.pipe(catchError(() => EMPTY), map(() => undefined))
}

/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
Expand All @@ -90,7 +96,7 @@ function fetchAssets(): Observable<void> {
export function mountGLightbox(
els: HTMLAnchorElement[]
): Observable<Component<GLightbox>> {
glightbox$ ||= fetchAssets()
glightbox$ ||= fetchScripts()
.pipe(
map(() => new GLightbox({
touchNavigation: true,
Expand All @@ -116,14 +122,18 @@ export function mountGLightbox(
shareReplay(1)
)

// Add elements to lightbox
glightbox$.pipe(
tap(gallery => gallery.setElements(els))
)

// Create and return component
return glightbox$
return fetchStyles().pipe(switchMap(() => glightbox$))
.pipe(
switchMap(() => els.map(el => ({ ref: el })))
switchMap(gallery => {
gallery.setElements(els)
return els.map((el, index) => {
fromEvent(el, "click").subscribe(ev => {
ev.preventDefault()
gallery.openAt(index)
})
return { ref: el }
})
})
)
}