This repository was archived by the owner on Oct 18, 2024. It is now read-only.
forked from splitbrain/dokuwiki-plugin-gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
74 lines (60 loc) · 2.07 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* DOKUWIKI:include_once swipebox/js/jquery.swipebox.js */
jQuery(function () {
/**
* Add a quicklink to the media popup
*/
function gallery_plugin() {
var $opts = jQuery('#media__opts');
if (!$opts.length) return;
if (!window.opener) return;
var glbl = document.createElement('label');
var glnk = document.createElement('a');
var gbrk = document.createElement('br');
glnk.name = 'gallery_plugin';
glnk.innerHTML = LANG.plugins.gallery.addgal; //FIXME localize
glnk.style.cursor = 'pointer';
glnk.onclick = function () {
var $h1 = jQuery('#media__ns');
if (!$h1.length) return;
var ns = $h1[0].innerHTML;
opener.insertAtCarret('wiki__text', '{{gallery>' + ns + '}}');
if (!dw_mediamanager.keepopen) window.close();
};
$opts[0].appendChild(glbl);
glbl.appendChild(glnk);
$opts[0].appendChild(gbrk);
}
const replaceImages = function () {
$image = jQuery('.gallery-image-replacement').each(function () {
if ($(this).is(':visible ')) {
const data = $(this).data('src');
//$(this).after($('<img/>').attr(data));
$(this).css({'background-image': 'url(' + data + ')'});
}
});
};
/**
* Display a selected page and hide all others
*/
function gallery_pageselect(e) {
var galid = e.target.hash.substr(10, 4);
var $pages = jQuery('div.gallery__' + galid);
$pages.hide();
jQuery('#' + e.target.hash.substr(1)).show();
replaceImages();
return false;
}
// === main ===
// initialize the lightbox mechanism
jQuery("a.lightbox, a[rel^='lightbox']").swipebox({
loopAtEnd: true
});
gallery_plugin();
replaceImages();
// hide all pages except the first one
var $pages = jQuery('.gallery_page');
$pages.hide();
$pages.eq(0).show();
// attach page selector
jQuery('a.gallery_pgsel').click(gallery_pageselect);
});