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
@@ -16,163 +16,328 @@
16
16
 
17
17
 
18
18
  (function (global, factory) {
19
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
20
- typeof define === 'function' && define.amd ? define(factory) :
21
- (global = global || self, global.Appearance = factory());
19
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
20
+ typeof define === 'function' && define.amd ? define(factory) :
21
+ (global = global || self, global.Appearance = factory());
22
22
  }(this, (function () { 'use strict';
23
23
 
24
- var Plugin = function Plugin() {
25
- // Scope support polyfill
26
- try {
27
- document.querySelector(":scope *");
28
- } catch (t) {
29
- !function (t) {
30
- var e = /:scope(?![\w-])/gi,
31
- r = u(t.querySelector);
32
-
33
- t.querySelector = function (t) {
34
- return r.apply(this, arguments);
35
- };
36
-
37
- var c = u(t.querySelectorAll);
38
-
39
- if (t.querySelectorAll = function (t) {
40
- return c.apply(this, arguments);
41
- }, t.matches) {
42
- var n = u(t.matches);
43
-
44
- t.matches = function (t) {
45
- return n.apply(this, arguments);
46
- };
47
- }
48
-
49
- if (t.closest) {
50
- var o = u(t.closest);
51
-
52
- t.closest = function (t) {
53
- return o.apply(this, arguments);
54
- };
55
- }
56
-
57
- function u(t) {
58
- return function (r) {
59
- if (r && e.test(r)) {
60
- var _c = "q" + Math.floor(9e6 * Math.random()) + 1e6;
61
-
62
- arguments[0] = r.replace(e, "[" + _c + "]"), this.setAttribute(_c, "");
63
-
64
- var _n = t.apply(this, arguments);
65
-
66
- return this.removeAttribute(_c), _n;
67
- }
68
-
69
- return t.apply(this, arguments);
70
- };
71
- }
72
- }(Element.prototype);
73
- }
74
-
75
- 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
-
86
- var loopAppearances = function loopAppearances(appearances, appearancesInFragment) {
87
- var delay = 0;
88
- appearances.filter(function (element, i) {
89
- if (!(appearancesInFragment.indexOf(element) > -1)) {
90
- var delayincrement = parseInt(element.dataset.delay ? element.dataset.delay : i > 0 ? options.delay : 0);
91
- delay += delayincrement;
92
- timeouts.push(setTimeout(function () {
93
- element.classList.add(options.visibleclass);
94
- }, delay));
95
- }
96
- });
97
- };
98
-
99
- var selectionArray = function selectionArray(container, selectors) {
100
- var selections = container.querySelectorAll(selectors);
101
- var selectionarray = Array.prototype.slice.call(selections);
102
- return selectionarray;
103
- };
104
-
105
- var showAppearances = function showAppearances(container) {
106
- var appearances = selectionArray(container, ":scope ." + options.baseclass);
107
- var appearancesInFragment = selectionArray(container, ":scope .fragment .".concat(options.baseclass));
108
- loopAppearances(appearances, appearancesInFragment);
109
- };
110
-
111
- var hideAppearances = function hideAppearances(container) {
112
- var disappearances = selectionArray(container, ":scope .".concat(options.baseclass, ", :scope .fragment.visible"));
113
- disappearances.filter(function (element) {
114
- element.classList.remove(element.classList.contains("fragment") ? "visible" : options.visibleclass);
115
- });
116
- };
117
-
118
- var showHideSlide = function showHideSlide(event) {
119
- clearTimeOuts(timeouts);
120
- showAppearances(event.currentSlide);
121
-
122
- if (event.previousSlide && options.hideagain) {
123
- hideAppearances(event.previousSlide);
124
- }
125
- };
126
-
127
- var showHideFragment = function showHideFragment(event) {
128
- if (event.type == "fragmentshowncomplete" || event.type == "fragmentshown") {
129
- showAppearances(event.fragment);
130
- } else {
131
- hideAppearances(event.fragment);
132
- }
133
- };
134
-
135
- deck.on('ready', function (event) {
136
- showHideSlide(event);
137
- });
138
- deck.on('slidetransitionend', function (event) {
139
- showHideSlide(event);
140
- });
141
- deck.on('fragmentshown', function (event) {
142
- showHideFragment(event);
143
- });
144
- deck.on('fragmenthidden', function (event) {
145
- showHideFragment(event);
146
- });
147
- };
148
-
149
- var init = function init(deck) {
150
- var defaultOptions = {
151
- baseclass: 'animated',
152
- visibleclass: 'in',
153
- hideagain: true,
154
- delay: 300
155
- };
156
-
157
- var defaults = function defaults(options, defaultOptions) {
158
- for (var i in defaultOptions) {
159
- if (!options.hasOwnProperty(i)) {
160
- options[i] = defaultOptions[i];
161
- }
162
- }
163
- };
164
-
165
- var options = deck.getConfig().appearance || {};
166
- defaults(options, defaultOptions);
167
- appear(deck, options);
168
- };
169
-
170
- return {
171
- id: 'appearance',
172
- init: init
173
- };
174
- };
175
-
176
- return Plugin;
24
+ function _slicedToArray(arr, i) {
25
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
26
+ }
27
+
28
+ function _arrayWithHoles(arr) {
29
+ if (Array.isArray(arr)) return arr;
30
+ }
31
+
32
+ function _iterableToArrayLimit(arr, i) {
33
+ if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
34
+ var _arr = [];
35
+ var _n = true;
36
+ var _d = false;
37
+ var _e = undefined;
38
+
39
+ try {
40
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
41
+ _arr.push(_s.value);
42
+
43
+ if (i && _arr.length === i) break;
44
+ }
45
+ } catch (err) {
46
+ _d = true;
47
+ _e = err;
48
+ } finally {
49
+ try {
50
+ if (!_n && _i["return"] != null) _i["return"]();
51
+ } finally {
52
+ if (_d) throw _e;
53
+ }
54
+ }
55
+
56
+ return _arr;
57
+ }
58
+
59
+ function _unsupportedIterableToArray(o, minLen) {
60
+ if (!o) return;
61
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
62
+ var n = Object.prototype.toString.call(o).slice(8, -1);
63
+ if (n === "Object" && o.constructor) n = o.constructor.name;
64
+ if (n === "Map" || n === "Set") return Array.from(o);
65
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
66
+ }
67
+
68
+ function _arrayLikeToArray(arr, len) {
69
+ if (len == null || len > arr.length) len = arr.length;
70
+
71
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
72
+
73
+ return arr2;
74
+ }
75
+
76
+ function _nonIterableRest() {
77
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
78
+ }
79
+
80
+ var Plugin = function Plugin() {
81
+ // Scope support polyfill
82
+ try {
83
+ document.querySelector(":scope *");
84
+ } catch (t) {
85
+ !function (t) {
86
+ var e = /:scope(?![\w-])/gi,
87
+ r = u(t.querySelector);
88
+
89
+ t.querySelector = function (t) {
90
+ return r.apply(this, arguments);
91
+ };
92
+
93
+ var c = u(t.querySelectorAll);
94
+
95
+ if (t.querySelectorAll = function (t) {
96
+ return c.apply(this, arguments);
97
+ }, t.matches) {
98
+ var n = u(t.matches);
99
+
100
+ t.matches = function (t) {
101
+ return n.apply(this, arguments);
102
+ };
103
+ }
104
+
105
+ if (t.closest) {
106
+ var o = u(t.closest);
107
+
108
+ t.closest = function (t) {
109
+ return o.apply(this, arguments);
110
+ };
111
+ }
112
+
113
+ function u(t) {
114
+ return function (r) {
115
+ if (r && e.test(r)) {
116
+ var _c = "q" + Math.floor(9e6 * Math.random()) + 1e6;
117
+
118
+ arguments[0] = r.replace(e, "[" + _c + "]"), this.setAttribute(_c, "");
119
+
120
+ var _n = t.apply(this, arguments);
121
+
122
+ return this.removeAttribute(_c), _n;
123
+ }
124
+
125
+ return t.apply(this, arguments);
126
+ };
127
+ }
128
+ }(Element.prototype);
129
+ }
130
+
131
+ var appear = function appear(deck, options) {
132
+ var debugLog = function debugLog(text) {
133
+ if (options.debug) console.log(text);
134
+ };
135
+
136
+ var timeouts = [];
137
+
138
+ var clearTimeOuts = function clearTimeOuts(timeouts) {
139
+ for (var i = 0; i < timeouts.length; i++) {
140
+ clearTimeout(timeouts[i]);
141
+ }
142
+
143
+ timeouts = [];
144
+ };
145
+
146
+ var loopAppearances = function loopAppearances(appearances, appearancesInFragment) {
147
+ var delay = 0;
148
+ appearances.filter(function (element, i) {
149
+ if (!(appearancesInFragment.indexOf(element) > -1)) {
150
+ var delayincrement = parseInt(element.dataset.delay ? element.dataset.delay : i > 0 ? options.delay : 0);
151
+ delay += delayincrement;
152
+ timeouts.push(setTimeout(function () {
153
+ element.classList.add(options.visibleclass);
154
+ }, delay));
155
+ }
156
+ });
157
+ };
158
+
159
+ var selectionArray = function selectionArray(container, selectors) {
160
+ var selections = container.querySelectorAll(selectors);
161
+ var selectionarray = Array.prototype.slice.call(selections);
162
+ return selectionarray;
163
+ };
164
+
165
+ var autoAdd = function autoAdd() {
166
+ if (options.autoelements) {
167
+ var _loop = function _loop() {
168
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
169
+ autoelement = _Object$entries$_i[0],
170
+ autoanimation = _Object$entries$_i[1];
171
+
172
+ if (options.autoappear) {
173
+ debugLog("All \"".concat(autoelement, "\"\" elements will animate with ").concat(autoanimation));
174
+ }
175
+
176
+ var autosection = options.autoappear ? "" : "[data-autoappear] ";
177
+ var autoAppearances = deck.getRevealElement().querySelectorAll(".slides ".concat(autosection).concat(autoelement));
178
+
179
+ if (autoAppearances.length > 0) {
180
+ autoAppearances.forEach(function (autoAppearance) {
181
+ if (!autoAppearance.classList.contains(options.baseclass)) {
182
+ autoAppearance.classList.add(options.baseclass);
183
+ autoAppearance.classList.add(autoanimation);
184
+ }
185
+ });
186
+ }
187
+ };
188
+
189
+ for (var _i = 0, _Object$entries = Object.entries(options.autoelements); _i < _Object$entries.length; _i++) {
190
+ _loop();
191
+ }
192
+ } else if (options.autoappear) {
193
+ console.log("Please set an \"autoelements\" object.");
194
+ }
195
+ };
196
+
197
+ var showAppearances = function showAppearances(container) {
198
+ clearTimeOuts(timeouts);
199
+ var appearances = selectionArray(container, ":scope ." + options.baseclass);
200
+ var appearancesInFragment = selectionArray(container, ":scope .fragment .".concat(options.baseclass));
201
+ loopAppearances(appearances, appearancesInFragment);
202
+ };
203
+
204
+ var hideAppearances = function hideAppearances(container) {
205
+ var disappearances = selectionArray(container, ":scope .".concat(options.baseclass, ", :scope .fragment.visible"));
206
+ disappearances.filter(function (element) {
207
+ element.classList.remove(element.classList.contains("fragment") ? "visible" : options.visibleclass);
208
+ });
209
+ };
210
+
211
+ var fromTo = function fromTo(event) {
212
+ var slides = {};
213
+ slides.from = event.fromSlide ? event.fromSlide : event.previousSlide ? event.previousSlide : null;
214
+ slides.to = event.toSlide ? event.toSlide : event.currentSlide ? event.currentSlide : null;
215
+ return slides;
216
+ };
217
+
218
+ var showHideSlide = function showHideSlide(event) {
219
+ var slides = fromTo(event);
220
+
221
+ if (slides.to.dataset.appearevent == "auto") {
222
+ slides.to.dataset.appearevent = "autoanimate";
223
+ }
224
+
225
+ if (options.appearevent == "auto") {
226
+ options.appearevent = "autoanimate";
227
+ }
228
+
229
+ if (!slides.to.dataset.eventdone) {
230
+ debugLog("Event: '".concat(event.type, "'"));
231
+
232
+ if (event.type == "ready") {
233
+ showAppearances(slides.to);
234
+ } else if (event.type == slides.to.dataset.appearevent) {
235
+ slides.to.dataset.eventdone = true;
236
+ showAppearances(slides.to);
237
+ } else if (event.type == options.appearevent) {
238
+ slides.to.dataset.eventdone = true;
239
+ showAppearances(slides.to);
240
+ } else if (event.type == "slidetransitionend" && options.appearevent == "autoanimate") {
241
+ slides.to.dataset.eventdone = true;
242
+ showAppearances(slides.to);
243
+ } else if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
244
+ if (slides.from && options.hideagain) {
245
+ hideAppearances(slides.to);
246
+ }
247
+
248
+ showAppearances(slides.to);
249
+ slides.to.dataset.eventdone = true;
250
+ } else if (event.type == 'overviewhidden') {
251
+ document.body.dataset.exitoverview = true;
252
+ setTimeout(function () {
253
+ document.body.removeAttribute('data-exitoverview');
254
+ }, 500);
255
+
256
+ if (event.currentSlide) {
257
+ if (slides.from && options.hideagain) {
258
+ hideAppearances(event.previousSlide);
259
+ }
260
+
261
+ showAppearances(slides.to);
262
+ event.currentSlide.dataset.eventdone = true;
263
+ }
264
+ }
265
+ }
266
+
267
+ if (event.type == "slidechanged" && slides.from) {
268
+ slides.from.removeAttribute('data-eventdone');
269
+ }
270
+
271
+ if (slides.from) {
272
+ if (event.type == 'slidetransitionend' && options.hideagain) {
273
+ hideAppearances(slides.from);
274
+ }
275
+ }
276
+ };
277
+
278
+ var showHideFragment = function showHideFragment(event) {
279
+ if (event.type == "fragmentshowncomplete" || event.type == "fragmentshown") {
280
+ showAppearances(event.fragment);
281
+ } else {
282
+ hideAppearances(event.fragment);
283
+ }
284
+ };
285
+
286
+ deck.on('ready', function (event) {
287
+ autoAdd();
288
+ showHideSlide(event);
289
+ });
290
+ deck.on('slidechanged', function (event) {
291
+ showHideSlide(event);
292
+ });
293
+ deck.on('slidetransitionend', function (event) {
294
+ showHideSlide(event);
295
+ });
296
+ deck.on('autoanimate', function (event) {
297
+ showHideSlide(event);
298
+ });
299
+ deck.on('overviewhidden', function (event) {
300
+ showHideSlide(event);
301
+ });
302
+ deck.on('fragmentshown', function (event) {
303
+ showHideFragment(event);
304
+ });
305
+ deck.on('fragmenthidden', function (event) {
306
+ showHideFragment(event);
307
+ });
308
+ };
309
+
310
+ var init = function init(deck) {
311
+ var defaultOptions = {
312
+ baseclass: 'animated',
313
+ visibleclass: 'in',
314
+ hideagain: true,
315
+ delay: 300,
316
+ debug: false,
317
+ appearevent: 'slidetransitionend',
318
+ autoappear: false,
319
+ autoelements: null
320
+ };
321
+
322
+ var defaults = function defaults(options, defaultOptions) {
323
+ for (var i in defaultOptions) {
324
+ if (!options.hasOwnProperty(i)) {
325
+ options[i] = defaultOptions[i];
326
+ }
327
+ }
328
+ };
329
+
330
+ var options = deck.getConfig().appearance || {};
331
+ defaults(options, defaultOptions);
332
+ appear(deck, options);
333
+ };
334
+
335
+ return {
336
+ id: 'appearance',
337
+ init: init
338
+ };
339
+ };
340
+
341
+ return Plugin;
177
342
 
178
343
  })));
@@ -6,6 +6,10 @@ const Plugin = () => {
6
6
 
7
7
  const appear = function (deck, options) {
8
8
 
9
+ const debugLog = function(text) {
10
+ if (options.debug) console.log(text);
11
+ }
12
+
9
13
  let timeouts = [];
10
14
 
11
15
  const clearTimeOuts = function (timeouts) {
@@ -17,6 +21,7 @@ const Plugin = () => {
17
21
 
18
22
  const loopAppearances = function (appearances, appearancesInFragment) {
19
23
  let delay = 0;
24
+
20
25
  appearances.filter(function (element, i) {
21
26
  if (!(appearancesInFragment.indexOf(element) > -1)) {
22
27
  let delayincrement = parseInt(element.dataset.delay ? element.dataset.delay : i > 0 ? options.delay : 0);
@@ -35,10 +40,39 @@ const Plugin = () => {
35
40
  let selectionarray = Array.prototype.slice.call(selections);
36
41
  return selectionarray;
37
42
  };
43
+
44
+ const autoAdd = function () {
45
+
46
+ if (options.autoelements) {
47
+
48
+ for (const [autoelement, autoanimation] of Object.entries(options.autoelements)) {
49
+
50
+ if (options.autoappear) {
51
+ debugLog(`All "${autoelement}"" elements will animate with ${autoanimation}`);
52
+ }
53
+ let autosection = options.autoappear ? "" : "[data-autoappear] ";
54
+ let autoAppearances = deck.getRevealElement().querySelectorAll(`.slides ${autosection}${autoelement}`);
55
+
56
+ if (autoAppearances.length > 0) {
57
+ autoAppearances.forEach(autoAppearance => {
58
+ if (!autoAppearance.classList.contains(options.baseclass)) {
59
+ autoAppearance.classList.add(options.baseclass);
60
+ autoAppearance.classList.add(autoanimation);
61
+ }
62
+ });
63
+ }
64
+
65
+ }
66
+ } else if (options.autoappear) {
67
+ console.log(`Please set an "autoelements" object.`);
68
+ }
69
+ }
38
70
 
39
71
  const showAppearances = function (container) {
72
+ clearTimeOuts(timeouts);
40
73
  let appearances = selectionArray(container, ":scope ." + options.baseclass);
41
74
  let appearancesInFragment = selectionArray(container, ":scope .fragment .".concat(options.baseclass));
75
+
42
76
  loopAppearances(appearances, appearancesInFragment);
43
77
  };
44
78
 
@@ -48,14 +82,74 @@ const Plugin = () => {
48
82
  element.classList.remove(element.classList.contains("fragment") ? "visible" : options.visibleclass);
49
83
  });
50
84
  };
51
-
85
+
86
+ const fromTo = function (event) {
87
+ let slides = {}
88
+ slides.from = event.fromSlide ? event.fromSlide : event.previousSlide ? event.previousSlide : null;
89
+ slides.to = event.toSlide ? event.toSlide : event.currentSlide ? event.currentSlide : null;
90
+ return slides
91
+ }
92
+
52
93
  const showHideSlide = function (event) {
53
94
 
54
- clearTimeOuts(timeouts);
55
- showAppearances(event.currentSlide);
56
-
57
- if (event.previousSlide && options.hideagain) {
58
- hideAppearances(event.previousSlide);
95
+ let slides = fromTo(event);
96
+
97
+ if (slides.to.dataset.appearevent == "auto") {slides.to.dataset.appearevent = "autoanimate"}
98
+ if (options.appearevent == "auto") {options.appearevent = "autoanimate"}
99
+
100
+ if ( !slides.to.dataset.eventdone ) {
101
+
102
+ debugLog(`Event: '${event.type}'`);
103
+
104
+ if (event.type == "ready") {
105
+ showAppearances(slides.to);
106
+
107
+ } else if (event.type == slides.to.dataset.appearevent) {
108
+ slides.to.dataset.eventdone = true;
109
+ showAppearances(slides.to);
110
+
111
+ } else if (event.type == options.appearevent) {
112
+
113
+ slides.to.dataset.eventdone = true;
114
+ showAppearances(slides.to);
115
+
116
+ } else if (event.type == "slidetransitionend" && options.appearevent == "autoanimate" ) {
117
+ slides.to.dataset.eventdone = true;
118
+ showAppearances(slides.to);
119
+
120
+ } else if (event.type == 'slidechanged' && document.body.dataset.exitoverview) {
121
+ if (slides.from && options.hideagain) {
122
+ hideAppearances(slides.to);
123
+ }
124
+ showAppearances(slides.to);
125
+ slides.to.dataset.eventdone = true;
126
+
127
+ } else if (event.type == 'overviewhidden' ) {
128
+
129
+ document.body.dataset.exitoverview = true;
130
+
131
+ setTimeout(function () {
132
+ document.body.removeAttribute('data-exitoverview')
133
+ }, 500)
134
+
135
+ if (event.currentSlide ) {
136
+
137
+ if (slides.from && options.hideagain) {
138
+ hideAppearances(event.previousSlide);
139
+ }
140
+ showAppearances(slides.to);
141
+ event.currentSlide.dataset.eventdone = true;
142
+ }
143
+ }
144
+ }
145
+ if (event.type == "slidechanged" && slides.from) {
146
+ slides.from.removeAttribute('data-eventdone');
147
+ }
148
+
149
+ if (slides.from ) {
150
+ if (event.type == 'slidetransitionend' && options.hideagain) {
151
+ hideAppearances(slides.from);
152
+ }
59
153
  }
60
154
  };
61
155
 
@@ -67,10 +161,13 @@ const Plugin = () => {
67
161
  }
68
162
  };
69
163
 
70
- deck.on( 'ready', event => { showHideSlide(event) } );
71
- deck.on( 'slidetransitionend', event => {showHideSlide(event) });
72
- deck.on( 'fragmentshown', event => {showHideFragment(event) });
73
- deck.on( 'fragmenthidden', event => {showHideFragment(event) });
164
+ deck.on( 'ready', event => { autoAdd(); showHideSlide(event) } );
165
+ deck.on( 'slidechanged', event => { showHideSlide(event) } );
166
+ deck.on( 'slidetransitionend', event => { showHideSlide(event) } );
167
+ deck.on( 'autoanimate', event => { showHideSlide(event) } );
168
+ deck.on( 'overviewhidden', event => { showHideSlide(event) } );
169
+ deck.on( 'fragmentshown', event => { showHideFragment(event) });
170
+ deck.on( 'fragmenthidden', event => { showHideFragment(event) });
74
171
  };
75
172
 
76
173
  const init = function (deck) {
@@ -79,7 +176,11 @@ const Plugin = () => {
79
176
  baseclass: 'animated',
80
177
  visibleclass: 'in',
81
178
  hideagain: true,
82
- delay: 300
179
+ delay: 300,
180
+ debug: false,
181
+ appearevent: 'slidetransitionend',
182
+ autoappear: false,
183
+ autoelements: null
83
184
  };
84
185
 
85
186
  const defaults = function (options, defaultOptions) {
package/screenshot.png CHANGED
Binary file