Skip to content

Commit 17ae5b4

Browse files
author
Martino
committed
Clear timout
Clearing timeout for Appearance items that are in a non-current slide.
1 parent 4f772b4 commit 17ae5b4

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "reveal.js-appearance",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "A plugin for Reveal.js 4 that adds appearance effects to elements",
55
"keywords": "reveal, reveal.js, reveal-plugin, plugin, text effects",
66
"homepage": "https://github.com/Martinomagnifico/reveal.js-appearance",

plugin/appearance/appearance.esm.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* https://github.com/Martinomagnifico
55
*
66
* Appearance.js for Reveal.js
7-
* Version 1.0.6
7+
* Version 1.0.7
88
*
99
* @license
1010
* MIT licensed
@@ -67,15 +67,25 @@ var Plugin = function Plugin() {
6767
}
6868

6969
var appear = function appear(deck, options) {
70+
var timeouts = [];
71+
72+
var clearTimeOuts = function clearTimeOuts(timeouts) {
73+
for (var i = 0; i < timeouts.length; i++) {
74+
clearTimeout(timeouts[i]);
75+
}
76+
77+
timeouts = [];
78+
};
79+
7080
var loopAppearances = function loopAppearances(appearances, appearancesInFragment) {
7181
var delay = 0;
7282
appearances.filter(function (element, i) {
7383
if (!(appearancesInFragment.indexOf(element) > -1)) {
7484
var delayincrement = parseInt(element.dataset.delay ? element.dataset.delay : i > 0 ? options.delay : 0);
7585
delay += delayincrement;
76-
setTimeout(function () {
86+
timeouts.push(setTimeout(function () {
7787
element.classList.add(options.visibleclass);
78-
}, delay);
88+
}, delay));
7989
}
8090
});
8191
};
@@ -100,6 +110,7 @@ var Plugin = function Plugin() {
100110
};
101111

102112
var showHideSlide = function showHideSlide(event) {
113+
clearTimeOuts(timeouts);
103114
showAppearances(event.currentSlide);
104115

105116
if (event.previousSlide && options.hideagain) {

plugin/appearance/appearance.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* https://github.com/Martinomagnifico
55
*
66
* Appearance.js for Reveal.js
7-
* Version 1.0.6
7+
* Version 1.0.7
88
*
99
* @license
1010
* MIT licensed
@@ -73,15 +73,25 @@
7373
}
7474

7575
var appear = function appear(deck, options) {
76+
var timeouts = [];
77+
78+
var clearTimeOuts = function clearTimeOuts(timeouts) {
79+
for (var i = 0; i < timeouts.length; i++) {
80+
clearTimeout(timeouts[i]);
81+
}
82+
83+
timeouts = [];
84+
};
85+
7686
var loopAppearances = function loopAppearances(appearances, appearancesInFragment) {
7787
var delay = 0;
7888
appearances.filter(function (element, i) {
7989
if (!(appearancesInFragment.indexOf(element) > -1)) {
8090
var delayincrement = parseInt(element.dataset.delay ? element.dataset.delay : i > 0 ? options.delay : 0);
8191
delay += delayincrement;
82-
setTimeout(function () {
92+
timeouts.push(setTimeout(function () {
8393
element.classList.add(options.visibleclass);
84-
}, delay);
94+
}, delay));
8595
}
8696
});
8797
};
@@ -106,6 +116,7 @@
106116
};
107117

108118
var showHideSlide = function showHideSlide(event) {
119+
clearTimeOuts(timeouts);
109120
showAppearances(event.currentSlide);
110121

111122
if (event.previousSlide && options.hideagain) {

plugin/appearance/plugin-src.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,26 @@ const Plugin = () => {
66

77
const appear = function (deck, options) {
88

9+
let timeouts = [];
10+
11+
const clearTimeOuts = function (timeouts) {
12+
for (let i=0; i<timeouts.length; i++) {
13+
clearTimeout(timeouts[i]);
14+
}
15+
timeouts = [];
16+
};
17+
918
const loopAppearances = function (appearances, appearancesInFragment) {
1019
let delay = 0;
1120
appearances.filter(function (element, i) {
1221
if (!(appearancesInFragment.indexOf(element) > -1)) {
1322
let delayincrement = parseInt(element.dataset.delay ? element.dataset.delay : i > 0 ? options.delay : 0);
1423
delay += delayincrement;
15-
setTimeout(function () {
16-
element.classList.add(options.visibleclass);
17-
}, delay);
24+
timeouts.push(
25+
setTimeout(function () {
26+
element.classList.add(options.visibleclass);
27+
}, delay)
28+
);
1829
}
1930
});
2031
};
@@ -34,11 +45,13 @@ const Plugin = () => {
3445
const hideAppearances = function (container) {
3546
let disappearances = selectionArray(container, ":scope .".concat(options.baseclass, ", :scope .fragment.visible"));
3647
disappearances.filter(function (element) {
37-
element.classList.remove(element.classList.contains("fragment") ? "visible" : options.visibleclass);
48+
element.classList.remove(element.classList.contains("fragment") ? "visible" : options.visibleclass);
3849
});
3950
};
4051

4152
const showHideSlide = function (event) {
53+
54+
clearTimeOuts(timeouts);
4255
showAppearances(event.currentSlide);
4356

4457
if (event.previousSlide && options.hideagain) {

0 commit comments

Comments
 (0)