reveal.js-appearance 1.0.7 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@
4
4
  * https://github.com/Martinomagnifico
5
5
  *
6
6
  * Appearance.js for Reveal.js
7
- * Version 1.0.7
7
+ * Version 1.1.1
8
8
  *
9
9
  * @license
10
10
  * MIT licensed
@@ -15,6 +15,62 @@
15
15
  ******************************************************************/
16
16
 
17
17
 
18
+ function _slicedToArray(arr, i) {
19
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
20
+ }
21
+
22
+ function _arrayWithHoles(arr) {
23
+ if (Array.isArray(arr)) return arr;
24
+ }
25
+
26
+ function _iterableToArrayLimit(arr, i) {
27
+ if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
28
+ var _arr = [];
29
+ var _n = true;
30
+ var _d = false;
31
+ var _e = undefined;
32
+
33
+ try {
34
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
35
+ _arr.push(_s.value);
36
+
37
+ if (i && _arr.length === i) break;
38
+ }
39
+ } catch (err) {
40
+ _d = true;
41
+ _e = err;
42
+ } finally {
43
+ try {
44
+ if (!_n && _i["return"] != null) _i["return"]();
45
+ } finally {
46
+ if (_d) throw _e;
47
+ }
48
+ }
49
+
50
+ return _arr;
51
+ }
52
+
53
+ function _unsupportedIterableToArray(o, minLen) {
54
+ if (!o) return;
55
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
56
+ var n = Object.prototype.toString.call(o).slice(8, -1);
57
+ if (n === "Object" && o.constructor) n = o.constructor.name;
58
+ if (n === "Map" || n === "Set") return Array.from(o);
59
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
60
+ }
61
+
62
+ function _arrayLikeToArray(arr, len) {
63
+ if (len == null || len > arr.length) len = arr.length;
64
+
65
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
66
+
67
+ return arr2;
68
+ }
69
+
70
+ function _nonIterableRest() {
71
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
72
+ }
73
+
18
74
  var Plugin = function Plugin() {
19
75
  // Scope support polyfill
20
76
  try {
@@ -67,6 +123,10 @@ var Plugin = function Plugin() {
67
123
  }
68
124
 
69
125
  var appear = function appear(deck, options) {
126
+ var debugLog = function debugLog(text) {
127
+ if (options.debug) console.log(text);
128
+ };
129
+
70
130
  var timeouts = [];
71
131
 
72
132
  var clearTimeOuts = function clearTimeOuts(timeouts) {
@@ -96,7 +156,40 @@ var Plugin = function Plugin() {
96
156
  return selectionarray;
97
157
  };
98
158
 
159
+ var autoAdd = function autoAdd() {
160
+ if (options.autoelements) {
161
+ var _loop = function _loop() {
162
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
163
+ autoelement = _Object$entries$_i[0],
164
+ autoanimation = _Object$entries$_i[1];
165
+
166
+ if (options.autoappear) {
167
+ debugLog("All \"".concat(autoelement, "\"\" elements will animate with ").concat(autoanimation));
168
+ }
169
+
170
+ var autosection = options.autoappear ? "" : "[data-autoappear] ";
171
+ var autoAppearances = deck.getRevealElement().querySelectorAll(".slides ".concat(autosection).concat(autoelement));
172
+
173
+ if (autoAppearances.length > 0) {
174
+ autoAppearances.forEach(function (autoAppearance) {
175
+ if (!autoAppearance.classList.contains(options.baseclass)) {
176
+ autoAppearance.classList.add(options.baseclass);
177
+ autoAppearance.classList.add(autoanimation);
178
+ }
179
+ });
180
+ }
181
+ };
182
+
183
+ for (var _i = 0, _Object$entries = Object.entries(options.autoelements); _i < _Object$entries.length; _i++) {
184
+ _loop();
185
+ }
186
+ } else if (options.autoappear) {
187
+ console.log("Please set an \"autoelements\" object.");
188
+ }
189
+ };
190
+
99
191
  var showAppearances = function showAppearances(container) {
192
+ clearTimeOuts(timeouts);
100
193
  var appearances = selectionArray(container, ":scope ." + options.baseclass);
101
194
  var appearancesInFragment = selectionArray(container, ":scope .fragment .".concat(options.baseclass));
102
195
  loopAppearances(appearances, appearancesInFragment);
@@ -109,12 +202,70 @@ var Plugin = function Plugin() {
109
202
  });
110
203
  };
111
204
 
205
+ var fromTo = function fromTo(event) {
206
+ var slides = {};
207
+ slides.from = event.fromSlide ? event.fromSlide : event.previousSlide ? event.previousSlide : null;
208
+ slides.to = event.toSlide ? event.toSlide : event.currentSlide ? event.currentSlide : null;
209
+ return slides;
210
+ };
211
+
112
212
  var showHideSlide = function showHideSlide(event) {
113
- clearTimeOuts(timeouts);
114
- showAppearances(event.currentSlide);
213
+ var slides = fromTo(event);
214
+
215
+ if (slides.to.dataset.appearevent == "auto") {
216
+ slides.to.dataset.appearevent = "autoanimate";
217
+ }
218
+
219
+ if (options.appearevent == "auto") {
220
+ options.appearevent = "autoanimate";
221
+ }
222
+
223
+ if (!slides.to.dataset.eventdone) {
224
+ debugLog("Event: '".concat(event.type, "'"));
225
+
226
+ if (event.type == "ready") {
227
+ showAppearances(slides.to);
228
+ } else if (event.type == slides.to.dataset.appearevent) {
229
+ slides.to.dataset.eventdone = true;
230
+ showAppearances(slides.to);
231
+ } else if (event.type == options.appearevent) {
232
+ slides.to.dataset.eventdone = true;
233
+ showAppearances(slides.to);
234
+ } else if (event.type == "slidetransitionend" && options.appearevent == "autoanimate") {
235
+ slides.to.dataset.eventdone = true;
236
+ showAppearances(slides.to);
237
+ } else if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
238
+ if (slides.from && options.hideagain) {
239
+ hideAppearances(slides.to);
240
+ }
241
+
242
+ showAppearances(slides.to);
243
+ slides.to.dataset.eventdone = true;
244
+ } else if (event.type == 'overviewhidden') {
245
+ document.body.dataset.exitoverview = true;
246
+ setTimeout(function () {
247
+ document.body.removeAttribute('data-exitoverview');
248
+ }, 500);
249
+
250
+ if (event.currentSlide) {
251
+ if (slides.from && options.hideagain) {
252
+ hideAppearances(event.previousSlide);
253
+ }
115
254
 
116
- if (event.previousSlide && options.hideagain) {
117
- hideAppearances(event.previousSlide);
255
+ showAppearances(slides.to);
256
+ event.currentSlide.dataset.eventdone = true;
257
+ }
258
+ }
259
+ }
260
+
261
+ if (event.type == "slidechanged" && slides.from) {
262
+ slides.from.removeAttribute('data-eventdone');
263
+ }
264
+
265
+ if (slides.from) {
266
+ if (event.type == 'slidetransitionend' && options.hideagain) {
267
+ hideAppearances(slides.from);
268
+ }
118
269
  }
119
270
  };
120
271
 
@@ -127,11 +278,21 @@ var Plugin = function Plugin() {
127
278
  };
128
279
 
129
280
  deck.on('ready', function (event) {
281
+ autoAdd();
282
+ showHideSlide(event);
283
+ });
284
+ deck.on('slidechanged', function (event) {
130
285
  showHideSlide(event);
131
286
  });
132
287
  deck.on('slidetransitionend', function (event) {
133
288
  showHideSlide(event);
134
289
  });
290
+ deck.on('autoanimate', function (event) {
291
+ showHideSlide(event);
292
+ });
293
+ deck.on('overviewhidden', function (event) {
294
+ showHideSlide(event);
295
+ });
135
296
  deck.on('fragmentshown', function (event) {
136
297
  showHideFragment(event);
137
298
  });
@@ -145,7 +306,11 @@ var Plugin = function Plugin() {
145
306
  baseclass: 'animated',
146
307
  visibleclass: 'in',
147
308
  hideagain: true,
148
- delay: 300
309
+ delay: 300,
310
+ debug: false,
311
+ appearevent: 'slidetransitionend',
312
+ autoappear: false,
313
+ autoelements: null
149
314
  };
150
315
 
151
316
  var defaults = function defaults(options, defaultOptions) {