summaryrefslogtreecommitdiff
path: root/2024-06-18-guix-social/reveal.js/js/controllers/notes.js
blob: 8af918c361b169b8c1fb9909852c13f1786c100e (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
 * Handles the showing of speaker notes
 */
export default class Notes {

	constructor( Reveal ) {

		this.Reveal = Reveal;

	}

	render() {

		this.element = document.createElement( 'div' );
		this.element.className = 'speaker-notes';
		this.element.setAttribute( 'data-prevent-swipe', '' );
		this.element.setAttribute( 'tabindex', '0' );
		this.Reveal.getRevealElement().appendChild( this.element );

	}

	/**
	 * Called when the reveal.js config is updated.
	 */
	configure( config, oldConfig ) {

		if( config.showNotes ) {
			this.element.setAttribute( 'data-layout', typeof config.showNotes === 'string' ? config.showNotes : 'inline' );
		}

	}

	/**
	 * Pick up notes from the current slide and display them
	 * to the viewer.
	 *
	 * @see {@link config.showNotes}
	 */
	update() {

		if( this.Reveal.getConfig().showNotes &&
			this.element && this.Reveal.getCurrentSlide() &&
			!this.Reveal.isScrollView() &&
			!this.Reveal.isPrintView()
		) {
			this.element.innerHTML = this.getSlideNotes() || '<span class="notes-placeholder">No notes on this slide.</span>';
		}

	}

	/**
	 * Updates the visibility of the speaker notes sidebar that
	 * is used to share annotated slides. The notes sidebar is
	 * only visible if showNotes is true and there are notes on
	 * one or more slides in the deck.
	 */
	updateVisibility() {

		if( this.Reveal.getConfig().showNotes &&
			this.hasNotes() &&
			!this.Reveal.isScrollView() &&
			!this.Reveal.isPrintView()
		) {
			this.Reveal.getRevealElement().classList.add( 'show-notes' );
		}
		else {
			this.Reveal.getRevealElement().classList.remove( 'show-notes' );
		}

	}

	/**
	 * Checks if there are speaker notes for ANY slide in the
	 * presentation.
	 */
	hasNotes() {

		return this.Reveal.getSlidesElement().querySelectorAll( '[data-notes], aside.notes' ).length > 0;

	}

	/**
	 * Checks if this presentation is running inside of the
	 * speaker notes window.
	 *
	 * @return {boolean}
	 */
	isSpeakerNotesWindow() {

		return !!window.location.search.match( /receiver/gi );

	}

	/**
	 * Retrieves the speaker notes from a slide. Notes can be
	 * defined in two ways:
	 * 1. As a data-notes attribute on the slide <section>
	 * 2. With <aside class="notes"> elements inside the slide
	 *
	 * @param {HTMLElement} [slide=currentSlide]
	 * @return {(string|null)}
	 */
	getSlideNotes( slide = this.Reveal.getCurrentSlide() ) {

		// Notes can be specified via the data-notes attribute...
		if( slide.hasAttribute( 'data-notes' ) ) {
			return slide.getAttribute( 'data-notes' );
		}

		// ... or using <aside class="notes"> elements
		let notesElements = slide.querySelectorAll( 'aside.notes' );
		if( notesElements ) {
			return Array.from(notesElements).map( notesElement => notesElement.innerHTML ).join( '\n' );
		}

		return null;

	}

	destroy() {

		this.element.remove();

	}

}