1/* DOKUWIKI:include_once simple-lightbox/simple-lightbox.js */
2/* DOKUWIKI:include script/prosemirror.js */
3
4jQuery(function () {
5    /**
6     * Add a quicklink to the media popup
7     */
8    (function() {
9        const $opts = jQuery('#media__opts');
10        if (!$opts.length) return;
11        if (!window.opener) return; // we're not in the popup
12
13        const glbl = document.createElement('label');
14        const glnk = document.createElement('a');
15        const gbrk = document.createElement('br');
16
17        glnk.innerHTML = LANG.plugins.gallery.addgal;
18        glnk.style.cursor = 'pointer';
19        glnk.href = '#';
20
21        glnk.onclick = function () {
22            const $h1 = jQuery('#media__ns');
23            if (!$h1.length) return;
24            const ns = $h1[0].textContent;
25            opener.insertAtCarret('wiki__text', '{{gallery>' + ns + '}}');
26            if (!dw_mediamanager.keepopen) window.close();
27        };
28
29        $opts[0].appendChild(glbl);
30        glbl.appendChild(glnk);
31        $opts[0].appendChild(gbrk);
32    })();
33
34    /**
35     * Display a selected page and hide all others
36     */
37    (function() {
38        // hide all pages except the first one in each gallery
39        jQuery('.plugin-gallery').each(function() {
40            const $gallery = jQuery(this);
41            $gallery.find('.gallery-page').hide().eq(0).show();
42            $gallery.find('.gallery-page-selector a').eq(0).addClass('active');
43        });
44        // attach page selector
45        jQuery('.gallery-page-selector a').click(function(e) {
46            const $self = jQuery(this);
47            $self.siblings().removeClass('active');
48            $self.addClass('active');
49            const $gallery = $self.closest('.plugin-gallery');
50            $gallery.find('.gallery-page').hide();
51            $gallery.find(e.target.hash).show();
52            e.preventDefault();
53        });
54        // make page selector visible
55        jQuery('.gallery-page-selector').show();
56    })();
57
58    /**
59     * Initialize the lightbox
60     */
61    new SimpleLightbox("a.lightbox, a[rel^='lightbox']", {
62        sourceAttr: 'data-url',
63        captionSelector: 'self',
64        captionType: 'data',
65        captionsData: 'caption',
66        captionPosition: 'outside',
67        captionHTML: true, // we allow HTML and double escape in the formatter
68        alertError: false,
69        fileExt: false,
70        uniqueImages: false
71    });
72});
73
74