This repository has been archived by the owner on Jan 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shower-notes.js
95 lines (77 loc) · 2.53 KB
/
shower-notes.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* @fileOverview
* Presenter notes plugin for shower.
*/
shower.modules.define('shower-notes', [
'util.extend'
], function (provide, extend) {
var DEFAULT_NOTE_SELECTOR = 'footer';
/**
* @class
* Presenter notes plugin for shower.
* @name plugin.Notes
* @param {Shower} shower
* @param {Object} [options] Plugin options.
* @param {String} [options.selector = 'footer']
* @constructor
*/
function Notes (shower, options) {
options = options || {};
this._shower = shower;
this._notesSelector = options.selector || DEFAULT_NOTE_SELECTOR;
if (this._hasConsole()) {
this._setupListeners();
}
}
extend(Notes.prototype, /** @lends plugin.Notes.prototype */{
destroy: function () {
this._clearListeners();
this._shower = null;
},
show: function () {
this.clear();
var shower = this._shower;
var slide = shower.player.getCurrentSlide();
var notes = slide.layout.getElement().querySelector(this._notesSelector);
if (notes && notes.innerHTML) {
console.info(notes.innerHTML.replace(/\n\s+/g, '\n'));
}
var currentSlideNumber = shower.player.getCurrentSlideIndex();
var nextSlide = shower.get(currentSlideNumber + 1);
if (nextSlide) {
console.info('NEXT: ' + nextSlide.getTitle());
}
},
clear: function () {
var shower = this._shower;
if (typeof console.clear !== 'undefined' &&
shower.container.isSlideMode()) {
console.clear();
}
},
_hasConsole: function () {
return typeof console !== 'undefined';
},
_setupListeners: function () {
var shower = this._shower;
this._showerListeners = shower.events.group()
.on('destroy', this.destroy, this);
this._playerListeners = shower.player.events.group()
.on('activate', this._onSlideActivate, this);
},
_clearListeners: function () {
if (!this._hasConsole()) {
return;
}
this._showerListeners.offAll();
this._playerListeners.offAll();
},
_onSlideActivate: function () {
this.show();
}
});
provide(Notes);
});
shower.modules.require(['shower'], function (sh) {
sh.plugins.add('shower-notes');
});