Skip to content

Commit 3a39ff8

Browse files
author
Marcin Szczepanski
committed
Build latest plugin
1 parent 0cc7100 commit 3a39ff8

File tree

1 file changed

+60
-11
lines changed

1 file changed

+60
-11
lines changed

gallery.plugin.js

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function(Gallery) {
2-
var galleryTimer;
2+
var galleryTimer, galleryMode;
33

44
Gallery.step = function (items, iterations) {
55
var length = items.length,
@@ -23,9 +23,27 @@
2323
};
2424
};
2525

26-
Gallery.start = function (elem) {
27-
var galleryNode = elem.querySelector('.gallery');
28-
if (!galleryNode) return; // early exit if no gallery
26+
Gallery.start = function (galleryNode, contextNode) {
27+
contextNode = contextNode || document.body.firstChild;
28+
galleryMode = galleryNode.dataset.mode || 'normal';
29+
30+
if (galleryMode === 'full-screen') {
31+
// FIXME remove depenency on Reveal, have a callback? function
32+
// that will get a root node to move full screen slides to (ie. slidesNode)
33+
34+
// for full screen mode we need to:
35+
// - take the gallery out of the flow and insert it before "slides"
36+
// - hide slides
37+
// - make it full screen
38+
39+
var placeholder = document.createElement("div");
40+
placeholder.id = "gallery-placeholder";
41+
galleryNode.parentNode.replaceChild(placeholder, galleryNode);
42+
43+
if (contextNode.parentNode) {
44+
contextNode.parentNode.insertBefore(galleryNode, contextNode);
45+
}
46+
}
2947

3048
var items = Array.prototype.slice.apply(galleryNode.querySelectorAll("li"));
3149
items.forEach(function (item, index) {
@@ -35,8 +53,16 @@
3553
item.className = "inactive";
3654
}
3755
var label = item.querySelector("label");
38-
if (!label) {
39-
var img = item.querySelector("img");
56+
var img = item.querySelector("img");
57+
58+
if (galleryMode === 'full-screen') {
59+
img.style.display = "none";
60+
item.style.backgroundImage = "url(" + img.src + ")";
61+
} else {
62+
img.style.display = "";
63+
}
64+
65+
if (!label && img.attributes.alt) {
4066
label = document.createElement("label");
4167
label.innerHTML = img.attributes.alt.value;
4268
item.appendChild(label);
@@ -48,22 +74,45 @@
4874
galleryTimer = setInterval(Gallery.step(items, iterations), interval);
4975
};
5076

51-
Gallery.stop = function () {
77+
// FIXME Gallery.stop should take elem and root nodes as well
78+
Gallery.stop = function (galleryNode, contextNode) {
5279
clearInterval(galleryTimer);
80+
81+
if (galleryMode === "full-screen") {
82+
// - put the gallery back where it was
83+
var placeholder = document.getElementById("gallery-placeholder");
84+
placeholder.parentNode.replaceChild(galleryNode, placeholder);
85+
86+
var items = Array.prototype.slice.apply(galleryNode.querySelectorAll("li"));
87+
items.forEach(function (item, index) {
88+
var img = item.querySelector("img");
89+
item.style.backgroundImage = "";
90+
img.style.display = "";
91+
});
92+
}
5393
};
5494
})(window.Gallery = window.Gallery || {});(function() {
5595
if( typeof window.addEventListener === 'function' ) {
96+
var slidesNode = document.querySelector(".slides");
5697
Reveal.addEventListener("slidechanged", function (event) {
57-
if (event.previousSlide.querySelector('.gallery')) {
58-
Gallery.stop();
98+
var galleryNode = event.previousSlide.querySelector('.gallery') || document.querySelector('.reveal > .gallery');
99+
if (galleryNode) {
100+
Gallery.stop(galleryNode, slidesNode);
101+
}
102+
103+
galleryNode = event.currentSlide.querySelector('.gallery');
104+
if (galleryNode) {
105+
Gallery.start(galleryNode, slidesNode);
59106
}
60107

61-
Gallery.start(event.currentSlide);
62108
});
63109

64110
// during initial load
65111
if (Reveal.getCurrentSlide()) {
66-
Gallery.start(Reveal.getCurrentSlide());
112+
var galleryNode = Reveal.getCurrentSlide().querySelector('.gallery');
113+
if (galleryNode) {
114+
Gallery.start(galleryNode, slidesNode);
115+
}
67116
}
68117
}
69118
})();

0 commit comments

Comments
 (0)